mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
first gpx file on map
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "ES6",
|
||||
"module": "ES6",
|
||||
"target": "ES5",
|
||||
"declaration": true,
|
||||
"outDir": "./dist",
|
||||
},
|
||||
|
Reference in New Issue
Block a user