@vinctus/react-maplibre 0.2.11 → 0.2.13
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 +9 -2
- package/package.json +1 -1
package/dist/Map.js
CHANGED
|
@@ -47,8 +47,10 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
if (map)
|
|
49
49
|
return; // initialize map only once
|
|
50
|
+
let createdMap = null;
|
|
50
51
|
if (mapContainer.current) {
|
|
51
52
|
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, options));
|
|
53
|
+
createdMap = m;
|
|
52
54
|
if (onDragEnd)
|
|
53
55
|
addEventHandler(m, 'dragend', onDragEnd);
|
|
54
56
|
if (onLoad)
|
|
@@ -62,14 +64,19 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
62
64
|
addEventHandler(m, 'zoomend', onZoomEnd);
|
|
63
65
|
setMap(m);
|
|
64
66
|
}
|
|
67
|
+
return () => {
|
|
68
|
+
if (createdMap) {
|
|
69
|
+
createdMap.remove(); // This destroys the map and cleans up all layers/sources
|
|
70
|
+
setMap(null);
|
|
71
|
+
setMapLoaded(false);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
65
74
|
}, [
|
|
66
75
|
map,
|
|
67
76
|
onDragEnd,
|
|
68
77
|
onLoad,
|
|
69
78
|
onMoveEnd,
|
|
70
79
|
onZoomEnd,
|
|
71
|
-
setMap,
|
|
72
|
-
setMapLoaded,
|
|
73
80
|
mapStyle,
|
|
74
81
|
longitude,
|
|
75
82
|
latitude,
|