Skip to content

Commit

Permalink
Zoom in locate control only on activation
Browse files Browse the repository at this point in the history
  • Loading branch information
cdauth committed Sep 3, 2024
1 parent 68b61eb commit c07d2e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
14 changes: 12 additions & 2 deletions frontend/src/lib/components/leaflet-map/leaflet-map-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function useLocateControl(map: Ref<Map>, context: FacilMapContext): Ref<Raw<Cont

let screenshotIconHtmlP = getIconHtml("currentColor", "1.5em", "screenshot");

return markRaw(control.locate({
const locateControl = control.locate({
flyTo: true,
markerStyle: { pane: "fm-raised-marker", zIndexOffset: 10000 },
locateOptions: {
Expand All @@ -217,7 +217,7 @@ function useLocateControl(map: Ref<Map>, context: FacilMapContext): Ref<Raw<Cont
inViewNotFollowing: "outOfView"
},
setView: "untilPan",
keepCurrentZoomLevel: true,
keepCurrentZoomLevel: false,
// These class names are not used anywhere, we just set them to avoid the default class names being set,
// which would apply the default icons using CSS.
icon: "fm-locate-control-icon",
Expand All @@ -229,6 +229,15 @@ function useLocateControl(map: Ref<Map>, context: FacilMapContext): Ref<Raw<Cont
}).catch(console.error);
return { link, icon };
}
});
return markRaw(Object.assign(Object.create(locateControl), {
setView(this: typeof locateControl) {
locateControl.setView.apply(this);

// After the control zoomed to the location on first activation, we keep the zoom level constant to not annoy
// the user. This is reset on the "locatedeactivate" event below.
this.options.keepCurrentZoomLevel = true;
}
}));
}
},
Expand All @@ -246,6 +255,7 @@ function useLocateControl(map: Ref<Map>, context: FacilMapContext): Ref<Raw<Cont
};
const handleDeactivate = () => {
active.value = false;
locateControl.options.keepCurrentZoomLevel = false;
};
map.on("locateactivate", handleActivate);
map.on("locatedeactivate", handleDeactivate);
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/type-fixup.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ declare module "leaflet" {

namespace Control {
const Heightgraph: any;

interface Locate {
options: LocateOptions;
}
}

namespace Draggable {
Expand Down

0 comments on commit c07d2e7

Please sign in to comment.