mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
surface
This commit is contained in:
@@ -503,6 +503,19 @@ export class TrackPoint {
|
||||
getSurface(): string {
|
||||
return this.extensions && this.extensions["gpxtpx:TrackPointExtension"] && this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"] && this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"].surface ? this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"].surface : undefined;
|
||||
}
|
||||
|
||||
setSurface(surface: string): void {
|
||||
if (!this.extensions) {
|
||||
this.extensions = {};
|
||||
}
|
||||
if (!this.extensions["gpxtpx:TrackPointExtension"]) {
|
||||
this.extensions["gpxtpx:TrackPointExtension"] = {};
|
||||
}
|
||||
if (!this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"]) {
|
||||
this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"] = {};
|
||||
}
|
||||
this.extensions["gpxtpx:TrackPointExtension"]["gpxtpx:Extensions"]["surface"] = surface;
|
||||
}
|
||||
};
|
||||
|
||||
export class Waypoint {
|
||||
|
@@ -42,6 +42,14 @@ async function getRoute(points: Coordinates[], brouterProfile: string, privateRo
|
||||
|
||||
let route: TrackPoint[] = [];
|
||||
let coordinates = geojson.features[0].geometry.coordinates;
|
||||
let messages = geojson.features[0].properties.messages;
|
||||
|
||||
const lngIdx = messages[0].indexOf("Longitude");
|
||||
const latIdx = messages[0].indexOf("Latitude");
|
||||
const tagIdx = messages[0].indexOf("WayTags");
|
||||
let messageIdx = 1;
|
||||
let surface = getSurface(messages[messageIdx][tagIdx]);
|
||||
|
||||
for (let i = 0; i < coordinates.length; i++) {
|
||||
let coord = coordinates[i];
|
||||
route.push(new TrackPoint({
|
||||
@@ -51,7 +59,25 @@ async function getRoute(points: Coordinates[], brouterProfile: string, privateRo
|
||||
},
|
||||
ele: coord[2] ?? undefined
|
||||
}));
|
||||
route[route.length - 1].setSurface(surface)
|
||||
|
||||
if (messageIdx < messages.length &&
|
||||
coordinates[i][0] == Number(messages[messageIdx][lngIdx]) / 1000000 &&
|
||||
coordinates[i][1] == Number(messages[messageIdx][latIdx]) / 1000000) {
|
||||
messageIdx++;
|
||||
|
||||
if (messageIdx == messages.length) surface = "missing";
|
||||
else surface = getSurface(messages[messageIdx][tagIdx]);
|
||||
}
|
||||
}
|
||||
|
||||
return route;
|
||||
}
|
||||
}
|
||||
|
||||
function getSurface(message: string): string {
|
||||
const fields = message.split(" ");
|
||||
for (let i = 0; i < fields.length; i++) if (fields[i].startsWith("surface=")) {
|
||||
return fields[i].substring(8);
|
||||
}
|
||||
return "unknown";
|
||||
};
|
Reference in New Issue
Block a user