@vinctus/react-maplibre 0.2.18 → 0.2.20
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/ErrorBoundary.js +2 -1
- package/dist/GeolocateControl.js +1 -1
- package/dist/Layer.js +2 -2
- package/dist/Map.js +23 -8
- package/dist/Marker.js +6 -5
- package/dist/NavigationControl.js +1 -1
- package/dist/Popup.js +3 -2
- package/dist/ScaleControl.js +1 -1
- package/package.json +1 -1
package/dist/ErrorBoundary.js
CHANGED
|
@@ -13,8 +13,9 @@ export class ErrorBoundary extends Component {
|
|
|
13
13
|
console.error('Uncaught map error:', error, errorInfo);
|
|
14
14
|
}
|
|
15
15
|
render() {
|
|
16
|
-
if (this.state.hasError)
|
|
16
|
+
if (this.state.hasError) {
|
|
17
17
|
return this.props.fallback || _jsx("h1", { children: "Sorry.. there was a map error" });
|
|
18
|
+
}
|
|
18
19
|
return this.props.children;
|
|
19
20
|
}
|
|
20
21
|
}
|
package/dist/GeolocateControl.js
CHANGED
|
@@ -3,7 +3,7 @@ import maplibre from 'maplibre-gl';
|
|
|
3
3
|
import { useMap } from './Map';
|
|
4
4
|
export const GeolocateControl = ({ position = 'bottom-right', options = { showUserLocation: false }, }) => {
|
|
5
5
|
const { map } = useMap();
|
|
6
|
-
const optionsString = JSON.stringify(options);
|
|
6
|
+
const optionsString = JSON.stringify(options || {});
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
const control = new maplibre.GeolocateControl(JSON.parse(optionsString));
|
|
9
9
|
if (map && position) {
|
package/dist/Layer.js
CHANGED
|
@@ -16,11 +16,11 @@ export const Layer = ({ layer, source }) => {
|
|
|
16
16
|
return () => {
|
|
17
17
|
if (map) {
|
|
18
18
|
// Check if layer exists before removing
|
|
19
|
-
if (map.getLayer
|
|
19
|
+
if (map.getLayer(parsedLayer.id)) {
|
|
20
20
|
map.removeLayer(parsedLayer.id); // when removing, the layer must be removed first, and then the source
|
|
21
21
|
}
|
|
22
22
|
// Check if source exists before removing
|
|
23
|
-
if (map.getSource
|
|
23
|
+
if (map.getSource(parsedLayer.id)) {
|
|
24
24
|
map.removeSource(parsedLayer.id);
|
|
25
25
|
}
|
|
26
26
|
}
|
package/dist/Map.js
CHANGED
|
@@ -44,34 +44,49 @@ export const Map = React.forwardRef((_a, ref) => {
|
|
|
44
44
|
const mapContainer = useRef(null);
|
|
45
45
|
const mapInstanceRef = useRef(null);
|
|
46
46
|
const { map, setMap, setMapLoaded } = useMap();
|
|
47
|
-
const optionsString = JSON.stringify(options);
|
|
47
|
+
const optionsString = JSON.stringify(options || {});
|
|
48
48
|
useImperativeHandle(ref, () => map, [map]);
|
|
49
49
|
useEffect(() => {
|
|
50
|
-
if (map)
|
|
51
|
-
return; // initialize map only once
|
|
52
50
|
if (mapContainer.current) {
|
|
53
51
|
const parsedOptions = JSON.parse(optionsString);
|
|
54
52
|
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, parsedOptions));
|
|
55
53
|
mapInstanceRef.current = m;
|
|
56
|
-
if (onDragEnd)
|
|
54
|
+
if (onDragEnd) {
|
|
57
55
|
addEventHandler(m, 'dragend', onDragEnd);
|
|
58
|
-
|
|
56
|
+
}
|
|
57
|
+
if (onLoad) {
|
|
59
58
|
addEventHandler(m, 'load', (ev) => {
|
|
60
59
|
onLoad(ev);
|
|
61
60
|
setMapLoaded(true);
|
|
62
61
|
});
|
|
63
|
-
|
|
62
|
+
}
|
|
63
|
+
if (onMoveEnd) {
|
|
64
64
|
addEventHandler(m, 'moveend', onMoveEnd);
|
|
65
|
-
|
|
65
|
+
}
|
|
66
|
+
if (onZoomEnd) {
|
|
66
67
|
addEventHandler(m, 'zoomend', onZoomEnd);
|
|
68
|
+
}
|
|
67
69
|
setMap(m);
|
|
68
70
|
// Cleanup when component unmounts
|
|
69
71
|
return () => {
|
|
70
72
|
m.remove(); // This destroys the map and cleans up all layers/sources
|
|
71
73
|
mapInstanceRef.current = null;
|
|
74
|
+
setMap(null);
|
|
72
75
|
};
|
|
73
76
|
}
|
|
74
|
-
}, [
|
|
77
|
+
}, [
|
|
78
|
+
mapStyle,
|
|
79
|
+
longitude,
|
|
80
|
+
latitude,
|
|
81
|
+
zoom,
|
|
82
|
+
optionsString,
|
|
83
|
+
onDragEnd,
|
|
84
|
+
onLoad,
|
|
85
|
+
onMoveEnd,
|
|
86
|
+
onZoomEnd,
|
|
87
|
+
setMap,
|
|
88
|
+
setMapLoaded,
|
|
89
|
+
]);
|
|
75
90
|
const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
|
|
76
91
|
return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
|
|
77
92
|
});
|
package/dist/Marker.js
CHANGED
|
@@ -21,11 +21,12 @@ export const Marker = (_a) => {
|
|
|
21
21
|
const markerRef = useRef(null);
|
|
22
22
|
const popupRef = useRef(null);
|
|
23
23
|
const cleanupRef = useRef(null);
|
|
24
|
-
const optionsString = JSON.stringify(options);
|
|
25
|
-
const popupString = JSON.stringify(popup);
|
|
24
|
+
const optionsString = JSON.stringify(options || {});
|
|
25
|
+
const popupString = JSON.stringify(popup || null);
|
|
26
26
|
useEffect(() => {
|
|
27
|
-
if (!map)
|
|
27
|
+
if (!map) {
|
|
28
28
|
return;
|
|
29
|
+
}
|
|
29
30
|
const element = document.createElement('div');
|
|
30
31
|
const parsedOptions = JSON.parse(optionsString);
|
|
31
32
|
setResult(ReactDOM.createPortal(children, element));
|
|
@@ -34,8 +35,8 @@ export const Marker = (_a) => {
|
|
|
34
35
|
marker.setLngLat([longitude, latitude]).addTo(map);
|
|
35
36
|
markerRef.current = marker;
|
|
36
37
|
// Handle popup manually if provided
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const parsedPopup = JSON.parse(popupString);
|
|
39
|
+
if (parsedPopup) {
|
|
39
40
|
const popupHTML = ReactDOMServer.renderToStaticMarkup(parsedPopup);
|
|
40
41
|
const handleMarkerClick = (e) => {
|
|
41
42
|
e.stopPropagation();
|
|
@@ -6,7 +6,7 @@ export const NavigationControl = ({ position = 'bottom-right', options = {
|
|
|
6
6
|
showCompass: false,
|
|
7
7
|
}, }) => {
|
|
8
8
|
const { map } = useMap();
|
|
9
|
-
const optionsString = JSON.stringify(options);
|
|
9
|
+
const optionsString = JSON.stringify(options || {});
|
|
10
10
|
useEffect(() => {
|
|
11
11
|
const control = new maplibre.NavigationControl(JSON.parse(optionsString));
|
|
12
12
|
if (map && position) {
|
package/dist/Popup.js
CHANGED
|
@@ -16,7 +16,7 @@ import ReactDOMServer from 'react-dom/server'; // eslint-disable-line import/no-
|
|
|
16
16
|
export const Popup = (_a) => {
|
|
17
17
|
var { children, longitude, latitude } = _a, options = __rest(_a, ["children", "longitude", "latitude"]);
|
|
18
18
|
const { map } = useMap();
|
|
19
|
-
const optionsString = JSON.stringify(options);
|
|
19
|
+
const optionsString = JSON.stringify(options || {});
|
|
20
20
|
useEffect(() => {
|
|
21
21
|
let popup = null;
|
|
22
22
|
if (map) {
|
|
@@ -26,8 +26,9 @@ export const Popup = (_a) => {
|
|
|
26
26
|
.addTo(map);
|
|
27
27
|
}
|
|
28
28
|
return () => {
|
|
29
|
-
if (popup)
|
|
29
|
+
if (popup) {
|
|
30
30
|
popup.remove();
|
|
31
|
+
}
|
|
31
32
|
};
|
|
32
33
|
}, [children, latitude, longitude, map, optionsString]);
|
|
33
34
|
return null;
|
package/dist/ScaleControl.js
CHANGED
|
@@ -3,7 +3,7 @@ import maplibre from 'maplibre-gl';
|
|
|
3
3
|
import { useMap } from './Map';
|
|
4
4
|
export const ScaleControl = ({ position = 'bottom-right', options }) => {
|
|
5
5
|
const { map } = useMap();
|
|
6
|
-
const optionsString = JSON.stringify(options);
|
|
6
|
+
const optionsString = JSON.stringify(options || {});
|
|
7
7
|
useEffect(() => {
|
|
8
8
|
const control = new maplibre.ScaleControl(JSON.parse(optionsString));
|
|
9
9
|
if (map && position) {
|