1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2025-02-09 13:46:56 +02:00

refactoring gpx marker (waypoints) on map

This commit is contained in:
Patrik J. Braun 2022-03-11 23:54:55 +01:00
parent ec8b287c9f
commit 82aaa614b3
2 changed files with 20 additions and 23 deletions

View File

@ -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));
});
}
}
}

View File

@ -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')
};
}
}