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:
parent
ceb6cc4a15
commit
987007b7c4
@ -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[]) {
|
||||
let last = list[0];
|
||||
const out = [];
|
||||
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]);
|
||||
last = list[i];
|
||||
}
|
||||
|
@ -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[]> {
|
||||
const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name);
|
||||
const gpx = await this.networkService.getXML('/gallery/content/' + filePath);
|
||||
|
Loading…
x
Reference in New Issue
Block a user