mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-30 23:30:04 +00:00
elevation tool test
This commit is contained in:
@@ -21,6 +21,7 @@ export abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
|
||||
abstract getEndTimestamp(): Date | undefined;
|
||||
abstract getStatistics(): GPXStatistics;
|
||||
abstract getSegments(): TrackSegment[];
|
||||
abstract getTrackPoints(): TrackPoint[];
|
||||
|
||||
abstract toGeoJSON(): GeoJSON.Feature | GeoJSON.Feature[] | GeoJSON.FeatureCollection | GeoJSON.FeatureCollection[];
|
||||
|
||||
@@ -66,6 +67,10 @@ abstract class GPXTreeNode<T extends GPXTreeElement<any>> extends GPXTreeElement
|
||||
return this.children.flatMap((child) => child.getSegments());
|
||||
}
|
||||
|
||||
getTrackPoints(): TrackPoint[] {
|
||||
return this.children.flatMap((child) => child.getTrackPoints());
|
||||
}
|
||||
|
||||
// Producers
|
||||
_reverse(originalNextTimestamp?: Date, newPreviousTimestamp?: Date) {
|
||||
let og = getOriginal(this);
|
||||
@@ -315,6 +320,26 @@ export class GPXFile extends GPXTreeNode<Track>{
|
||||
});
|
||||
}
|
||||
|
||||
addElevation(callback: (Coordinates) => number, trackIndices?: number[], segmentIndices?: number[], waypointIndices?: number[]) {
|
||||
let og = getOriginal(this); // Read as much as possible from the original object because it is faster
|
||||
this.trk.forEach((track, trackIndex) => {
|
||||
if (trackIndices === undefined || trackIndices.includes(trackIndex)) {
|
||||
track.trkseg.forEach((segment, segmentIndex) => {
|
||||
if (segmentIndices === undefined || segmentIndices.includes(segmentIndex)) {
|
||||
segment.trkpt.forEach((point, pointIndex) => {
|
||||
point.ele = callback(og.trk[trackIndex].trkseg[segmentIndex].trkpt[pointIndex].attributes);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
this.wpt.forEach((waypoint, waypointIndex) => {
|
||||
if (waypointIndices === undefined || waypointIndices.includes(waypointIndex)) {
|
||||
waypoint.ele = callback(og.wpt[waypointIndex].attributes);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setStyle(style: LineStyleExtension) {
|
||||
this.trk.forEach((track) => {
|
||||
track.setStyle(style);
|
||||
@@ -753,6 +778,10 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
return [this];
|
||||
}
|
||||
|
||||
getTrackPoints(): TrackPoint[] {
|
||||
return this.trkpt;
|
||||
}
|
||||
|
||||
toGeoJSON(): GeoJSON.Feature {
|
||||
return {
|
||||
type: "Feature",
|
||||
|
Reference in New Issue
Block a user