@vinctus/react-maplibre 0.2.14 → 0.2.16
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/GeolocateControl.js +6 -1
- package/dist/Layer.js +10 -11
- package/dist/Map.js +9 -24
- package/dist/NavigationControl.js +6 -1
- package/dist/ScaleControl.js +6 -1
- package/package.json +1 -1
package/dist/GeolocateControl.js
CHANGED
|
@@ -9,7 +9,12 @@ export const GeolocateControl = ({ position = 'bottom-right', options = { showUs
|
|
|
9
9
|
map.addControl(control, position);
|
|
10
10
|
}
|
|
11
11
|
return () => {
|
|
12
|
-
|
|
12
|
+
try {
|
|
13
|
+
map === null || map === void 0 ? void 0 : map.removeControl(control);
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
// Map might be destroyed already, ignore cleanup errors
|
|
17
|
+
}
|
|
13
18
|
};
|
|
14
19
|
}, [position, options, map]);
|
|
15
20
|
return null;
|
package/dist/Layer.js
CHANGED
|
@@ -16,18 +16,17 @@ export const Layer = ({ layer, source }) => {
|
|
|
16
16
|
return () => {
|
|
17
17
|
if (added && map) {
|
|
18
18
|
try {
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
map.removeLayer(parsedLayer.id); // when removing, the layer must be removed first, and then the source
|
|
22
|
-
}
|
|
23
|
-
// Check if source exists before removing
|
|
24
|
-
if (map.getSource(parsedLayer.id)) {
|
|
25
|
-
map.removeSource(parsedLayer.id);
|
|
26
|
-
}
|
|
19
|
+
// Try to remove layer and source, ignoring errors if map is destroyed
|
|
20
|
+
map.removeLayer(parsedLayer.id);
|
|
27
21
|
}
|
|
28
|
-
catch (
|
|
29
|
-
//
|
|
30
|
-
|
|
22
|
+
catch (_a) {
|
|
23
|
+
// Layer might not exist or map might be destroyed
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
map.removeSource(parsedLayer.id);
|
|
27
|
+
}
|
|
28
|
+
catch (_b) {
|
|
29
|
+
// Source might not exist or map might be destroyed
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
};
|
package/dist/Map.js
CHANGED
|
@@ -42,17 +42,15 @@ function addEventHandler(map, type, handler) {
|
|
|
42
42
|
export const Map = React.forwardRef((_a, ref) => {
|
|
43
43
|
var { children, style, id, longitude, latitude, maxPitch = DISABLE_PITCH, mapStyle = DEFAULT_STYLE, zoom, onDragEnd, onLoad, onMoveEnd, onZoomEnd, fallback } = _a, options = __rest(_a, ["children", "style", "id", "longitude", "latitude", "maxPitch", "mapStyle", "zoom", "onDragEnd", "onLoad", "onMoveEnd", "onZoomEnd", "fallback"]);
|
|
44
44
|
const mapContainer = useRef(null);
|
|
45
|
-
const
|
|
45
|
+
const mapInstanceRef = useRef(null);
|
|
46
46
|
const { map, setMap, setMapLoaded } = useMap();
|
|
47
47
|
useImperativeHandle(ref, () => map, [map]);
|
|
48
48
|
useEffect(() => {
|
|
49
|
-
if (
|
|
49
|
+
if (map)
|
|
50
50
|
return; // initialize map only once
|
|
51
|
-
let createdMap = null;
|
|
52
51
|
if (mapContainer.current) {
|
|
53
52
|
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, options));
|
|
54
|
-
|
|
55
|
-
initializationRef.current = true;
|
|
53
|
+
mapInstanceRef.current = m;
|
|
56
54
|
if (onDragEnd)
|
|
57
55
|
addEventHandler(m, 'dragend', onDragEnd);
|
|
58
56
|
if (onLoad)
|
|
@@ -65,26 +63,13 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
65
63
|
if (onZoomEnd)
|
|
66
64
|
addEventHandler(m, 'zoomend', onZoomEnd);
|
|
67
65
|
setMap(m);
|
|
66
|
+
// Cleanup when component unmounts
|
|
67
|
+
return () => {
|
|
68
|
+
m.remove(); // This destroys the map and cleans up all layers/sources
|
|
69
|
+
mapInstanceRef.current = null;
|
|
70
|
+
};
|
|
68
71
|
}
|
|
69
|
-
|
|
70
|
-
if (createdMap) {
|
|
71
|
-
createdMap.remove(); // This destroys the map and cleans up all layers/sources
|
|
72
|
-
setMap(null);
|
|
73
|
-
setMapLoaded(false);
|
|
74
|
-
initializationRef.current = false;
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
}, [
|
|
78
|
-
onDragEnd,
|
|
79
|
-
onLoad,
|
|
80
|
-
onMoveEnd,
|
|
81
|
-
onZoomEnd,
|
|
82
|
-
mapStyle,
|
|
83
|
-
longitude,
|
|
84
|
-
latitude,
|
|
85
|
-
zoom,
|
|
86
|
-
options,
|
|
87
|
-
]);
|
|
72
|
+
}, []); // Empty deps - only run once on mount
|
|
88
73
|
const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
|
|
89
74
|
return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
|
|
90
75
|
});
|
|
@@ -12,7 +12,12 @@ export const NavigationControl = ({ position = 'bottom-right', options = {
|
|
|
12
12
|
map.addControl(control, position);
|
|
13
13
|
}
|
|
14
14
|
return () => {
|
|
15
|
-
|
|
15
|
+
try {
|
|
16
|
+
map === null || map === void 0 ? void 0 : map.removeControl(control);
|
|
17
|
+
}
|
|
18
|
+
catch (_a) {
|
|
19
|
+
// Map might be destroyed already, ignore cleanup errors
|
|
20
|
+
}
|
|
16
21
|
};
|
|
17
22
|
}, [position, options, map]);
|
|
18
23
|
return null;
|
package/dist/ScaleControl.js
CHANGED
|
@@ -9,7 +9,12 @@ export const ScaleControl = ({ position = 'bottom-right', options, }) => {
|
|
|
9
9
|
map.addControl(control, position);
|
|
10
10
|
}
|
|
11
11
|
return () => {
|
|
12
|
-
|
|
12
|
+
try {
|
|
13
|
+
map === null || map === void 0 ? void 0 : map.removeControl(control);
|
|
14
|
+
}
|
|
15
|
+
catch (_a) {
|
|
16
|
+
// Map might be destroyed already, ignore cleanup errors
|
|
17
|
+
}
|
|
13
18
|
};
|
|
14
19
|
}, [position, options, map]);
|
|
15
20
|
return null;
|