mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 23:53:25 +00:00
fix routing anchor visibility for any bearing
This commit is contained in:
@@ -81,7 +81,6 @@ export class RoutingControls {
|
|||||||
add() {
|
add() {
|
||||||
this.active = true;
|
this.active = true;
|
||||||
|
|
||||||
this.map.on('zoom', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
|
||||||
this.map.on('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
this.map.on('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
||||||
this.map.on('click', this.appendAnchorBinded);
|
this.map.on('click', this.appendAnchorBinded);
|
||||||
this.map.on('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
this.map.on('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
||||||
@@ -129,7 +128,6 @@ export class RoutingControls {
|
|||||||
for (let anchor of this.anchors) {
|
for (let anchor of this.anchors) {
|
||||||
anchor.marker.remove();
|
anchor.marker.remove();
|
||||||
}
|
}
|
||||||
this.map.off('zoom', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
|
||||||
this.map.off('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
this.map.off('move', this.toggleAnchorsForZoomLevelAndBoundsBinded);
|
||||||
this.map.off('click', this.appendAnchorBinded);
|
this.map.off('click', this.appendAnchorBinded);
|
||||||
this.map.off('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
this.map.off('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
||||||
@@ -228,14 +226,15 @@ export class RoutingControls {
|
|||||||
toggleAnchorsForZoomLevelAndBounds() { // Show markers only if they are in the current zoom level and bounds
|
toggleAnchorsForZoomLevelAndBounds() { // Show markers only if they are in the current zoom level and bounds
|
||||||
this.shownAnchors.splice(0, this.shownAnchors.length);
|
this.shownAnchors.splice(0, this.shownAnchors.length);
|
||||||
|
|
||||||
let southWest = this.map.unproject([0, this.map.getCanvas().height]);
|
let center = this.map.getCenter();
|
||||||
let northEast = this.map.unproject([this.map.getCanvas().width, 0]);
|
let bottomLeft = this.map.unproject([0, this.map.getCanvas().height]);
|
||||||
let bounds = new mapboxgl.LngLatBounds(southWest, northEast);
|
let topRight = this.map.unproject([this.map.getCanvas().width, 0]);
|
||||||
|
let diagonal = bottomLeft.distanceTo(topRight);
|
||||||
|
|
||||||
let zoom = this.map.getZoom();
|
let zoom = this.map.getZoom();
|
||||||
this.anchors.forEach((anchor) => {
|
this.anchors.forEach((anchor) => {
|
||||||
anchor.inZoom = anchor.point._data.zoom <= zoom;
|
anchor.inZoom = anchor.point._data.zoom <= zoom;
|
||||||
if (anchor.inZoom && bounds.contains(anchor.marker.getLngLat())) {
|
if (anchor.inZoom && center.distanceTo(anchor.marker.getLngLat()) < diagonal) {
|
||||||
anchor.marker.addTo(this.map);
|
anchor.marker.addTo(this.map);
|
||||||
this.shownAnchors.push(anchor);
|
this.shownAnchors.push(anchor);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user