@vinctus/react-maplibre 0.2.12 → 0.2.14

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.
Files changed (2) hide show
  1. package/dist/Map.js +4 -4
  2. package/package.json +1 -1
package/dist/Map.js CHANGED
@@ -42,15 +42,17 @@ 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 initializationRef = useRef(false);
45
46
  const { map, setMap, setMapLoaded } = useMap();
46
47
  useImperativeHandle(ref, () => map, [map]);
47
48
  useEffect(() => {
48
- if (map)
49
+ if (initializationRef.current)
49
50
  return; // initialize map only once
50
51
  let createdMap = null;
51
52
  if (mapContainer.current) {
52
53
  const m = new maplibre.Map(Object.assign({ container: mapContainer.current, style: mapStyle, center: [longitude, latitude], zoom }, options));
53
54
  createdMap = m;
55
+ initializationRef.current = true;
54
56
  if (onDragEnd)
55
57
  addEventHandler(m, 'dragend', onDragEnd);
56
58
  if (onLoad)
@@ -69,16 +71,14 @@ export const Map = React.forwardRef((_a, ref) => {
69
71
  createdMap.remove(); // This destroys the map and cleans up all layers/sources
70
72
  setMap(null);
71
73
  setMapLoaded(false);
74
+ initializationRef.current = false;
72
75
  }
73
76
  };
74
77
  }, [
75
- map,
76
78
  onDragEnd,
77
79
  onLoad,
78
80
  onMoveEnd,
79
81
  onZoomEnd,
80
- setMap,
81
- setMapLoaded,
82
82
  mapStyle,
83
83
  longitude,
84
84
  latitude,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinctus/react-maplibre",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "description": "Minimalist MapLibre GL JS React wrapper library",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",