first gpx file on map

This commit is contained in:
vcoppe
2024-04-16 22:57:28 +02:00
parent 76178e5c00
commit bd2d3eed66
7 changed files with 343 additions and 10 deletions

View File

@@ -10,6 +10,8 @@ abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
abstract getStartTimestamp(): Date;
abstract getEndTimestamp(): Date;
abstract toGeoJSON(): any;
}
// An abstract class that can be extended to facilitate functions working similarly with Tracks and TrackSegments
@@ -80,6 +82,13 @@ export class GPXFile extends GPXTreeNode<Track>{
clone(): GPXFile {
return new GPXFile(structuredClone(this));
}
toGeoJSON(): any {
return {
type: "FeatureCollection",
features: this.getChildren().flatMap((child) => child.toGeoJSON())
};
}
};
// A class that represents a Track in a GPX file
@@ -112,6 +121,10 @@ export class Track extends GPXTreeNode<TrackSegment> {
clone(): Track {
return new Track(structuredClone(this));
}
toGeoJSON(): any {
return this.getChildren().map((child) => child.toGeoJSON());
}
};
// A class that represents a TrackSegment in a GPX file
@@ -150,6 +163,17 @@ export class TrackSegment extends GPXTreeLeaf {
return this.trkpt[this.trkpt.length - 1].time;
}
toGeoJSON(): any {
return {
type: "Feature",
geometry: {
type: "LineString",
coordinates: this.trkpt.map((point) => [point.attributes.lon, point.attributes.lat])
},
properties: {}
};
}
clone(): TrackSegment {
return new TrackSegment(structuredClone(this));
}

View File

@@ -1,7 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "ES6",
"module": "ES6",
"target": "ES5",
"declaration": true,
"outDir": "./dist",
},