1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

refactoring the map service

This commit is contained in:
Patrik J. Braun 2018-11-26 17:34:07 +01:00
parent ceb6cc4a15
commit 987007b7c4
2 changed files with 16 additions and 16 deletions

View File

@ -154,27 +154,12 @@ export class GalleryMapLightboxComponent implements OnChanges, AfterViewInit {
} }
private calcDistance(loc: MapPath, loc2: MapPath): number {
const radlat1 = Math.PI * loc.latitude / 180;
const radlat2 = Math.PI * loc2.latitude / 180;
const theta = loc.longitude - loc2.longitude;
const radtheta = Math.PI * theta / 180;
let dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
if (dist > 1) {
dist = 1;
}
dist = Math.acos(dist);
dist = dist * 180 / Math.PI;
dist = dist * 60 * 1.1515;
return dist * 1.609344;
}
private gpxFilter(list: MapPath[]) { private gpxFilter(list: MapPath[]) {
let last = list[0]; let last = list[0];
const out = []; const out = [];
for (let i = 1; i < list.length; i++) { for (let i = 1; i < list.length; i++) {
if (this.calcDistance(list[i], last) > 0.5) { if (this.mapService.calcDistance(list[i], last) > 0.5) {
out.push(list[i]); out.push(list[i]);
last = list[i]; last = list[i];
} }

View File

@ -11,6 +11,21 @@ export class MapService {
} }
public calcDistance(loc: MapPath, loc2: MapPath): number {
const radlat1 = Math.PI * loc.latitude / 180;
const radlat2 = Math.PI * loc2.latitude / 180;
const theta = loc.longitude - loc2.longitude;
const radtheta = Math.PI * theta / 180;
let dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
if (dist > 1) {
dist = 1;
}
dist = Math.acos(dist);
dist = dist * 180 / Math.PI;
dist = dist * 60 * 1.1515;
return dist * 1.609344;
}
public async getMapPath(file: FileDTO): Promise<MapPath[]> { public async getMapPath(file: FileDTO): Promise<MapPath[]> {
const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name); const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name);
const gpx = await this.networkService.getXML('/gallery/content/' + filePath); const gpx = await this.networkService.getXML('/gallery/content/' + filePath);