Improve leaflet type handing

This commit is contained in:
Timothy Armes
2024-10-01 15:07:35 +02:00
parent ac77459afb
commit 0aaf14e112
5 changed files with 54 additions and 48 deletions
+1 -14
View File
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef } from "react";
import React from "react";
import { useAtomValue, useSetAtom } from "jotai";
import L, { DomUtil, LatLngLiteral, Marker } from "leaflet";
import L, { BouncingMarker, DomUtil, LatLngLiteral, Marker } from "leaflet";
import "leaflet-defaulticon-compatibility";
import "leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.css";
import "leaflet.smooth_marker_bouncing";
@@ -21,19 +21,6 @@ export type MarkerRef = {
bounce: () => void;
};
// Declare a class type that adds in methods etc. defined by leaflet.smooth_marker_bouncing
// to keep Typescript happy
declare class BouncingMarker extends Marker {
isBouncing(): boolean;
bounce(): void;
stopBouncing(): void;
_icon: HTMLElement;
_bouncingMotion?: {
bouncingAnimationPlaying: boolean;
};
}
const stopBouncingMarkers = () => {
const markers =
// @ts-ignore
+15 -16
View File
@@ -52,27 +52,26 @@ export const MapEvents = ({
map.addHandler("gestureHandling", GestureHandling);
// @ts-expect-error Typescript does not see additional handler here
map.gestureHandling.enable();
}, [map]);
map.gestureHandling?.enable();
}, [bounds, map]);
useEffect(() => {
console.log("setting map language", locale);
// @ts-expect-error Typescript does not see additional handler here
map.options.gestureHandlingOptions.text = {
touch: t("touch"),
scroll: t("scroll"),
scrollMac: t("scrollMac"),
};
if (
"gestureHandlingOptions" in map.options &&
map.options.gestureHandlingOptions
) {
map.options.gestureHandlingOptions.text = {
touch: t("touch"),
scroll: t("scroll"),
scrollMac: t("scrollMac"),
};
}
// We need to toggle the handler to update the text on prod. No idea why.
// @ts-expect-error Typescript does not see additional handler here
map.gestureHandling.disable();
// @ts-expect-error Typescript does not see additional handler here
map.gestureHandling.enable();
}, [map, locale]);
map.gestureHandling?.disable();
map.gestureHandling?.enable();
}, [map, locale, t]);
return null;
};