@vinctus/react-maplibre 1.3.0 → 1.3.2
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/Layer.js +13 -7
- package/dist/Marker.js +4 -4
- package/dist/Popup.js +4 -17
- package/package.json +1 -1
package/dist/Layer.js
CHANGED
|
@@ -39,14 +39,18 @@ export const Layer = ({ layer, source }) => {
|
|
|
39
39
|
const { id } = layer;
|
|
40
40
|
const { paint, layout } = layer, layerStructure = __rest(layer, ["paint", "layout"]);
|
|
41
41
|
const { data } = source, sourceOptions = __rest(source, ["data"]);
|
|
42
|
+
const layerStructureString = JSON.stringify(layerStructure);
|
|
43
|
+
const paintString = JSON.stringify(paint !== null && paint !== void 0 ? paint : {});
|
|
44
|
+
const layoutString = JSON.stringify(layout !== null && layout !== void 0 ? layout : {});
|
|
45
|
+
const sourceOptionsString = JSON.stringify(sourceOptions);
|
|
46
|
+
const dataString = JSON.stringify(data);
|
|
42
47
|
const strings = {
|
|
43
|
-
layerStructureString
|
|
44
|
-
paintString
|
|
45
|
-
layoutString
|
|
46
|
-
sourceOptionsString
|
|
47
|
-
dataString
|
|
48
|
+
layerStructureString,
|
|
49
|
+
paintString,
|
|
50
|
+
layoutString,
|
|
51
|
+
sourceOptionsString,
|
|
52
|
+
dataString,
|
|
48
53
|
};
|
|
49
|
-
const { layerStructureString, paintString, layoutString, sourceOptionsString, dataString } = strings;
|
|
50
54
|
// Keeps the newest props available to the creation effect without making it depend on them, so
|
|
51
55
|
// that data, paint and layout changes update the existing source and layer in place.
|
|
52
56
|
const latest = useRef(strings);
|
|
@@ -76,7 +80,9 @@ export const Layer = ({ layer, source }) => {
|
|
|
76
80
|
}, [id, layerStructureString, sourceOptionsString, map, mapLoaded]);
|
|
77
81
|
useEffect(() => {
|
|
78
82
|
const current = applied.current;
|
|
79
|
-
|
|
83
|
+
// A replaced map is removed before the context hands out the new one, so this effect can run
|
|
84
|
+
// once more against the removed map.
|
|
85
|
+
if (!map || !mapLoaded || !current || map._removed) {
|
|
80
86
|
return;
|
|
81
87
|
}
|
|
82
88
|
// The source disappears when the map's style is replaced, so the source and layer are rebuilt
|
package/dist/Marker.js
CHANGED
|
@@ -51,8 +51,8 @@ export const Marker = ({ children, longitude, latitude, className, anchor, color
|
|
|
51
51
|
}
|
|
52
52
|
}, [marker, latitude, longitude]);
|
|
53
53
|
useEffect(() => {
|
|
54
|
-
|
|
55
|
-
if (!marker ||
|
|
54
|
+
const initialHtml = popupHtmlRef.current;
|
|
55
|
+
if (!marker || initialHtml === undefined) {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
const newPopup = new maplibre.Popup({
|
|
@@ -60,9 +60,9 @@ export const Marker = ({ children, longitude, latitude, className, anchor, color
|
|
|
60
60
|
closeButton,
|
|
61
61
|
closeOnClick,
|
|
62
62
|
className: popupClassName,
|
|
63
|
-
}).setHTML(
|
|
63
|
+
}).setHTML(initialHtml);
|
|
64
64
|
popupInstance.current = newPopup;
|
|
65
|
-
appliedPopupHtml.current =
|
|
65
|
+
appliedPopupHtml.current = initialHtml;
|
|
66
66
|
// Attaching the popup to the marker lets MapLibre toggle it on click and keep it anchored to
|
|
67
67
|
// the marker as the marker moves.
|
|
68
68
|
marker.setPopup(newPopup);
|
package/dist/Popup.js
CHANGED
|
@@ -11,7 +11,6 @@ export const Popup = ({ children, longitude, latitude, className, closeOnClick,
|
|
|
11
11
|
// that content and position changes update the existing popup instead of recreating it.
|
|
12
12
|
const latest = useRef({ html, coordinates: [longitude, latitude] });
|
|
13
13
|
const popupInstance = useRef(null);
|
|
14
|
-
const applied = useRef(null);
|
|
15
14
|
latest.current = { html, coordinates: [longitude, latitude] };
|
|
16
15
|
useEffect(() => {
|
|
17
16
|
if (!map || !mapLoaded) {
|
|
@@ -23,7 +22,6 @@ export const Popup = ({ children, longitude, latitude, className, closeOnClick,
|
|
|
23
22
|
.setHTML(initialHtml)
|
|
24
23
|
.addTo(map);
|
|
25
24
|
popupInstance.current = popup;
|
|
26
|
-
applied.current = { html: initialHtml, coordinates };
|
|
27
25
|
return () => {
|
|
28
26
|
try {
|
|
29
27
|
popup.remove();
|
|
@@ -32,26 +30,15 @@ export const Popup = ({ children, longitude, latitude, className, closeOnClick,
|
|
|
32
30
|
console.warn('Error cleaning up Popup');
|
|
33
31
|
}
|
|
34
32
|
popupInstance.current = null;
|
|
35
|
-
applied.current = null;
|
|
36
33
|
};
|
|
37
34
|
}, [map, mapLoaded, className, closeOnClick, closeButton]);
|
|
38
35
|
useEffect(() => {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (popup &&
|
|
42
|
-
current &&
|
|
43
|
-
(current.coordinates[0] !== longitude || current.coordinates[1] !== latitude)) {
|
|
44
|
-
popup.setLngLat([longitude, latitude]);
|
|
45
|
-
current.coordinates = [longitude, latitude];
|
|
46
|
-
}
|
|
36
|
+
var _a;
|
|
37
|
+
(_a = popupInstance.current) === null || _a === void 0 ? void 0 : _a.setLngLat([longitude, latitude]);
|
|
47
38
|
}, [longitude, latitude]);
|
|
48
39
|
useEffect(() => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (popup && current && current.html !== html) {
|
|
52
|
-
popup.setHTML(html);
|
|
53
|
-
current.html = html;
|
|
54
|
-
}
|
|
40
|
+
var _a;
|
|
41
|
+
(_a = popupInstance.current) === null || _a === void 0 ? void 0 : _a.setHTML(html);
|
|
55
42
|
}, [html]);
|
|
56
43
|
return null;
|
|
57
44
|
};
|