fix(touch_bar): jerkiness when zooming

This commit is contained in:
Elian Doran 2025-03-08 23:13:58 +02:00
parent 323f42873f
commit cbbe10ba67
No known key found for this signature in database
2 changed files with 10 additions and 2 deletions

View File

@ -52,8 +52,6 @@ export default class GeoMapWidget extends NoteContextAwareWidget {
this.initCallback(L);
}
map.addEventListener("zoom", () => this.triggerCommand("refreshTouchBar"));
L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors',
detectRetina: true

View File

@ -105,6 +105,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
private currentMarkerData: Record<string, Marker>;
private currentTrackData: Record<string, GPX>;
private gpxLoaded?: boolean;
private ignoreNextZoomEvent?: boolean;
static getType() {
return "geoMap";
@ -144,6 +145,13 @@ export default class GeoMapTypeWidget extends TypeWidget {
map.on("moveend", updateFn);
map.on("zoomend", updateFn);
map.on("click", (e) => this.#onMapClicked(e));
map.on("zoom", () => {
if (!this.ignoreNextZoomEvent) {
this.triggerCommand("refreshTouchBar");
}
this.ignoreNextZoomEvent = false;
});
}
async #restoreViewportAndZoom() {
@ -383,6 +391,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
buildTouchBarCommand({ TouchBar }: CommandListenerData<"buildTouchBar">) {
const map = this.geoMapWidget.map;
const that = this;
if (!map) {
return;
}
@ -394,6 +403,7 @@ export default class GeoMapTypeWidget extends TypeWidget {
minValue: map.getMinZoom(),
maxValue: map.getMaxZoom(),
change(newValue) {
that.ignoreNextZoomEvent = true;
map.setZoom(newValue);
},
}),