maplibre-gl-layer-control 0.7.1 → 0.7.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/dist/index.cjs +33 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +33 -4
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +12 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -642,6 +642,7 @@ class LayerControl {
|
|
|
642
642
|
__publicField(this, "state");
|
|
643
643
|
__publicField(this, "targetLayers");
|
|
644
644
|
__publicField(this, "styleEditors");
|
|
645
|
+
__publicField(this, "initialSourceIds", null);
|
|
645
646
|
// Panel width management
|
|
646
647
|
__publicField(this, "minPanelWidth");
|
|
647
648
|
__publicField(this, "maxPanelWidth");
|
|
@@ -669,7 +670,7 @@ class LayerControl {
|
|
|
669
670
|
this.excludeDrawnLayers = options.excludeDrawnLayers !== false;
|
|
670
671
|
this.state = {
|
|
671
672
|
collapsed: options.collapsed !== false,
|
|
672
|
-
panelWidth: options.panelWidth ||
|
|
673
|
+
panelWidth: options.panelWidth || 360,
|
|
673
674
|
activeStyleEditor: null,
|
|
674
675
|
layerStates: options.layerStates || {},
|
|
675
676
|
originalStyles: /* @__PURE__ */ new Map(),
|
|
@@ -693,6 +694,12 @@ class LayerControl {
|
|
|
693
694
|
onAdd(map) {
|
|
694
695
|
this.map = map;
|
|
695
696
|
this.mapContainer = map.getContainer();
|
|
697
|
+
const style = this.map.getStyle();
|
|
698
|
+
if (style && style.sources) {
|
|
699
|
+
this.initialSourceIds = new Set(Object.keys(style.sources));
|
|
700
|
+
} else {
|
|
701
|
+
this.initialSourceIds = /* @__PURE__ */ new Set();
|
|
702
|
+
}
|
|
696
703
|
if (Object.keys(this.state.layerStates).length === 0) {
|
|
697
704
|
this.autoDetectLayers();
|
|
698
705
|
}
|
|
@@ -836,9 +843,11 @@ class LayerControl {
|
|
|
836
843
|
/**
|
|
837
844
|
* Detect which sources are user-added (not from the basemap style)
|
|
838
845
|
* User-added sources are identified by:
|
|
839
|
-
* -
|
|
840
|
-
* -
|
|
841
|
-
*
|
|
846
|
+
* - Sources that were NOT present when the control was first added
|
|
847
|
+
* - Additionally for sources added later:
|
|
848
|
+
* - GeoJSON sources with inline data objects (not URL strings)
|
|
849
|
+
* - Image, video, canvas sources
|
|
850
|
+
* - Raster, raster-dem, vector sources from non-basemap tile providers
|
|
842
851
|
*/
|
|
843
852
|
detectUserAddedSources() {
|
|
844
853
|
const userAddedSources = /* @__PURE__ */ new Set();
|
|
@@ -876,6 +885,9 @@ class LayerControl {
|
|
|
876
885
|
}
|
|
877
886
|
}
|
|
878
887
|
for (const [sourceId, source] of Object.entries(style.sources)) {
|
|
888
|
+
if (this.initialSourceIds && this.initialSourceIds.has(sourceId)) {
|
|
889
|
+
continue;
|
|
890
|
+
}
|
|
879
891
|
const src = source;
|
|
880
892
|
const sourceType = src.type;
|
|
881
893
|
if (sourceType === "image" || sourceType === "video" || sourceType === "canvas") {
|
|
@@ -2402,6 +2414,23 @@ class LayerControl {
|
|
|
2402
2414
|
console.warn("Failed to check for new layers:", error);
|
|
2403
2415
|
}
|
|
2404
2416
|
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Register a custom layer adapter dynamically.
|
|
2419
|
+
* This allows adding adapters after the LayerControl has been initialized.
|
|
2420
|
+
* @param adapter The custom layer adapter to register
|
|
2421
|
+
*/
|
|
2422
|
+
registerCustomAdapter(adapter) {
|
|
2423
|
+
if (!this.customLayerRegistry) {
|
|
2424
|
+
this.customLayerRegistry = new CustomLayerRegistry();
|
|
2425
|
+
this.customLayerUnsubscribe = this.customLayerRegistry.onChange(() => {
|
|
2426
|
+
this.checkForNewLayers();
|
|
2427
|
+
});
|
|
2428
|
+
}
|
|
2429
|
+
this.customLayerRegistry.register(adapter);
|
|
2430
|
+
if (this.panel) {
|
|
2431
|
+
this.checkForNewLayers();
|
|
2432
|
+
}
|
|
2433
|
+
}
|
|
2405
2434
|
}
|
|
2406
2435
|
exports.CustomLayerRegistry = CustomLayerRegistry;
|
|
2407
2436
|
exports.LayerControl = LayerControl;
|