maplibre-gl-layer-control 0.10.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 +51 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +51 -19
- package/dist/index.mjs.map +1 -1
- package/dist/maplibre-gl-layer-control.css +13 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +1 -1
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);
|
|
@@ -2209,6 +2225,17 @@ class LayerControl {
|
|
|
2209
2225
|
e.stopPropagation();
|
|
2210
2226
|
this.resetLayerStyle(layerId);
|
|
2211
2227
|
});
|
|
2228
|
+
const removeBtn = document.createElement("button");
|
|
2229
|
+
removeBtn.className = "style-editor-button style-editor-button-remove";
|
|
2230
|
+
removeBtn.textContent = "Remove";
|
|
2231
|
+
removeBtn.title = "Remove layer from map";
|
|
2232
|
+
removeBtn.addEventListener("click", (e) => {
|
|
2233
|
+
e.stopPropagation();
|
|
2234
|
+
if (confirm("Are you sure you want to remove this layer?")) {
|
|
2235
|
+
this.closeStyleEditor(layerId);
|
|
2236
|
+
this.removeLayer(layerId);
|
|
2237
|
+
}
|
|
2238
|
+
});
|
|
2212
2239
|
const closeActionBtn = document.createElement("button");
|
|
2213
2240
|
closeActionBtn.className = "style-editor-button style-editor-button-close";
|
|
2214
2241
|
closeActionBtn.textContent = "Close";
|
|
@@ -2217,6 +2244,7 @@ class LayerControl {
|
|
|
2217
2244
|
this.closeStyleEditor(layerId);
|
|
2218
2245
|
});
|
|
2219
2246
|
actions.appendChild(resetBtn);
|
|
2247
|
+
actions.appendChild(removeBtn);
|
|
2220
2248
|
actions.appendChild(closeActionBtn);
|
|
2221
2249
|
editor.appendChild(header);
|
|
2222
2250
|
editor.appendChild(controls);
|
|
@@ -2617,7 +2645,7 @@ class LayerControl {
|
|
|
2617
2645
|
if (this.customLayerRegistry) {
|
|
2618
2646
|
const customLayerIds = this.customLayerRegistry.getAllLayerIds();
|
|
2619
2647
|
customLayerIds.forEach((layerId) => {
|
|
2620
|
-
if (!this.state.layerStates[layerId]) {
|
|
2648
|
+
if (!this.state.layerStates[layerId] && !this.removedCustomLayerIds.has(layerId)) {
|
|
2621
2649
|
const customState = this.customLayerRegistry.getLayerState(layerId);
|
|
2622
2650
|
if (customState) {
|
|
2623
2651
|
this.state.layerStates[layerId] = {
|
|
@@ -2658,7 +2686,10 @@ class LayerControl {
|
|
|
2658
2686
|
registerCustomAdapter(adapter) {
|
|
2659
2687
|
if (!this.customLayerRegistry) {
|
|
2660
2688
|
this.customLayerRegistry = new CustomLayerRegistry();
|
|
2661
|
-
this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
|
|
2689
|
+
this.customLayerUnsubscribe = this.customLayerRegistry.onChange((event, layerId) => {
|
|
2690
|
+
if (event === "add" && layerId) {
|
|
2691
|
+
this.removedCustomLayerIds.delete(layerId);
|
|
2692
|
+
}
|
|
2662
2693
|
this.checkForNewLayers();
|
|
2663
2694
|
});
|
|
2664
2695
|
}
|
|
@@ -3073,27 +3104,28 @@ class LayerControl {
|
|
|
3073
3104
|
var _a, _b;
|
|
3074
3105
|
const layerState = this.state.layerStates[layerId];
|
|
3075
3106
|
if ((layerState == null ? void 0 : layerState.isCustomLayer) && this.customLayerRegistry) {
|
|
3107
|
+
this.removedCustomLayerIds.add(layerId);
|
|
3108
|
+
this.customLayerRegistry.setVisibility(layerId, false);
|
|
3076
3109
|
this.customLayerRegistry.removeLayer(layerId);
|
|
3077
|
-
}
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
}
|
|
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) {
|
|
3091
3123
|
}
|
|
3092
3124
|
}
|
|
3093
3125
|
}
|
|
3094
|
-
} catch (error) {
|
|
3095
|
-
console.warn(`Failed to remove layer ${layerId}:`, error);
|
|
3096
3126
|
}
|
|
3127
|
+
} catch (error) {
|
|
3128
|
+
console.warn(`Failed to remove layer ${layerId}:`, error);
|
|
3097
3129
|
}
|
|
3098
3130
|
delete this.state.layerStates[layerId];
|
|
3099
3131
|
this.state.customLayerNames.delete(layerId);
|