import { useLeafletContext } from '@react-leaflet/core' ; import { LeafletEventHandlerFnMap , Map } from 'leaflet' ; import { useEffect } from 'react' ; export function useMap ( ) { return useLeafletContext ( ) . map ; } export function useMapEvent < T extends keyof LeafletEventHandlerFnMap > ( type , handler ) { const map = useMap ( ) ; useEffect ( function addMapEventHandler ( ) { map . on ( type , handler ) ; return function removeMapEventHandler ( ) { 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 ; }