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

Refactored getMapPoints and getMapPath into getMapCoordinates

Added argument tagname to getMapCoordinates() to accept 'trkpt' or 'wpt';
replaced interfaces MapPoints and MapPath with MapCoordinates.
This commit is contained in:
zigmhount 2022-03-09 16:31:54 +01:00 committed by GitHub
parent 52d34979b1
commit 7928a07230
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,11 +70,11 @@ export class MapService {
} }
public async getMapPath(file: FileDTO): Promise<MapPath[]> { public async getMapCoordinates(file: FileDTO, tagname: string): Promise<MapCoordinates[]> {
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);
const elements = gpx.getElementsByTagName('trkpt'); const elements = gpx.getElementsByTagName(tagname);
const points: MapPath[] = []; const points: MapCoordinates[] = [];
// tslint:disable-next-line:prefer-for-of // tslint:disable-next-line:prefer-for-of
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {
points.push({ points.push({
@ -84,33 +84,10 @@ export class MapService {
} }
return points; return points;
} }
// Waypoints <wpt> from GPX files:
public async getMapPoints(file: FileDTO): Promise<MapPoints[]> {
const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name);
const gpx = await this.networkService.getXML('/gallery/content/' + filePath);
const elements = gpx.getElementsByTagName('wpt');
const wpoints: MapPoints[] = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < elements.length; i++) {
wpoints.push({
lat: parseFloat(elements[i].getAttribute('lat')),
lng: parseFloat(elements[i].getAttribute('lon'))
});
}
console.log('From file ' + filePath + ', wpoints=' + JSON.stringify(wpoints));
return wpoints;
}
} }
export interface MapPath { export interface MapCoordinates {
lat: number;
lng: number;
}
export interface MapPoints {
lat: number; lat: number;
lng: number; lng: number;
} }