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

Refactor getMapCoordinates

Removed input parameter tagname, hardcoded instead the array tagnames=['trkpt,'wpt'] , and iterated through this array to get elements from the XML file at once and gather them in coordinates[ ] = [ track_path_points[ ], wpoints_points[ ] ].
This commit is contained in:
zigmhount 2022-03-09 20:44:37 +01:00 committed by GitHub
parent 5e56561576
commit f1a5c6c0ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,19 +70,24 @@ export class MapService {
}
public async getMapCoordinates(file: FileDTO, tagname: string): Promise<MapCoordinates[]> {
public async getMapCoordinates(file: FileDTO): Promise<MapCoordinates[][]> {
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(tagname);
const points: MapCoordinates[] = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < elements.length; i++) {
points.push({
lat: parseFloat(elements[i].getAttribute('lat')),
lng: parseFloat(elements[i].getAttribute('lon'))
});
}
return points;
const tagnames=['trkpt','wpt'];
var coordinates: MapCoordinates[][]=[];
tagnames.forEach(function (item, index) {
const elements=gpx.getElementsByTagName(item);
const points: MapCoordinates[] = [];
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < elements.length; i++) {
points.push({
lat: parseFloat(elements[i].getAttribute('lat')),
lng: parseFloat(elements[i].getAttribute('lon'))
});
}
coordinates[index]=points;
})
return coordinates;
}
}