|
|
@ -1,29 +1,11 @@
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
import exifr from 'exifr';
|
|
|
|
import * as exifr from 'exifr';
|
|
|
|
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
providedIn: 'root',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
export class ExifService {
|
|
|
|
export class ExifService {
|
|
|
|
|
|
|
|
|
|
|
|
private getExifData(file: File): Promise<any> {
|
|
|
|
private getExifData(file: File): Promise<any> {
|
|
|
|
// console.log('getExifData(file)');
|
|
|
|
|
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
|
|
|
|
// console.log('getExifData(file) -> Promise');
|
|
|
|
|
|
|
|
// const reader = new FileReader();
|
|
|
|
|
|
|
|
// console.log('getExifData(file) -> Promise -> reader');
|
|
|
|
|
|
|
|
// reader.onload = (event: any) => {
|
|
|
|
|
|
|
|
// console.log('getExifData(file) -> Promise -> reader -> onload');
|
|
|
|
|
|
|
|
// EXIF.getData(event.target.result, function() {
|
|
|
|
|
|
|
|
// console.log('getExifData(file) -> Promise -> reader -> onload -> EXIF.getData');
|
|
|
|
|
|
|
|
// const allExifData = EXIF.getAllTags(this);
|
|
|
|
|
|
|
|
// console.log('getExifData(file) -> Promise -> reader -> onload -> EXIF.getData -> getAllTags');
|
|
|
|
|
|
|
|
// resolve(allExifData);
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
// reader.onerror = (error) => reject(error);
|
|
|
|
|
|
|
|
// reader.readAsArrayBuffer(file);
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
return exifr.parse(file);
|
|
|
|
return exifr.parse(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -32,7 +14,7 @@ export class ExifService {
|
|
|
|
return await this.getExifData(file);
|
|
|
|
return await this.getExifData(file);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error reading EXIF data:', error);
|
|
|
|
console.error('Error reading EXIF data:', error);
|
|
|
|
return
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -56,12 +38,21 @@ export class ExifService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getLocation(file: File): Promise<{ latitude?: number; longitude?: number }> {
|
|
|
|
async getLocation(
|
|
|
|
|
|
|
|
file: File
|
|
|
|
|
|
|
|
): Promise<{ latitude?: number; longitude?: number }> {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const exifData = await this.getExifData(file);
|
|
|
|
const exifData = await this.getExifData(file);
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
latitude: exifData.GPSLatitude ? this.convertToDecimal(exifData.GPSLatitude, exifData.GPSLatitudeRef) : undefined,
|
|
|
|
latitude: exifData.GPSLatitude
|
|
|
|
longitude: exifData.GPSLongitude ? this.convertToDecimal(exifData.GPSLongitude, exifData.GPSLongitudeRef) : undefined
|
|
|
|
? this.convertToDecimal(exifData.GPSLatitude, exifData.GPSLatitudeRef)
|
|
|
|
|
|
|
|
: undefined,
|
|
|
|
|
|
|
|
longitude: exifData.GPSLongitude
|
|
|
|
|
|
|
|
? this.convertToDecimal(
|
|
|
|
|
|
|
|
exifData.GPSLongitude,
|
|
|
|
|
|
|
|
exifData.GPSLongitudeRef
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
: undefined,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error reading EXIF data:', error);
|
|
|
|
console.error('Error reading EXIF data:', error);
|
|
|
@ -82,6 +73,6 @@ export class ExifService {
|
|
|
|
private convertToDecimal(coordinate: number[], direction: string): number {
|
|
|
|
private convertToDecimal(coordinate: number[], direction: string): number {
|
|
|
|
if (!coordinate || coordinate.length !== 3) return NaN;
|
|
|
|
if (!coordinate || coordinate.length !== 3) return NaN;
|
|
|
|
const decimal = coordinate[0] + coordinate[1] / 60 + coordinate[2] / 3600;
|
|
|
|
const decimal = coordinate[0] + coordinate[1] / 60 + coordinate[2] / 3600;
|
|
|
|
return (direction === 'S' || direction === 'W') ? -decimal : decimal;
|
|
|
|
return direction === 'S' || direction === 'W' ? -decimal : decimal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|