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.mjs
CHANGED
|
@@ -683,6 +683,7 @@ class LayerControl {
|
|
|
683
683
|
__publicField(this, "excludeLayerPatterns");
|
|
684
684
|
__publicField(this, "customLayerRegistry", null);
|
|
685
685
|
__publicField(this, "customLayerUnsubscribe", null);
|
|
686
|
+
__publicField(this, "removedCustomLayerIds", /* @__PURE__ */ new Set());
|
|
686
687
|
__publicField(this, "basemapStyleUrl", null);
|
|
687
688
|
__publicField(this, "basemapLayerIds", null);
|
|
688
689
|
__publicField(this, "widthSliderEl", null);
|
|
@@ -1481,7 +1482,10 @@ class LayerControl {
|
|
|
1481
1482
|
}
|
|
1482
1483
|
});
|
|
1483
1484
|
if (this.customLayerRegistry) {
|
|
1484
|
-
this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
|
|
1485
|
+
this.customLayerUnsubscribe = this.customLayerRegistry.onChange((event, layerId) => {
|
|
1486
|
+
if (event === "add" && layerId) {
|
|
1487
|
+
this.removedCustomLayerIds.delete(layerId);
|
|
1488
|
+
}
|
|
1485
1489
|
setTimeout(() => this.checkForNewLayers(), 100);
|
|
1486
1490
|
});
|
|
1487
1491
|
}
|
|
@@ -2145,6 +2149,17 @@ class LayerControl {
|
|
|
2145
2149
|
content.appendChild(infoText);
|
|
2146
2150
|
const actions = document.createElement("div");
|
|
2147
2151
|
actions.className = "style-editor-actions";
|
|
2152
|
+
const removeBtn = document.createElement("button");
|
|
2153
|
+
removeBtn.className = "style-editor-button style-editor-button-remove";
|
|
2154
|
+
removeBtn.textContent = "Remove";
|
|
2155
|
+
removeBtn.title = "Remove layer from map";
|
|
2156
|
+
removeBtn.addEventListener("click", (e) => {
|
|
2157
|
+
e.stopPropagation();
|
|
2158
|
+
if (confirm("Are you sure you want to remove this layer?")) {
|
|
2159
|
+
this.closeStyleEditor(layerId);
|
|
2160
|
+
this.removeLayer(layerId);
|
|
2161
|
+
}
|
|
2162
|
+
});
|
|
2148
2163
|
const closeActionBtn = document.createElement("button");
|
|
2149
2164
|
closeActionBtn.className = "style-editor-button style-editor-button-close";
|
|
2150
2165
|
closeActionBtn.textContent = "Close";
|
|
@@ -2152,6 +2167,7 @@ class LayerControl {
|
|
|
2152
2167
|
e.stopPropagation();
|
|
2153
2168
|
this.closeStyleEditor(layerId);
|
|
2154
2169
|
});
|
|
2170
|
+
actions.appendChild(removeBtn);
|
|
2155
2171
|
actions.appendChild(closeActionBtn);
|
|
2156
2172
|
editor.appendChild(header);
|
|
2157
2173
|
editor.appendChild(content);
|
|
@@ -2207,6 +2223,17 @@ class LayerControl {
|
|
|
2207
2223
|
e.stopPropagation();
|
|
2208
2224
|
this.resetLayerStyle(layerId);
|
|
2209
2225
|
});
|
|
2226
|
+
const removeBtn = document.createElement("button");
|
|
2227
|
+
removeBtn.className = "style-editor-button style-editor-button-remove";
|
|
2228
|
+
removeBtn.textContent = "Remove";
|
|
2229
|
+
removeBtn.title = "Remove layer from map";
|
|
2230
|
+
removeBtn.addEventListener("click", (e) => {
|
|
2231
|
+
e.stopPropagation();
|
|
2232
|
+
if (confirm("Are you sure you want to remove this layer?")) {
|
|
2233
|
+
this.closeStyleEditor(layerId);
|
|
2234
|
+
this.removeLayer(layerId);
|
|
2235
|
+
}
|
|
2236
|
+
});
|
|
2210
2237
|
const closeActionBtn = document.createElement("button");
|
|
2211
2238
|
closeActionBtn.className = "style-editor-button style-editor-button-close";
|
|
2212
2239
|
closeActionBtn.textContent = "Close";
|
|
@@ -2215,6 +2242,7 @@ class LayerControl {
|
|
|
2215
2242
|
this.closeStyleEditor(layerId);
|
|
2216
2243
|
});
|
|
2217
2244
|
actions.appendChild(resetBtn);
|
|
2245
|
+
actions.appendChild(removeBtn);
|
|
2218
2246
|
actions.appendChild(closeActionBtn);
|
|
2219
2247
|
editor.appendChild(header);
|
|
2220
2248
|
editor.appendChild(controls);
|
|
@@ -2615,7 +2643,7 @@ class LayerControl {
|
|
|
2615
2643
|
if (this.customLayerRegistry) {
|
|
2616
2644
|
const customLayerIds = this.customLayerRegistry.getAllLayerIds();
|
|
2617
2645
|
customLayerIds.forEach((layerId) => {
|
|
2618
|
-
if (!this.state.layerStates[layerId]) {
|
|
2646
|
+
if (!this.state.layerStates[layerId] && !this.removedCustomLayerIds.has(layerId)) {
|
|
2619
2647
|
const customState = this.customLayerRegistry.getLayerState(layerId);
|
|
2620
2648
|
if (customState) {
|
|
2621
2649
|
this.state.layerStates[layerId] = {
|
|
@@ -2656,7 +2684,10 @@ class LayerControl {
|
|
|
2656
2684
|
registerCustomAdapter(adapter) {
|
|
2657
2685
|
if (!this.customLayerRegistry) {
|
|
2658
2686
|
this.customLayerRegistry = new CustomLayerRegistry();
|
|
2659
|
-
this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
|
|
2687
|
+
this.customLayerUnsubscribe = this.customLayerRegistry.onChange((event, layerId) => {
|
|
2688
|
+
if (event === "add" && layerId) {
|
|
2689
|
+
this.removedCustomLayerIds.delete(layerId);
|
|
2690
|
+
}
|
|
2660
2691
|
this.checkForNewLayers();
|
|
2661
2692
|
});
|
|
2662
2693
|
}
|
|
@@ -3071,27 +3102,28 @@ class LayerControl {
|
|
|
3071
3102
|
var _a, _b;
|
|
3072
3103
|
const layerState = this.state.layerStates[layerId];
|
|
3073
3104
|
if ((layerState == null ? void 0 : layerState.isCustomLayer) && this.customLayerRegistry) {
|
|
3105
|
+
this.removedCustomLayerIds.add(layerId);
|
|
3106
|
+
this.customLayerRegistry.setVisibility(layerId, false);
|
|
3074
3107
|
this.customLayerRegistry.removeLayer(layerId);
|
|
3075
|
-
}
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
}
|
|
3108
|
+
}
|
|
3109
|
+
try {
|
|
3110
|
+
const layer = this.map.getLayer(layerId);
|
|
3111
|
+
if (layer) {
|
|
3112
|
+
const sourceId = layer.source;
|
|
3113
|
+
this.map.removeLayer(layerId);
|
|
3114
|
+
if (sourceId) {
|
|
3115
|
+
const style = this.map.getStyle();
|
|
3116
|
+
const sourceStillUsed = (_a = style == null ? void 0 : style.layers) == null ? void 0 : _a.some((l) => l.source === sourceId);
|
|
3117
|
+
if (!sourceStillUsed) {
|
|
3118
|
+
try {
|
|
3119
|
+
this.map.removeSource(sourceId);
|
|
3120
|
+
} catch (e) {
|
|
3089
3121
|
}
|
|
3090
3122
|
}
|
|
3091
3123
|
}
|
|
3092
|
-
} catch (error) {
|
|
3093
|
-
console.warn(`Failed to remove layer ${layerId}:`, error);
|
|
3094
3124
|
}
|
|
3125
|
+
} catch (error) {
|
|
3126
|
+
console.warn(`Failed to remove layer ${layerId}:`, error);
|
|
3095
3127
|
}
|
|
3096
3128
|
delete this.state.layerStates[layerId];
|
|
3097
3129
|
this.state.customLayerNames.delete(layerId);
|