@vinctus/react-maplibre 0.2.24 → 0.2.26
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 +1 -2
- package/dist/GeolocateControl.js +2 -3
- package/dist/Layer.js +0 -2
- package/dist/Map.js +8 -26
- package/dist/Marker.js +9 -6
- package/dist/NavigationControl.js +2 -3
- package/dist/Popup.js +2 -3
- package/dist/ScaleControl.js +3 -4
- package/package.json +1 -1
package/dist/ErrorBoundary.js
CHANGED
|
@@ -13,9 +13,8 @@ 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
|
-
}
|
|
19
18
|
return this.props.children;
|
|
20
19
|
}
|
|
21
20
|
}
|
package/dist/GeolocateControl.js
CHANGED
|
@@ -3,9 +3,8 @@ 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 || {});
|
|
7
6
|
useEffect(() => {
|
|
8
|
-
const control = new maplibre.GeolocateControl(
|
|
7
|
+
const control = new maplibre.GeolocateControl(options);
|
|
9
8
|
if (map && position) {
|
|
10
9
|
map.addControl(control, position);
|
|
11
10
|
}
|
|
@@ -14,6 +13,6 @@ export const GeolocateControl = ({ position = 'bottom-right', options = { showUs
|
|
|
14
13
|
map.removeControl(control);
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
|
-
}, [position,
|
|
16
|
+
}, [position, options, map]);
|
|
18
17
|
return null;
|
|
19
18
|
};
|
package/dist/Layer.js
CHANGED
|
@@ -5,11 +5,9 @@ export const Layer = ({ layer, source }) => {
|
|
|
5
5
|
const layerString = JSON.stringify(Object.assign({ source: layer.id }, layer));
|
|
6
6
|
const sourceString = JSON.stringify(source);
|
|
7
7
|
useEffect(() => {
|
|
8
|
-
let added = false;
|
|
9
8
|
const parsedSource = JSON.parse(sourceString);
|
|
10
9
|
const parsedLayer = JSON.parse(layerString);
|
|
11
10
|
if (map && mapLoaded) {
|
|
12
|
-
added = true;
|
|
13
11
|
map.addSource(parsedLayer.id, parsedSource); // when adding, the source must be added first, and then the layer
|
|
14
12
|
map.addLayer(parsedLayer);
|
|
15
13
|
}
|
package/dist/Map.js
CHANGED
|
@@ -44,50 +44,32 @@ 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 || {});
|
|
48
47
|
useImperativeHandle(ref, () => map, [map]);
|
|
49
48
|
useEffect(() => {
|
|
50
|
-
if (map)
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
49
|
+
if (map)
|
|
50
|
+
return; // initialize map only once
|
|
53
51
|
if (mapContainer.current) {
|
|
54
|
-
const
|
|
55
|
-
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, parsedOptions));
|
|
52
|
+
const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, options));
|
|
56
53
|
mapInstanceRef.current = m;
|
|
57
|
-
if (onDragEnd)
|
|
54
|
+
if (onDragEnd)
|
|
58
55
|
addEventHandler(m, 'dragend', onDragEnd);
|
|
59
|
-
|
|
60
|
-
if (onLoad) {
|
|
56
|
+
if (onLoad)
|
|
61
57
|
addEventHandler(m, 'load', (ev) => {
|
|
62
58
|
onLoad(ev);
|
|
63
59
|
setMapLoaded(true);
|
|
64
60
|
});
|
|
65
|
-
|
|
66
|
-
if (onMoveEnd) {
|
|
61
|
+
if (onMoveEnd)
|
|
67
62
|
addEventHandler(m, 'moveend', onMoveEnd);
|
|
68
|
-
|
|
69
|
-
if (onZoomEnd) {
|
|
63
|
+
if (onZoomEnd)
|
|
70
64
|
addEventHandler(m, 'zoomend', onZoomEnd);
|
|
71
|
-
}
|
|
72
65
|
setMap(m);
|
|
73
66
|
// Cleanup when component unmounts
|
|
74
67
|
return () => {
|
|
75
68
|
m.remove(); // This destroys the map and cleans up all layers/sources
|
|
76
69
|
mapInstanceRef.current = null;
|
|
77
|
-
setMap(null);
|
|
78
70
|
};
|
|
79
71
|
}
|
|
80
|
-
}, [
|
|
81
|
-
mapStyle,
|
|
82
|
-
longitude,
|
|
83
|
-
latitude,
|
|
84
|
-
zoom,
|
|
85
|
-
optionsString,
|
|
86
|
-
onDragEnd,
|
|
87
|
-
onLoad,
|
|
88
|
-
onMoveEnd,
|
|
89
|
-
onZoomEnd,
|
|
90
|
-
]);
|
|
72
|
+
}, []); // Empty deps - only run once on mount
|
|
91
73
|
const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
|
|
92
74
|
return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
|
|
93
75
|
});
|
package/dist/Marker.js
CHANGED
|
@@ -21,16 +21,19 @@ 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
|
|
24
|
+
const optionsString = JSON.stringify(options);
|
|
25
25
|
useEffect(() => {
|
|
26
|
-
if (!map)
|
|
26
|
+
if (!map)
|
|
27
27
|
return;
|
|
28
|
-
}
|
|
29
28
|
const element = document.createElement('div');
|
|
30
29
|
const parsedOptions = JSON.parse(optionsString);
|
|
31
|
-
|
|
30
|
+
if (children) {
|
|
31
|
+
setResult(ReactDOM.createPortal(children, element));
|
|
32
|
+
}
|
|
32
33
|
// Create marker
|
|
33
|
-
const marker =
|
|
34
|
+
const marker = children
|
|
35
|
+
? new maplibre.Marker(Object.assign(Object.assign({}, parsedOptions), { element }))
|
|
36
|
+
: new maplibre.Marker(Object.assign({}, parsedOptions));
|
|
34
37
|
marker.setLngLat([longitude, latitude]).addTo(map);
|
|
35
38
|
markerRef.current = marker;
|
|
36
39
|
// Handle popup manually if provided
|
|
@@ -84,6 +87,6 @@ export const Marker = (_a) => {
|
|
|
84
87
|
markerRef.current = null;
|
|
85
88
|
}
|
|
86
89
|
};
|
|
87
|
-
}, [map, optionsString, children, longitude, latitude, popup, closeOnClick, closeButton
|
|
90
|
+
}, [map, optionsString, children, longitude, latitude, popup, closeOnClick, closeButton]);
|
|
88
91
|
return result;
|
|
89
92
|
};
|
|
@@ -6,9 +6,8 @@ export const NavigationControl = ({ position = 'bottom-right', options = {
|
|
|
6
6
|
showCompass: false,
|
|
7
7
|
}, }) => {
|
|
8
8
|
const { map } = useMap();
|
|
9
|
-
const optionsString = JSON.stringify(options || {});
|
|
10
9
|
useEffect(() => {
|
|
11
|
-
const control = new maplibre.NavigationControl(
|
|
10
|
+
const control = new maplibre.NavigationControl(options);
|
|
12
11
|
if (map && position) {
|
|
13
12
|
map.addControl(control, position);
|
|
14
13
|
}
|
|
@@ -17,6 +16,6 @@ export const NavigationControl = ({ position = 'bottom-right', options = {
|
|
|
17
16
|
map.removeControl(control);
|
|
18
17
|
}
|
|
19
18
|
};
|
|
20
|
-
}, [position,
|
|
19
|
+
}, [position, options, map]);
|
|
21
20
|
return null;
|
|
22
21
|
};
|
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,9 +26,8 @@ export const Popup = (_a) => {
|
|
|
26
26
|
.addTo(map);
|
|
27
27
|
}
|
|
28
28
|
return () => {
|
|
29
|
-
if (popup)
|
|
29
|
+
if (popup)
|
|
30
30
|
popup.remove();
|
|
31
|
-
}
|
|
32
31
|
};
|
|
33
32
|
}, [children, latitude, longitude, map, optionsString]);
|
|
34
33
|
return null;
|
package/dist/ScaleControl.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import maplibre from 'maplibre-gl';
|
|
3
3
|
import { useMap } from './Map';
|
|
4
|
-
export const ScaleControl = ({ position = 'bottom-right', options }) => {
|
|
4
|
+
export const ScaleControl = ({ position = 'bottom-right', options, }) => {
|
|
5
5
|
const { map } = useMap();
|
|
6
|
-
const optionsString = JSON.stringify(options || {});
|
|
7
6
|
useEffect(() => {
|
|
8
|
-
const control = new maplibre.ScaleControl(
|
|
7
|
+
const control = new maplibre.ScaleControl(options);
|
|
9
8
|
if (map && position) {
|
|
10
9
|
map.addControl(control, position);
|
|
11
10
|
}
|
|
@@ -14,6 +13,6 @@ export const ScaleControl = ({ position = 'bottom-right', options }) => {
|
|
|
14
13
|
map.removeControl(control);
|
|
15
14
|
}
|
|
16
15
|
};
|
|
17
|
-
}, [position,
|
|
16
|
+
}, [position, options, map]);
|
|
18
17
|
return null;
|
|
19
18
|
};
|