single simplify call to create whole anchor point hierarchy

This commit is contained in:
vcoppe
2024-04-23 19:33:11 +02:00
parent dff39366fa
commit 9bc743bc18
3 changed files with 65 additions and 80 deletions

View File

@@ -20,6 +20,7 @@ abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
abstract getStartTimestamp(): Date;
abstract getEndTimestamp(): Date;
abstract getTrackPoints(): TrackPoint[];
abstract getTrackPointsAndStatistics(): { points: TrackPoint[], statistics: TrackPointStatistics };
abstract toGeoJSON(): any;
@@ -71,6 +72,10 @@ abstract class GPXTreeNode<T extends GPXTreeElement<any>> extends GPXTreeElement
return this.getChildren()[this.getChildren().length - 1].getEndTimestamp();
}
getTrackPoints(): TrackPoint[] {
return this.getChildren().flatMap((child) => child.getTrackPoints());
}
getTrackPointsAndStatistics(): { points: TrackPoint[]; statistics: TrackPointStatistics; } {
let points: TrackPoint[] = [];
let statistics: TrackPointStatistics = {
@@ -379,6 +384,10 @@ export class TrackSegment extends GPXTreeLeaf {
return this.trkpt[this.trkpt.length - 1].time;
}
getTrackPoints(): TrackPoint[] {
return this.trkpt;
}
getTrackPointsAndStatistics(): { points: TrackPoint[], statistics: TrackPointStatistics } {
return {
points: this.trkpt,