@vinctus/react-maplibre 0.2.16 → 0.2.17

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.
@@ -9,11 +9,8 @@ export const GeolocateControl = ({ position = 'bottom-right', options = { showUs
9
9
  map.addControl(control, position);
10
10
  }
11
11
  return () => {
12
- try {
13
- map === null || map === void 0 ? void 0 : map.removeControl(control);
14
- }
15
- catch (_a) {
16
- // Map might be destroyed already, ignore cleanup errors
12
+ if (map && map.hasControl && map.hasControl(control)) {
13
+ map.removeControl(control);
17
14
  }
18
15
  };
19
16
  }, [position, options, map]);
package/dist/Layer.js CHANGED
@@ -16,14 +16,19 @@ export const Layer = ({ layer, source }) => {
16
16
  return () => {
17
17
  if (added && map) {
18
18
  try {
19
- // Try to remove layer and source, ignoring errors if map is destroyed
20
- map.removeLayer(parsedLayer.id);
19
+ // Check if layer exists before removing
20
+ if (map.getLayer && map.getLayer(parsedLayer.id)) {
21
+ map.removeLayer(parsedLayer.id); // when removing, the layer must be removed first, and then the source
22
+ }
21
23
  }
22
24
  catch (_a) {
23
25
  // Layer might not exist or map might be destroyed
24
26
  }
25
27
  try {
26
- map.removeSource(parsedLayer.id);
28
+ // Check if source exists before removing
29
+ if (map.getSource && map.getSource(parsedLayer.id)) {
30
+ map.removeSource(parsedLayer.id);
31
+ }
27
32
  }
28
33
  catch (_b) {
29
34
  // Source might not exist or map might be destroyed
@@ -12,11 +12,8 @@ export const NavigationControl = ({ position = 'bottom-right', options = {
12
12
  map.addControl(control, position);
13
13
  }
14
14
  return () => {
15
- try {
16
- map === null || map === void 0 ? void 0 : map.removeControl(control);
17
- }
18
- catch (_a) {
19
- // Map might be destroyed already, ignore cleanup errors
15
+ if (map && map.hasControl && map.hasControl(control)) {
16
+ map.removeControl(control);
20
17
  }
21
18
  };
22
19
  }, [position, options, map]);
@@ -9,11 +9,8 @@ export const ScaleControl = ({ position = 'bottom-right', options, }) => {
9
9
  map.addControl(control, position);
10
10
  }
11
11
  return () => {
12
- try {
13
- map === null || map === void 0 ? void 0 : map.removeControl(control);
14
- }
15
- catch (_a) {
16
- // Map might be destroyed already, ignore cleanup errors
12
+ if (map && map.hasControl && map.hasControl(control)) {
13
+ map.removeControl(control);
17
14
  }
18
15
  };
19
16
  }, [position, options, map]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vinctus/react-maplibre",
3
- "version": "0.2.16",
3
+ "version": "0.2.17",
4
4
  "description": "Minimalist MapLibre GL JS React wrapper library",
5
5
  "type": "module",
6
6
  "types": "dist/index.d.ts",