From f1a5c6c0ee660256ad9fe09c9e241f8571aa9cee Mon Sep 17 00:00:00 2001 From: zigmhount <58641590+zigmhount@users.noreply.github.com> Date: Wed, 9 Mar 2022 20:44:37 +0100 Subject: [PATCH] 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[ ] ]. --- .../app/ui/gallery/map/map.service.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/frontend/app/ui/gallery/map/map.service.ts b/src/frontend/app/ui/gallery/map/map.service.ts index 84720e16..476cc5c1 100644 --- a/src/frontend/app/ui/gallery/map/map.service.ts +++ b/src/frontend/app/ui/gallery/map/map.service.ts @@ -70,19 +70,24 @@ export class MapService { } - public async getMapCoordinates(file: FileDTO, tagname: string): Promise { + public async getMapCoordinates(file: FileDTO): Promise { 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; } }