mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
waypoints reactive to file changes
This commit is contained in:
@@ -102,9 +102,19 @@ export class GPXLayer {
|
||||
this.map.on('mouseenter', this.layerId, toPointerCursor);
|
||||
this.map.on('mouseleave', this.layerId, toDefaultCursor);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.markers.length == 0) {
|
||||
get(this.file).wpt.forEach((waypoint) => {
|
||||
updateData() {
|
||||
let source = this.map.getSource(this.layerId);
|
||||
if (source) {
|
||||
source.setData(this.getGeoJSON());
|
||||
}
|
||||
|
||||
let markerIndex = 0;
|
||||
get(this.file).wpt.forEach((waypoint) => { // Update markers
|
||||
if (markerIndex < this.markers.length) {
|
||||
this.markers[markerIndex].setLngLat(waypoint.getCoordinates());
|
||||
} else {
|
||||
let marker = new mapboxgl.Marker().setLngLat(waypoint.getCoordinates());
|
||||
marker.getElement().addEventListener('click', (e) => {
|
||||
marker.setPopup(this.popup);
|
||||
@@ -113,7 +123,12 @@ export class GPXLayer {
|
||||
});
|
||||
|
||||
this.markers.push(marker);
|
||||
});
|
||||
}
|
||||
markerIndex++;
|
||||
});
|
||||
|
||||
while (markerIndex < this.markers.length) { // Remove extra markers
|
||||
this.markers.pop()?.remove();
|
||||
}
|
||||
|
||||
this.markers.forEach((marker) => {
|
||||
@@ -121,13 +136,6 @@ export class GPXLayer {
|
||||
});
|
||||
}
|
||||
|
||||
updateData() {
|
||||
let source = this.map.getSource(this.layerId);
|
||||
if (source) {
|
||||
source.setData(this.getGeoJSON());
|
||||
}
|
||||
}
|
||||
|
||||
remove() {
|
||||
this.map.off('click', this.layerId, this.selectOnClickBinded);
|
||||
this.map.off('mouseenter', this.layerId, toPointerCursor);
|
||||
|
Reference in New Issue
Block a user