maplibre-gl-layer-control 0.11.0 → 0.12.0

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/index.cjs CHANGED
@@ -685,6 +685,7 @@ class LayerControl {
685
685
  __publicField(this, "excludeLayerPatterns");
686
686
  __publicField(this, "customLayerRegistry", null);
687
687
  __publicField(this, "customLayerUnsubscribe", null);
688
+ __publicField(this, "removedCustomLayerIds", /* @__PURE__ */ new Set());
688
689
  __publicField(this, "basemapStyleUrl", null);
689
690
  __publicField(this, "basemapLayerIds", null);
690
691
  __publicField(this, "widthSliderEl", null);
@@ -1483,7 +1484,10 @@ class LayerControl {
1483
1484
  }
1484
1485
  });
1485
1486
  if (this.customLayerRegistry) {
1486
- this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
1487
+ this.customLayerUnsubscribe = this.customLayerRegistry.onChange((event, layerId) => {
1488
+ if (event === "add" && layerId) {
1489
+ this.removedCustomLayerIds.delete(layerId);
1490
+ }
1487
1491
  setTimeout(() => this.checkForNewLayers(), 100);
1488
1492
  });
1489
1493
  }
@@ -2147,6 +2151,17 @@ class LayerControl {
2147
2151
  content.appendChild(infoText);
2148
2152
  const actions = document.createElement("div");
2149
2153
  actions.className = "style-editor-actions";
2154
+ const removeBtn = document.createElement("button");
2155
+ removeBtn.className = "style-editor-button style-editor-button-remove";
2156
+ removeBtn.textContent = "Remove";
2157
+ removeBtn.title = "Remove layer from map";
2158
+ removeBtn.addEventListener("click", (e) => {
2159
+ e.stopPropagation();
2160
+ if (confirm("Are you sure you want to remove this layer?")) {
2161
+ this.closeStyleEditor(layerId);
2162
+ this.removeLayer(layerId);
2163
+ }
2164
+ });
2150
2165
  const closeActionBtn = document.createElement("button");
2151
2166
  closeActionBtn.className = "style-editor-button style-editor-button-close";
2152
2167
  closeActionBtn.textContent = "Close";
@@ -2154,6 +2169,7 @@ class LayerControl {
2154
2169
  e.stopPropagation();
2155
2170
  this.closeStyleEditor(layerId);
2156
2171
  });
2172
+ actions.appendChild(removeBtn);
2157
2173
  actions.appendChild(closeActionBtn);
2158
2174
  editor.appendChild(header);
2159
2175
  editor.appendChild(content);
@@ -2629,7 +2645,7 @@ class LayerControl {
2629
2645
  if (this.customLayerRegistry) {
2630
2646
  const customLayerIds = this.customLayerRegistry.getAllLayerIds();
2631
2647
  customLayerIds.forEach((layerId) => {
2632
- if (!this.state.layerStates[layerId]) {
2648
+ if (!this.state.layerStates[layerId] && !this.removedCustomLayerIds.has(layerId)) {
2633
2649
  const customState = this.customLayerRegistry.getLayerState(layerId);
2634
2650
  if (customState) {
2635
2651
  this.state.layerStates[layerId] = {
@@ -2670,7 +2686,10 @@ class LayerControl {
2670
2686
  registerCustomAdapter(adapter) {
2671
2687
  if (!this.customLayerRegistry) {
2672
2688
  this.customLayerRegistry = new CustomLayerRegistry();
2673
- this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
2689
+ this.customLayerUnsubscribe = this.customLayerRegistry.onChange((event, layerId) => {
2690
+ if (event === "add" && layerId) {
2691
+ this.removedCustomLayerIds.delete(layerId);
2692
+ }
2674
2693
  this.checkForNewLayers();
2675
2694
  });
2676
2695
  }
@@ -3085,27 +3104,28 @@ class LayerControl {
3085
3104
  var _a, _b;
3086
3105
  const layerState = this.state.layerStates[layerId];
3087
3106
  if ((layerState == null ? void 0 : layerState.isCustomLayer) && this.customLayerRegistry) {
3107
+ this.removedCustomLayerIds.add(layerId);
3108
+ this.customLayerRegistry.setVisibility(layerId, false);
3088
3109
  this.customLayerRegistry.removeLayer(layerId);
3089
- } else {
3090
- try {
3091
- const layer = this.map.getLayer(layerId);
3092
- if (layer) {
3093
- const sourceId = layer.source;
3094
- this.map.removeLayer(layerId);
3095
- if (sourceId) {
3096
- const style = this.map.getStyle();
3097
- const sourceStillUsed = (_a = style == null ? void 0 : style.layers) == null ? void 0 : _a.some((l) => l.source === sourceId);
3098
- if (!sourceStillUsed) {
3099
- try {
3100
- this.map.removeSource(sourceId);
3101
- } catch (e) {
3102
- }
3110
+ }
3111
+ try {
3112
+ const layer = this.map.getLayer(layerId);
3113
+ if (layer) {
3114
+ const sourceId = layer.source;
3115
+ this.map.removeLayer(layerId);
3116
+ if (sourceId) {
3117
+ const style = this.map.getStyle();
3118
+ const sourceStillUsed = (_a = style == null ? void 0 : style.layers) == null ? void 0 : _a.some((l) => l.source === sourceId);
3119
+ if (!sourceStillUsed) {
3120
+ try {
3121
+ this.map.removeSource(sourceId);
3122
+ } catch (e) {
3103
3123
  }
3104
3124
  }
3105
3125
  }
3106
- } catch (error) {
3107
- console.warn(`Failed to remove layer ${layerId}:`, error);
3108
3126
  }
3127
+ } catch (error) {
3128
+ console.warn(`Failed to remove layer ${layerId}:`, error);
3109
3129
  }
3110
3130
  delete this.state.layerStates[layerId];
3111
3131
  this.state.customLayerNames.delete(layerId);