Small preact-based (like React.js) project
https://inga-lovinde.github.io/static/komoot-demo/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
572 B
24 lines
572 B
import leaflet from 'leaflet';
|
|
import { type Ref, useEffect } from 'preact/hooks';
|
|
|
|
export const useLayers = (
|
|
mapRef: Readonly<Ref<leaflet.Map | undefined>>,
|
|
layers: leaflet.Layer[],
|
|
) =>
|
|
useEffect(() => {
|
|
const map = mapRef.current;
|
|
if (!map) {
|
|
return;
|
|
}
|
|
|
|
for (const layer of layers) {
|
|
layer.addTo(map);
|
|
}
|
|
|
|
return () => {
|
|
for (const layer of layers) {
|
|
layer.removeFrom(map);
|
|
layer.remove();
|
|
}
|
|
};
|
|
}, [mapRef, layers]);
|
|
|