@vinctus/react-maplibre 0.2.23 → 0.2.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Map.js +11 -3
- package/package.json +1 -1
package/dist/Map.js
CHANGED
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import React, { useRef, useEffect, useState, useContext, useImperativeHandle, useMemo, } from 'react';
|
|
13
|
+
import React, { useRef, useEffect, useState, useContext, useImperativeHandle, useMemo, useCallback, } from 'react';
|
|
14
14
|
import maplibre from 'maplibre-gl';
|
|
15
15
|
import { ErrorBoundary } from './ErrorBoundary'; // eslint-disable-line import/no-webpack-loader-syntax
|
|
16
16
|
const DEFAULT_STYLE = 'https://demotiles.maplibre.org/style.json';
|
|
@@ -34,7 +34,13 @@ export const useMap = () => useContext(MapContext);
|
|
|
34
34
|
export const MapProvider = ({ children }) => {
|
|
35
35
|
const [map, setMap] = useState(null);
|
|
36
36
|
const [mapLoaded, setMapLoaded] = useState(false);
|
|
37
|
-
|
|
37
|
+
const stableSetMap = useCallback((newMap) => {
|
|
38
|
+
setMap(newMap);
|
|
39
|
+
}, []);
|
|
40
|
+
const stableSetMapLoaded = useCallback((loaded) => {
|
|
41
|
+
setMapLoaded(loaded);
|
|
42
|
+
}, []);
|
|
43
|
+
return (_jsx(MapContext.Provider, { value: { map, setMap: stableSetMap, mapLoaded, setMapLoaded: stableSetMapLoaded }, children: children }));
|
|
38
44
|
};
|
|
39
45
|
function addEventHandler(map, type, handler) {
|
|
40
46
|
map.on(type, (ev) => handler(Object.assign({ viewState: viewStateFromMap(map) }, ev)));
|
|
@@ -74,7 +80,7 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
74
80
|
return () => {
|
|
75
81
|
m.remove(); // This destroys the map and cleans up all layers/sources
|
|
76
82
|
mapInstanceRef.current = null;
|
|
77
|
-
|
|
83
|
+
setMap(null);
|
|
78
84
|
};
|
|
79
85
|
}
|
|
80
86
|
}, [
|
|
@@ -87,6 +93,8 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
87
93
|
onLoad,
|
|
88
94
|
onMoveEnd,
|
|
89
95
|
onZoomEnd,
|
|
96
|
+
setMap,
|
|
97
|
+
setMapLoaded,
|
|
90
98
|
]);
|
|
91
99
|
const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
|
|
92
100
|
return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
|