Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpx wpt mappoints #452

Merged
merged 10 commits into from
Mar 11, 2022
15 changes: 15 additions & 0 deletions demo/images/emptydirectory/unique_wpt.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<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">
<metadata>
<name>favourites</name>
</metadata>
<wpt lat="46.1234" lon="10.1234">
<time>2022-02-12T19:31:58Z</time>
<name>Location name</name>
<extensions>
<osmand:icon>special_star</osmand:icon>
<osmand:background>circle</osmand:background>
<osmand:color>#eecc22</osmand:color>
</extensions>
</wpt>
</gpx>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<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">
<metadata>
<name>favourites</name>
</metadata>
<wpt lat="39.1234" lon="-0.54332">
<time>2022-02-04T00:12:22Z</time>
<name>Location 1</name>
<extensions>
<osmand:icon>special_star</osmand:icon>
<osmand:background>circle</osmand:background>
<osmand:color>#eecc22</osmand:color>
</extensions>
</wpt>
<wpt lat="39.54321" lon="-0.1234">
<time>2022-02-04T00:12:22Z</time>
<name>Location 2</name>
<extensions>
<osmand:address>Street 1, Town</osmand:address>
<osmand:icon>special_star</osmand:icon>
<osmand:background>circle</osmand:background>
<osmand:color>#eecc22</osmand:color>
</extensions>
</wpt>
<wpt lat="12.54321" lon="10.1234">
<time>2022-02-04T00:12:22Z</time>
<name>Location 3</name>
<extensions>
<osmand:address>Street 2, Town</osmand:address>
<osmand:icon>special_star</osmand:icon>
<osmand:background>circle</osmand:background>
<osmand:color>#eecc22</osmand:color>
</extensions>
</wpt>
</gpx>
Original file line number Diff line number Diff line change
Expand Up @@ -386,15 +386,23 @@ 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];
const path = await this.mapService.getMapPath(file);
// get <trkpt> items into path[] and <wpt> items into wpoints[]
const [path,wpoints] = await this.mapService.getMapCoordinates(file);
if (file !== this.gpxFiles[i]) { // check race condition
return;
}
if (path.length === 0) {
continue;
if (path.length !== 0) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clean up this part a bit? removing unnecessary comments, etc. Otherwise this PR looks good.

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; i < wpoints.length; wpt_i++) {
if (wpoints[wpt_i] === undefined) {
continue wpoints_loop;
}
this.mapLayersControlOption.overlays.Paths.addLayer(marker(wpoints[wpt_i] as LatLng));
}
}
this.mapLayersControlOption.overlays.Paths.addLayer(marker(path[0] as LatLng));
this.mapLayersControlOption.overlays.Paths.addLayer(polyline(path as LatLng[]));
}
}
}
Expand Down
30 changes: 17 additions & 13 deletions src/frontend/app/ui/gallery/map/map.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,29 @@ export class MapService {
}


public async getMapPath(file: FileDTO): Promise<MapPath[]> {
public async getMapCoordinates(file: FileDTO): Promise<MapCoordinates[][]> {
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('trkpt');
const points: MapPath[] = [];
// 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;
}

}


export interface MapPath {
export interface MapCoordinates {
lat: number;
lng: number;
}