maplibre-gl-layer-control 0.14.0 → 0.14.1
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 +23 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +23 -6
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +21 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -686,6 +686,7 @@ class LayerControl {
|
|
|
686
686
|
__publicField(this, "styleEditors");
|
|
687
687
|
__publicField(this, "initialSourceIds", null);
|
|
688
688
|
__publicField(this, "initialLayerIds", null);
|
|
689
|
+
__publicField(this, "initialLayerStates");
|
|
689
690
|
// Panel width management
|
|
690
691
|
__publicField(this, "minPanelWidth");
|
|
691
692
|
__publicField(this, "maxPanelWidth");
|
|
@@ -729,11 +730,12 @@ class LayerControl {
|
|
|
729
730
|
this.onLayerRename = options.onLayerRename;
|
|
730
731
|
this.onLayerReorder = options.onLayerReorder;
|
|
731
732
|
this.onLayerRemove = options.onLayerRemove;
|
|
733
|
+
this.initialLayerStates = options.layerStates || {};
|
|
732
734
|
this.state = {
|
|
733
735
|
collapsed: options.collapsed !== false,
|
|
734
736
|
panelWidth: options.panelWidth || 350,
|
|
735
737
|
activeStyleEditor: null,
|
|
736
|
-
layerStates:
|
|
738
|
+
layerStates: {},
|
|
737
739
|
originalStyles: /* @__PURE__ */ new Map(),
|
|
738
740
|
userInteractingWithSlider: false,
|
|
739
741
|
backgroundLegendOpen: false,
|
|
@@ -757,7 +759,7 @@ class LayerControl {
|
|
|
757
759
|
},
|
|
758
760
|
isStyleOperationInProgress: false
|
|
759
761
|
};
|
|
760
|
-
this.targetLayers = options.layers || Object.keys(this.
|
|
762
|
+
this.targetLayers = options.layers || Object.keys(this.initialLayerStates);
|
|
761
763
|
this.styleEditors = /* @__PURE__ */ new Map();
|
|
762
764
|
if (options.customLayerAdapters && options.customLayerAdapters.length > 0) {
|
|
763
765
|
this.customLayerRegistry = new CustomLayerRegistry();
|
|
@@ -929,11 +931,11 @@ class LayerControl {
|
|
|
929
931
|
const layerType = layer.type;
|
|
930
932
|
const opacity = getLayerOpacity(this.map, layerId, layerType);
|
|
931
933
|
const friendlyName = this.generateFriendlyName(layerId);
|
|
932
|
-
this.state.layerStates[layerId] = {
|
|
934
|
+
this.state.layerStates[layerId] = this.mergeWithUserState(layerId, {
|
|
933
935
|
visible: isVisible,
|
|
934
936
|
opacity,
|
|
935
937
|
name: friendlyName
|
|
936
|
-
};
|
|
938
|
+
});
|
|
937
939
|
});
|
|
938
940
|
} else {
|
|
939
941
|
const userLayers = [];
|
|
@@ -964,11 +966,11 @@ class LayerControl {
|
|
|
964
966
|
const layerType = layer.type;
|
|
965
967
|
const opacity = getLayerOpacity(this.map, layerId, layerType);
|
|
966
968
|
const friendlyName = this.generateFriendlyName(layerId);
|
|
967
|
-
this.state.layerStates[layerId] = {
|
|
969
|
+
this.state.layerStates[layerId] = this.mergeWithUserState(layerId, {
|
|
968
970
|
visible: isVisible,
|
|
969
971
|
opacity,
|
|
970
972
|
name: friendlyName
|
|
971
|
-
};
|
|
973
|
+
});
|
|
972
974
|
});
|
|
973
975
|
}
|
|
974
976
|
if (this.customLayerRegistry) {
|
|
@@ -1089,6 +1091,21 @@ class LayerControl {
|
|
|
1089
1091
|
name = name.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
1090
1092
|
return name || layerId;
|
|
1091
1093
|
}
|
|
1094
|
+
/**
|
|
1095
|
+
* Merge auto-detected layer state with user-provided initial state.
|
|
1096
|
+
* User-provided values take precedence over detected values.
|
|
1097
|
+
*/
|
|
1098
|
+
mergeWithUserState(layerId, detected) {
|
|
1099
|
+
const userState = this.initialLayerStates[layerId];
|
|
1100
|
+
if (!userState) return detected;
|
|
1101
|
+
return {
|
|
1102
|
+
visible: userState.visible ?? detected.visible,
|
|
1103
|
+
opacity: userState.opacity ?? detected.opacity,
|
|
1104
|
+
name: userState.name ?? detected.name,
|
|
1105
|
+
...userState.isCustomLayer !== void 0 && { isCustomLayer: userState.isCustomLayer },
|
|
1106
|
+
...userState.customLayerType !== void 0 && { customLayerType: userState.customLayerType }
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1092
1109
|
/**
|
|
1093
1110
|
* Check if a layer ID belongs to a drawing library (Geoman, Mapbox GL Draw, etc.)
|
|
1094
1111
|
* @param layerId The layer ID to check
|