Skip to content

Commit

Permalink
change autozoom logic
Browse files Browse the repository at this point in the history
  • Loading branch information
derGraph committed Sep 5, 2024
1 parent 065c181 commit d5c1ca7
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lib/Leaflet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let map: L.Map | undefined;
let mapElement: HTMLDivElement;
let lines: L.Polyline[][] = [];
let oldBounds: L.LatLngBoundsExpression | undefined;
let mapMoved: Boolean = false;
onMount(() => {
map = L.map(mapElement);
Expand Down Expand Up @@ -51,11 +51,14 @@
$: if (map) {
if (bounds) {
map.fitBounds(bounds);
oldBounds = map.getBounds();
} else if (view && zoom) {
map.setView(view, zoom);
oldBounds = map.getBounds();
}
map?.on("mousedown", onMouseDown);
}
function onMouseDown(ev: {}){
mapMoved = true;
}
$: onTracksChange(tracks);
Expand Down Expand Up @@ -141,10 +144,9 @@
maxBounds.extend(line.getBounds());
});
});
if (map?.getBounds().isValid()) {
if (map?.getBounds().equals(oldBounds!) && maxBounds.isValid()) {
if (map?.getBounds().isValid() && !mapMoved) {
if (maxBounds.isValid()) {
map?.fitBounds(maxBounds);
oldBounds = maxBounds;
}
}
}
Expand Down

0 comments on commit d5c1ca7

Please sign in to comment.