fix anchors for new files

This commit is contained in:
vcoppe
2024-05-04 00:06:03 +02:00
parent f92748871e
commit c9bc13a1c5
2 changed files with 12 additions and 14 deletions

View File

@@ -195,9 +195,9 @@ export class Track extends GPXTreeNode<TrackSegment> {
this.link = track.link;
this.type = track.type;
this.trkseg = track.trkseg ? track.trkseg.map((seg) => new TrackSegment(seg)) : [];
this.extensions = cloneJSON(track.extensions);
this.extensions = track.extensions;
if (track.hasOwnProperty('_data')) {
this._data = cloneJSON(track._data);
this._data = track._data;
}
} else {
this.trkseg = [new TrackSegment()];
@@ -263,7 +263,7 @@ export class TrackSegment extends GPXTreeLeaf {
if (segment) {
this.trkpt = segment.trkpt.map((point) => new TrackPoint(point));
if (segment.hasOwnProperty('_data')) {
this._data = cloneJSON(segment._data);
this._data = segment._data;
}
} else {
this.trkpt = [];

View File

@@ -65,22 +65,20 @@ export class RoutingControls {
for (let segmentIndex = 0; segmentIndex < segments.length; segmentIndex++) {
let segment = segments[segmentIndex];
if (segment.trkpt.length === 0) { // Empty segment, skip
continue;
}
if (!segment._data.anchors) { // New segment, compute anchor points for it
computeAnchorPoints(segment);
}
if (!segment.trkpt[0]._data.anchor) { // First point is not an anchor, make it one
segment.trkpt[0]._data.anchor = true;
segment.trkpt[0]._data.zoom = 0;
}
if (segment.trkpt.length > 0) {
if (!segment.trkpt[0]._data.anchor) { // First point is not an anchor, make it one
segment.trkpt[0]._data.anchor = true;
segment.trkpt[0]._data.zoom = 0;
}
if (!segment.trkpt[segment.trkpt.length - 1]._data.anchor) { // Last point is not an anchor, make it one
segment.trkpt[segment.trkpt.length - 1]._data.anchor = true;
segment.trkpt[segment.trkpt.length - 1]._data.zoom = 0;
if (!segment.trkpt[segment.trkpt.length - 1]._data.anchor) { // Last point is not an anchor, make it one
segment.trkpt[segment.trkpt.length - 1]._data.anchor = true;
segment.trkpt[segment.trkpt.length - 1]._data.zoom = 0;
}
}
for (let point of segment.trkpt) { // Update the existing anchors (could be improved by matching the existing anchors with the new ones?)