UNPKG

731 BJavaScriptView Raw
1import { useLeafletContext } from '@react-leaflet/core';
2import { useEffect } from 'react';
3export function useMap() {
4 return useLeafletContext().map;
5}
6export function useMapEvent(type, handler) {
7 const map = useMap();
8 useEffect(function addMapEventHandler() {
9 // @ts-ignore event type
10 map.on(type, handler);
11 return function removeMapEventHandler() {
12 // @ts-ignore event type
13 map.off(type, handler);
14 };
15 }, [map, type, handler]);
16 return map;
17}
18export function useMapEvents(handlers) {
19 const map = useMap();
20 useEffect(function addMapEventHandlers() {
21 map.on(handlers);
22 return function removeMapEventHandlers() {
23 map.off(handlers);
24 };
25 }, [map, handlers]);
26 return map;
27}
\No newline at end of file