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.
34 lines
848 B
34 lines
848 B
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; |
|
}
|
|
|