mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
routing progress
This commit is contained in:
@@ -8,7 +8,7 @@ function cloneJSON<T>(obj: T): T {
|
||||
}
|
||||
|
||||
// An abstract class that groups functions that need to be computed recursively in the GPX file hierarchy
|
||||
abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
|
||||
export abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
|
||||
_data: { [key: string]: any } = {};
|
||||
|
||||
abstract isLeaf(): boolean;
|
||||
@@ -27,6 +27,8 @@ abstract class GPXTreeElement<T extends GPXTreeElement<any>> {
|
||||
abstract toGeoJSON(): GeoJSON.Feature | GeoJSON.Feature[] | GeoJSON.FeatureCollection | GeoJSON.FeatureCollection[];
|
||||
}
|
||||
|
||||
export type AnyGPXTreeElement = GPXTreeElement<GPXTreeElement<any>>;
|
||||
|
||||
// An abstract class that can be extended to facilitate functions working similarly with Tracks and TrackSegments
|
||||
abstract class GPXTreeNode<T extends GPXTreeElement<any>> extends GPXTreeElement<T> {
|
||||
isLeaf(): boolean {
|
||||
@@ -286,6 +288,7 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
const points = this.trkpt;
|
||||
for (let i = 0; i < points.length; i++) {
|
||||
points[i]._data['index'] = i;
|
||||
points[i]._data['segment'] = this;
|
||||
|
||||
// distance
|
||||
let dist = 0;
|
||||
@@ -370,6 +373,11 @@ export class TrackSegment extends GPXTreeLeaf {
|
||||
this._computeStatistics();
|
||||
}
|
||||
|
||||
replace(start: number, end: number, points: TrackPoint[]): void {
|
||||
this.trkpt.splice(start, end - start + 1, ...points);
|
||||
this._computeStatistics();
|
||||
}
|
||||
|
||||
reverse(originalNextTimestamp: Date | undefined, newPreviousTimestamp: Date | undefined): void {
|
||||
if (originalNextTimestamp !== undefined && newPreviousTimestamp !== undefined) {
|
||||
let originalEndTimestamp = this.getEndTimestamp();
|
||||
@@ -460,6 +468,10 @@ export class TrackPoint {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
setCoordinates(coordinates: Coordinates): void {
|
||||
this.attributes = coordinates;
|
||||
}
|
||||
|
||||
getLatitude(): number {
|
||||
return this.attributes.lat;
|
||||
}
|
||||
@@ -599,7 +611,7 @@ export type TrackPointStatistics = {
|
||||
}
|
||||
|
||||
const earthRadius = 6371008.8;
|
||||
function distance(coord1: Coordinates, coord2: Coordinates): number {
|
||||
export function distance(coord1: Coordinates, coord2: Coordinates): number {
|
||||
const rad = Math.PI / 180;
|
||||
const lat1 = coord1.lat * rad;
|
||||
const lat2 = coord2.lat * rad;
|
||||
|
Reference in New Issue
Block a user