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 | }, [map, type, handler]);
|
16 | return map;
|
17 | }
|
18 | export 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 |