Skip to content

Commit 9104db6

Browse files
authored
Merge pull request #452 from zigmhount/gpx_wpt_mappoints
Gpx wpt mappoints
2 parents 182eb7d + 92f346b commit 9104db6

File tree

4 files changed

+80
-18
lines changed

4 files changed

+80
-18
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
2+
<gpx version="1.1" creator="OsmAnd~ 4.1.11" xmlns="http://www.topografix.com/GPX/1/1" xmlns:osmand="https://osmand.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
3+
<metadata>
4+
<name>favourites</name>
5+
</metadata>
6+
<wpt lat="46.1234" lon="10.1234">
7+
<time>2022-02-12T19:31:58Z</time>
8+
<name>Location name</name>
9+
<extensions>
10+
<osmand:icon>special_star</osmand:icon>
11+
<osmand:background>circle</osmand:background>
12+
<osmand:color>#eecc22</osmand:color>
13+
</extensions>
14+
</wpt>
15+
</gpx>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
2+
<gpx version="1.1" creator="OsmAnd~ 4.1.11" xmlns="http://www.topografix.com/GPX/1/1" xmlns:osmand="https://osmand.net" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
3+
<metadata>
4+
<name>favourites</name>
5+
</metadata>
6+
<wpt lat="39.1234" lon="-0.54332">
7+
<time>2022-02-04T00:12:22Z</time>
8+
<name>Location 1</name>
9+
<extensions>
10+
<osmand:icon>special_star</osmand:icon>
11+
<osmand:background>circle</osmand:background>
12+
<osmand:color>#eecc22</osmand:color>
13+
</extensions>
14+
</wpt>
15+
<wpt lat="39.54321" lon="-0.1234">
16+
<time>2022-02-04T00:12:22Z</time>
17+
<name>Location 2</name>
18+
<extensions>
19+
<osmand:address>Street 1, Town</osmand:address>
20+
<osmand:icon>special_star</osmand:icon>
21+
<osmand:background>circle</osmand:background>
22+
<osmand:color>#eecc22</osmand:color>
23+
</extensions>
24+
</wpt>
25+
<wpt lat="12.54321" lon="10.1234">
26+
<time>2022-02-04T00:12:22Z</time>
27+
<name>Location 3</name>
28+
<extensions>
29+
<osmand:address>Street 2, Town</osmand:address>
30+
<osmand:icon>special_star</osmand:icon>
31+
<osmand:background>circle</osmand:background>
32+
<osmand:color>#eecc22</osmand:color>
33+
</extensions>
34+
</wpt>
35+
</gpx>

src/frontend/app/ui/gallery/map/lightbox/lightbox.map.gallery.component.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,15 +386,23 @@ export class GalleryMapLightboxComponent implements OnChanges {
386386
// tslint:disable-next-line:prefer-for-of
387387
for (let i = 0; i < this.gpxFiles.length; i++) {
388388
const file = this.gpxFiles[i];
389-
const path = await this.mapService.getMapPath(file);
389+
// get <trkpt> items into path[] and <wpt> items into wpoints[]
390+
const [path,wpoints] = await this.mapService.getMapCoordinates(file);
390391
if (file !== this.gpxFiles[i]) { // check race condition
391392
return;
392393
}
393-
if (path.length === 0) {
394-
continue;
394+
if (path.length !== 0) {
395+
this.mapLayersControlOption.overlays.Paths.addLayer(marker(path[0] as LatLng));
396+
this.mapLayersControlOption.overlays.Paths.addLayer(polyline(path as LatLng[]));
397+
}
398+
if (wpoints.length !== 0) {
399+
wpoints_loop: for (let wpt_i = 0; i < wpoints.length; wpt_i++) {
400+
if (wpoints[wpt_i] === undefined) {
401+
continue wpoints_loop;
402+
}
403+
this.mapLayersControlOption.overlays.Paths.addLayer(marker(wpoints[wpt_i] as LatLng));
404+
}
395405
}
396-
this.mapLayersControlOption.overlays.Paths.addLayer(marker(path[0] as LatLng));
397-
this.mapLayersControlOption.overlays.Paths.addLayer(polyline(path as LatLng[]));
398406
}
399407
}
400408
}

src/frontend/app/ui/gallery/map/map.service.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,29 @@ export class MapService {
7070
}
7171

7272

73-
public async getMapPath(file: FileDTO): Promise<MapPath[]> {
73+
public async getMapCoordinates(file: FileDTO): Promise<MapCoordinates[][]> {
7474
const filePath = Utils.concatUrls(file.directory.path, file.directory.name, file.name);
7575
const gpx = await this.networkService.getXML('/gallery/content/' + filePath);
76-
const elements = gpx.getElementsByTagName('trkpt');
77-
const points: MapPath[] = [];
78-
// tslint:disable-next-line:prefer-for-of
79-
for (let i = 0; i < elements.length; i++) {
80-
points.push({
81-
lat: parseFloat(elements[i].getAttribute('lat')),
82-
lng: parseFloat(elements[i].getAttribute('lon'))
83-
});
84-
}
85-
return points;
76+
const tagnames=['trkpt','wpt'];
77+
var coordinates: MapCoordinates[][]=[];
78+
tagnames.forEach(function (item, index) {
79+
const elements=gpx.getElementsByTagName(item);
80+
const points: MapCoordinates[] = [];
81+
// tslint:disable-next-line:prefer-for-of
82+
for (let i = 0; i < elements.length; i++) {
83+
points.push({
84+
lat: parseFloat(elements[i].getAttribute('lat')),
85+
lng: parseFloat(elements[i].getAttribute('lon'))
86+
});
87+
}
88+
coordinates[index]=points;
89+
})
90+
return coordinates;
8691
}
87-
8892
}
8993

9094

91-
export interface MapPath {
95+
export interface MapCoordinates {
9296
lat: number;
9397
lng: number;
9498
}

0 commit comments

Comments
 (0)