fix routing controls visibility on edges of the map

This commit is contained in:
vcoppe
2024-07-09 23:41:38 +02:00
parent e86dcb7750
commit bdcc554aaf

View File

@@ -1,5 +1,4 @@
import { distance, type Coordinates, TrackPoint, TrackSegment, Track } from "gpx";
import { original } from "immer";
import { get, writable, type Readable } from "svelte/store";
import mapboxgl from "mapbox-gl";
import { route } from "./Routing";
@@ -214,10 +213,14 @@ export class RoutingControls {
toggleAnchorsForZoomLevelAndBounds() { // Show markers only if they are in the current zoom level and bounds
this.shownAnchors.splice(0, this.shownAnchors.length);
let southWest = this.map.unproject([0, this.map.getCanvas().height]);
let northEast = this.map.unproject([this.map.getCanvas().width, 0]);
let bounds = new mapboxgl.LngLatBounds(southWest, northEast);
let zoom = this.map.getZoom();
this.anchors.forEach((anchor) => {
anchor.inZoom = anchor.point._data.zoom <= zoom;
if (anchor.inZoom && this.map.getBounds().contains(anchor.marker.getLngLat())) {
if (anchor.inZoom && bounds.contains(anchor.marker.getLngLat())) {
anchor.marker.addTo(this.map);
this.shownAnchors.push(anchor);
} else {