-
Notifications
You must be signed in to change notification settings - Fork 211
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
Gpx wpt mappoints #452
Changes from 5 commits
ac4a854
7008bc9
55c0e98
07a1d99
52d3497
7928a07
ffa5ed6
5e56561
f1a5c6c
92f346b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -387,14 +387,32 @@ export class GalleryMapLightboxComponent implements OnChanges { | |
for (let i = 0; i < this.gpxFiles.length; i++) { | ||
const file = this.gpxFiles[i]; | ||
const path = await this.mapService.getMapPath(file); | ||
const wpoints = await this.mapService.getMapPoints(file); | ||
if (file !== this.gpxFiles[i]) { // check race condition | ||
return; | ||
} | ||
if (path.length === 0) { | ||
continue; | ||
if (path.length !== 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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[])); | ||
// console.log('Trk path is not empty, in file ' + i + ', path[0]=' + JSON.stringify(path[0])); | ||
// continue; | ||
} else { | ||
// console.log('No trk path in file ' + i); | ||
// continue; | ||
} | ||
if (wpoints.length !== 0) { | ||
// console.log('Wpt exist in file ' + i + ', wpoints[0]=' + JSON.stringify(wpoints[0]) +', wpoints.length=' + wpoints.length); | ||
wpoints_loop: for (let wpt_i = 0; i < wpoints.length; wpt_i++) { | ||
// console.log('item number ' + wpt_i + ' out of ' + wpoints.length + ', coord=' + JSON.stringify(wpoints[wpt_i])); | ||
if (wpoints[wpt_i] === undefined) { | ||
break wpoints_loop; | ||
} | ||
this.mapLayersControlOption.overlays.Paths.addLayer(marker(wpoints[wpt_i] as LatLng)); | ||
} | ||
// console.log('Wpoints plotted.'); | ||
} else { | ||
// console.log('No wpt points in file ' + i); | ||
} | ||
this.mapLayersControlOption.overlays.Paths.addLayer(marker(path[0] as LatLng)); | ||
this.mapLayersControlOption.overlays.Paths.addLayer(polyline(path as LatLng[])); | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,23 @@ export class MapService { | |
} | ||
return points; | ||
} | ||
|
||
// Waypoints <wpt> from GPX files: | ||
public async getMapPoints(file: FileDTO): Promise<MapPoints[]> { | ||
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('wpt'); | ||
const wpoints: MapPoints[] = []; | ||
// tslint:disable-next-line:prefer-for-of | ||
for (let i = 0; i < elements.length; i++) { | ||
wpoints.push({ | ||
lat: parseFloat(elements[i].getAttribute('lat')), | ||
lng: parseFloat(elements[i].getAttribute('lon')) | ||
}); | ||
} | ||
console.log('From file ' + filePath + ', wpoints=' + JSON.stringify(wpoints)); | ||
return wpoints; | ||
} | ||
|
||
} | ||
|
||
|
@@ -92,3 +109,8 @@ export interface MapPath { | |
lat: number; | ||
lng: number; | ||
} | ||
|
||
export interface MapPoints { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can reuse the interface above. Maybe refactor it to something like MapCoordinates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
lat: number; | ||
lng: number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add the code from
getMapPoints
togetMapPath
, as both functions do a network call and that is wasteful (probably the browser would serve the second call from cache, but still). Also the two function has some common code. You can rename the function to something more generic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've made it a single
getMapCoordinates[][]
instead, which returns the array of arrayscoordinates = [path,wpoints]
- so there's only one network call to the GPX file, but 2 calls togetElementsByTagName
ingetMapCoordinates()
. I hope that's good enough :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is perfect, thank you.