maplibre-gl-layer-control 0.8.0 → 0.8.2
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/README.md +1 -0
- package/dist/index.cjs +40 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +40 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -170,6 +170,7 @@ function MapComponent() {
|
|
|
170
170
|
| `showOpacitySlider` | `boolean` | `true` | Show opacity slider for layers |
|
|
171
171
|
| `showLayerSymbol` | `boolean` | `true` | Show layer type symbols (colored icons) next to layer names |
|
|
172
172
|
| `excludeDrawnLayers` | `boolean` | `true` | Exclude layers from drawing libraries (Geoman, Mapbox GL Draw, etc.) |
|
|
173
|
+
| `excludeLayers` | `string[]` | `undefined` | Array of wildcard patterns to exclude layers by name (e.g., `['*-temp-*', 'debug-*']`) |
|
|
173
174
|
| `customLayerAdapters` | `CustomLayerAdapter[]` | `undefined` | Adapters for non-MapLibre layers (deck.gl, Zarr, etc.) |
|
|
174
175
|
| `basemapStyleUrl` | `string` | `undefined` | URL of basemap style JSON for reliable layer detection (see below) |
|
|
175
176
|
|
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ class CustomLayerRegistry {
|
|
|
7
7
|
constructor() {
|
|
8
8
|
__publicField(this, "adapters", /* @__PURE__ */ new Map());
|
|
9
9
|
__publicField(this, "changeListeners", []);
|
|
10
|
-
__publicField(this, "unsubscribers",
|
|
10
|
+
__publicField(this, "unsubscribers", /* @__PURE__ */ new Map());
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Register a custom layer adapter.
|
|
@@ -19,7 +19,7 @@ class CustomLayerRegistry {
|
|
|
19
19
|
const unsubscribe = adapter.onLayerChange((event, layerId) => {
|
|
20
20
|
this.notifyChange(event, layerId);
|
|
21
21
|
});
|
|
22
|
-
this.unsubscribers.
|
|
22
|
+
this.unsubscribers.set(adapter.type, unsubscribe);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
@@ -27,6 +27,11 @@ class CustomLayerRegistry {
|
|
|
27
27
|
* @param type The adapter type to unregister
|
|
28
28
|
*/
|
|
29
29
|
unregister(type) {
|
|
30
|
+
const unsubscribe = this.unsubscribers.get(type);
|
|
31
|
+
if (unsubscribe) {
|
|
32
|
+
unsubscribe();
|
|
33
|
+
this.unsubscribers.delete(type);
|
|
34
|
+
}
|
|
30
35
|
this.adapters.delete(type);
|
|
31
36
|
}
|
|
32
37
|
/**
|
|
@@ -137,7 +142,7 @@ class CustomLayerRegistry {
|
|
|
137
142
|
*/
|
|
138
143
|
destroy() {
|
|
139
144
|
this.unsubscribers.forEach((unsub) => unsub());
|
|
140
|
-
this.unsubscribers
|
|
145
|
+
this.unsubscribers.clear();
|
|
141
146
|
this.adapters.clear();
|
|
142
147
|
this.changeListeners = [];
|
|
143
148
|
}
|
|
@@ -652,6 +657,7 @@ class LayerControl {
|
|
|
652
657
|
__publicField(this, "showOpacitySlider");
|
|
653
658
|
__publicField(this, "showLayerSymbol");
|
|
654
659
|
__publicField(this, "excludeDrawnLayers");
|
|
660
|
+
__publicField(this, "excludeLayerPatterns");
|
|
655
661
|
__publicField(this, "customLayerRegistry", null);
|
|
656
662
|
__publicField(this, "customLayerUnsubscribe", null);
|
|
657
663
|
__publicField(this, "basemapStyleUrl", null);
|
|
@@ -671,6 +677,7 @@ class LayerControl {
|
|
|
671
677
|
this.showOpacitySlider = options.showOpacitySlider !== false;
|
|
672
678
|
this.showLayerSymbol = options.showLayerSymbol !== false;
|
|
673
679
|
this.excludeDrawnLayers = options.excludeDrawnLayers !== false;
|
|
680
|
+
this.excludeLayerPatterns = this.wildcardPatternsToRegex(options.excludeLayers || []);
|
|
674
681
|
this.state = {
|
|
675
682
|
collapsed: options.collapsed !== false,
|
|
676
683
|
panelWidth: options.panelWidth || 360,
|
|
@@ -811,6 +818,10 @@ class LayerControl {
|
|
|
811
818
|
backgroundLayerIds.push(layerId);
|
|
812
819
|
return;
|
|
813
820
|
}
|
|
821
|
+
if (this.isExcludedByPattern(layerId)) {
|
|
822
|
+
backgroundLayerIds.push(layerId);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
814
825
|
if (useBasemapStyleDetection) {
|
|
815
826
|
if (this.basemapLayerIds.has(layerId)) {
|
|
816
827
|
backgroundLayerIds.push(layerId);
|
|
@@ -851,6 +862,10 @@ class LayerControl {
|
|
|
851
862
|
const userLayers = [];
|
|
852
863
|
const basemapLayers = [];
|
|
853
864
|
allLayerIds.forEach((layerId) => {
|
|
865
|
+
if (this.isExcludedByPattern(layerId)) {
|
|
866
|
+
basemapLayers.push(layerId);
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
854
869
|
if (this.targetLayers.includes(layerId)) {
|
|
855
870
|
userLayers.push(layerId);
|
|
856
871
|
} else {
|
|
@@ -1019,6 +1034,22 @@ class LayerControl {
|
|
|
1019
1034
|
];
|
|
1020
1035
|
return drawnLayerPatterns.some((pattern) => pattern.test(layerId));
|
|
1021
1036
|
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Convert wildcard patterns (e.g., '*-temp-*', 'debug-*') to RegExp objects
|
|
1039
|
+
*/
|
|
1040
|
+
wildcardPatternsToRegex(patterns) {
|
|
1041
|
+
return patterns.map((pattern) => {
|
|
1042
|
+
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&");
|
|
1043
|
+
const regexStr = escaped.replace(/\*/g, ".*");
|
|
1044
|
+
return new RegExp(`^${regexStr}$`, "i");
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Check if a layer matches any of the user-defined exclusion patterns
|
|
1049
|
+
*/
|
|
1050
|
+
isExcludedByPattern(layerId) {
|
|
1051
|
+
return this.excludeLayerPatterns.some((pattern) => pattern.test(layerId));
|
|
1052
|
+
}
|
|
1022
1053
|
/**
|
|
1023
1054
|
* Create the main container element
|
|
1024
1055
|
*/
|
|
@@ -1819,6 +1850,9 @@ class LayerControl {
|
|
|
1819
1850
|
if (this.excludeDrawnLayers && this.isDrawnLayer(layer.id)) {
|
|
1820
1851
|
return;
|
|
1821
1852
|
}
|
|
1853
|
+
if (this.isExcludedByPattern(layer.id)) {
|
|
1854
|
+
return;
|
|
1855
|
+
}
|
|
1822
1856
|
if (this.state.onlyRenderedFilter && !this.isLayerRendered(layer.id)) {
|
|
1823
1857
|
return;
|
|
1824
1858
|
}
|
|
@@ -2409,6 +2443,9 @@ class LayerControl {
|
|
|
2409
2443
|
if (this.excludeDrawnLayers && this.isDrawnLayer(layerId)) {
|
|
2410
2444
|
return;
|
|
2411
2445
|
}
|
|
2446
|
+
if (this.isExcludedByPattern(layerId)) {
|
|
2447
|
+
return;
|
|
2448
|
+
}
|
|
2412
2449
|
if (useBasemapStyleDetection) {
|
|
2413
2450
|
if (this.basemapLayerIds.has(layerId)) {
|
|
2414
2451
|
return;
|