File size: 848 Bytes
d2efaca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import { useLeafletContext } from '@react-leaflet/core';
import { useEffect } from 'react';
export function useMap() {
return useLeafletContext().map;
}
export function useMapEvent(type, handler) {
const map = useMap();
useEffect(function addMapEventHandler() {
// @ts-ignore event type
map.on(type, handler);
return function removeMapEventHandler() {
// @ts-ignore event type
map.off(type, handler);
};
}, [
map,
type,
handler
]);
return map;
}
export function useMapEvents(handlers) {
const map = useMap();
useEffect(function addMapEventHandlers() {
map.on(handlers);
return function removeMapEventHandlers() {
map.off(handlers);
};
}, [
map,
handlers
]);
return map;
}
|