You've already forked pigallery2
							
							
				mirror of
				https://github.com/bpatrik/pigallery2.git
				synced 2025-10-30 23:57:43 +02:00 
			
		
		
		
	refactoring gpx marker (waypoints) on map
This commit is contained in:
		| @@ -386,23 +386,18 @@ export class GalleryMapLightboxComponent implements OnChanges { | ||||
|     // tslint:disable-next-line:prefer-for-of | ||||
|     for (let i = 0; i < this.gpxFiles.length; i++) { | ||||
|       const file = this.gpxFiles[i]; | ||||
|       // get <trkpt> items into path[] and <wpt> items into wpoints[] | ||||
|       const [path,wpoints] = await this.mapService.getMapCoordinates(file); | ||||
|       const parsedGPX = await this.mapService.getMapCoordinates(file); | ||||
|       if (file !== this.gpxFiles[i]) { // check race condition | ||||
|         return; | ||||
|       } | ||||
|       if (path.length !== 0) { | ||||
|         this.mapLayersControlOption.overlays.Paths.addLayer(marker(path[0] as LatLng)); | ||||
|         this.mapLayersControlOption.overlays.Paths.addLayer(polyline(path as LatLng[])); | ||||
|       } | ||||
|       if (wpoints.length !== 0) { | ||||
|         wpoints_loop: for (let wpt_i = 0; wpt_i < wpoints.length; wpt_i++) { | ||||
|           if (wpoints[wpt_i] === undefined) { | ||||
|             continue wpoints_loop; | ||||
|           } | ||||
|           this.mapLayersControlOption.overlays.Paths.addLayer(marker(wpoints[wpt_i] as LatLng)); | ||||
|         } | ||||
|       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[])); | ||||
|       } | ||||
|       parsedGPX.markers.forEach(mc => { | ||||
|         this.mapLayersControlOption.overlays.Paths.addLayer(marker(mc as LatLng)); | ||||
|       }); | ||||
|     } | ||||
|   } | ||||
| } | ||||
|   | ||||
| @@ -70,24 +70,26 @@ export class MapService { | ||||
|   } | ||||
|  | ||||
|  | ||||
|   public async getMapCoordinates(file: FileDTO): Promise<MapCoordinates[][]> { | ||||
|   public async getMapCoordinates(file: FileDTO): Promise<{ path: MapCoordinates[], markers: MapCoordinates[] }> { | ||||
|     const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name); | ||||
|     const gpx = await this.networkService.getXML('/gallery/content/' + filePath); | ||||
|     const tagnames=['trkpt','wpt']; | ||||
|     var coordinates: MapCoordinates[][]=[]; | ||||
|     tagnames.forEach(function (item, index) { | ||||
|       const elements=gpx.getElementsByTagName(item); | ||||
|       const points: MapCoordinates[] = []; | ||||
|     const getCoordinates = (tagName: string): MapCoordinates[] => { | ||||
|       const elements = gpx.getElementsByTagName(tagName); | ||||
|       const ret: MapCoordinates[] = []; | ||||
|       // tslint:disable-next-line:prefer-for-of | ||||
|       for (let i = 0; i < elements.length; i++) { | ||||
|         points.push({ | ||||
|         ret.push({ | ||||
|           lat: parseFloat(elements[i].getAttribute('lat')), | ||||
|           lng: parseFloat(elements[i].getAttribute('lon')) | ||||
|         }); | ||||
|       } | ||||
|       coordinates[index]=points; | ||||
|     }) | ||||
|     return coordinates; | ||||
|       return ret; | ||||
|     }; | ||||
|  | ||||
|     return { | ||||
|       path: getCoordinates('trkpt'), | ||||
|       markers: getCoordinates('wpt') | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user