@vinctus/react-maplibre 0.2.19 → 0.2.21

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.
@@ -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/Map.js CHANGED
@@ -44,12 +44,9 @@ 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
- }
53
50
  if (mapContainer.current) {
54
51
  const parsedOptions = JSON.parse(optionsString);
55
52
  const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, parsedOptions));
@@ -74,9 +71,22 @@ export const Map = React.forwardRef((_a, ref) => {
74
71
  return () => {
75
72
  m.remove(); // This destroys the map and cleans up all layers/sources
76
73
  mapInstanceRef.current = null;
74
+ setMap(null);
77
75
  };
78
76
  }
79
- }, [map, mapStyle, longitude, latitude, zoom, optionsString, onDragEnd, onLoad, onMoveEnd, onZoomEnd, setMap, setMapLoaded]);
77
+ }, [
78
+ mapStyle,
79
+ longitude,
80
+ latitude,
81
+ zoom,
82
+ optionsString,
83
+ onDragEnd,
84
+ onLoad,
85
+ onMoveEnd,
86
+ onZoomEnd,
87
+ setMap,
88
+ setMapLoaded,
89
+ ]);
80
90
  const memoizedStyle = useMemo(() => (Object.assign({ position: 'relative', width: '100%', height: '100%' }, style)), [style]);
81
91
  return (_jsx(ErrorBoundary, { fallback: fallback, children: _jsx("div", { id: id, ref: mapContainer, style: memoizedStyle, children: children }) }));
82
92
  });
package/dist/Marker.js CHANGED
@@ -21,8 +21,7 @@ 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 || {});
26
25
  useEffect(() => {
27
26
  if (!map) {
28
27
  return;
@@ -36,8 +35,7 @@ export const Marker = (_a) => {
36
35
  markerRef.current = marker;
37
36
  // Handle popup manually if provided
38
37
  if (popup) {
39
- const parsedPopup = JSON.parse(popupString);
40
- const popupHTML = ReactDOMServer.renderToStaticMarkup(parsedPopup);
38
+ const popupHTML = ReactDOMServer.renderToStaticMarkup(popup);
41
39
  const handleMarkerClick = (e) => {
42
40
  e.stopPropagation();
43
41
  // Close existing popup if any
@@ -86,6 +84,6 @@ export const Marker = (_a) => {
86
84
  markerRef.current = null;
87
85
  }
88
86
  };
89
- }, [map, optionsString, children, longitude, latitude, popupString, closeOnClick, closeButton, popupClassName]);
87
+ }, [map, optionsString, children, longitude, latitude, popup, closeOnClick, closeButton, popupClassName]);
90
88
  return result;
91
89
  };
@@ -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) {
@@ -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) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinctus/react-maplibre",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "Minimalist MapLibre GL JS React wrapper library",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",