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