From 346590f651694ae8830c21e5cfe5380951c51c1c Mon Sep 17 00:00:00 2001 From: "Patrik J. Braun" Date: Sat, 12 Mar 2022 00:00:49 +0100 Subject: [PATCH] refactoring map service: Using leaflet's LatLngLiteral interface --- .../map/lightbox/lightbox.map.gallery.component.ts | 7 +++---- src/frontend/app/ui/gallery/map/map.service.ts | 13 ++++--------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/frontend/app/ui/gallery/map/lightbox/lightbox.map.gallery.component.ts b/src/frontend/app/ui/gallery/map/lightbox/lightbox.map.gallery.component.ts index 5953f801..315d2814 100644 --- a/src/frontend/app/ui/gallery/map/lightbox/lightbox.map.gallery.component.ts +++ b/src/frontend/app/ui/gallery/map/lightbox/lightbox.map.gallery.component.ts @@ -15,7 +15,6 @@ import { Control, divIcon, icon, - LatLng, latLng, latLngBounds, layerGroup, @@ -392,11 +391,11 @@ export class GalleryMapLightboxComponent implements OnChanges { } if (parsedGPX.path.length !== 0) { // render the beginning of the path with a marker - this.mapLayersControlOption.overlays.Paths.addLayer(marker(parsedGPX.path[0] as LatLng)); - this.mapLayersControlOption.overlays.Paths.addLayer(polyline(parsedGPX.path as LatLng[])); + this.mapLayersControlOption.overlays.Paths.addLayer(marker(parsedGPX.path[0])); + this.mapLayersControlOption.overlays.Paths.addLayer(polyline(parsedGPX.path)); } parsedGPX.markers.forEach(mc => { - this.mapLayersControlOption.overlays.Paths.addLayer(marker(mc as LatLng)); + this.mapLayersControlOption.overlays.Paths.addLayer(marker(mc)); }); } } diff --git a/src/frontend/app/ui/gallery/map/map.service.ts b/src/frontend/app/ui/gallery/map/map.service.ts index 789787c1..bcf10474 100644 --- a/src/frontend/app/ui/gallery/map/map.service.ts +++ b/src/frontend/app/ui/gallery/map/map.service.ts @@ -4,6 +4,7 @@ import {FileDTO} from '../../../../../common/entities/FileDTO'; import {Utils} from '../../../../../common/Utils'; import {Config} from '../../../../../common/config/public/Config'; import {MapLayers, MapProviders} from '../../../../../common/config/public/ClientConfig'; +import {LatLngLiteral} from 'leaflet'; @Injectable() @@ -70,12 +71,12 @@ export class MapService { } - public async getMapCoordinates(file: FileDTO): Promise<{ path: MapCoordinates[], markers: MapCoordinates[] }> { + public async getMapCoordinates(file: FileDTO): Promise<{ path: LatLngLiteral[], markers: LatLngLiteral[] }> { const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name); const gpx = await this.networkService.getXML('/gallery/content/' + filePath); - const getCoordinates = (tagName: string): MapCoordinates[] => { + const getCoordinates = (tagName: string): LatLngLiteral[] => { const elements = gpx.getElementsByTagName(tagName); - const ret: MapCoordinates[] = []; + const ret: LatLngLiteral[] = []; // tslint:disable-next-line:prefer-for-of for (let i = 0; i < elements.length; i++) { ret.push({ @@ -92,9 +93,3 @@ export class MapService { }; } } - - -export interface MapCoordinates { - lat: number; - lng: number; -}