maplibre-gl-layer-control 0.17.0 → 0.17.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 +2 -0
- package/dist/index.cjs +31 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +31 -12
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +14 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -722,6 +722,8 @@ class LayerControl {
|
|
|
722
722
|
__publicField(this, "onLayerRename");
|
|
723
723
|
__publicField(this, "onLayerReorder");
|
|
724
724
|
__publicField(this, "onLayerRemove");
|
|
725
|
+
__publicField(this, "onBackgroundVisibilityChange");
|
|
726
|
+
__publicField(this, "onBackgroundOpacityChange");
|
|
725
727
|
// Background-layer visibility presets
|
|
726
728
|
__publicField(this, "enableBackgroundPresets");
|
|
727
729
|
__publicField(this, "backgroundPresetStorageKey");
|
|
@@ -742,6 +744,8 @@ class LayerControl {
|
|
|
742
744
|
this.onLayerRename = options.onLayerRename;
|
|
743
745
|
this.onLayerReorder = options.onLayerReorder;
|
|
744
746
|
this.onLayerRemove = options.onLayerRemove;
|
|
747
|
+
this.onBackgroundVisibilityChange = options.onBackgroundVisibilityChange;
|
|
748
|
+
this.onBackgroundOpacityChange = options.onBackgroundOpacityChange;
|
|
745
749
|
this.enableBackgroundPresets = options.enableBackgroundPresets !== false;
|
|
746
750
|
this.backgroundPresetStorageKey = options.backgroundPresetStorageKey || "maplibre-layer-control:background-presets";
|
|
747
751
|
this.onBackgroundPresetsChange = options.onBackgroundPresetsChange;
|
|
@@ -1904,6 +1908,7 @@ class LayerControl {
|
|
|
1904
1908
|
* Toggle visibility for all background layers (basemap layers)
|
|
1905
1909
|
*/
|
|
1906
1910
|
toggleBackgroundVisibility(visible) {
|
|
1911
|
+
var _a;
|
|
1907
1912
|
if (this.state.layerStates["Background"]) {
|
|
1908
1913
|
this.state.layerStates["Background"].visible = visible;
|
|
1909
1914
|
}
|
|
@@ -1931,11 +1936,13 @@ class LayerControl {
|
|
|
1931
1936
|
});
|
|
1932
1937
|
}
|
|
1933
1938
|
}
|
|
1939
|
+
(_a = this.onBackgroundVisibilityChange) == null ? void 0 : _a.call(this, visible);
|
|
1934
1940
|
}
|
|
1935
1941
|
/**
|
|
1936
1942
|
* Change opacity for all background layers (basemap layers)
|
|
1937
1943
|
*/
|
|
1938
1944
|
changeBackgroundOpacity(opacity) {
|
|
1945
|
+
var _a;
|
|
1939
1946
|
if (this.state.layerStates["Background"]) {
|
|
1940
1947
|
this.state.layerStates["Background"].opacity = opacity;
|
|
1941
1948
|
}
|
|
@@ -1948,6 +1955,7 @@ class LayerControl {
|
|
|
1948
1955
|
}
|
|
1949
1956
|
}
|
|
1950
1957
|
});
|
|
1958
|
+
(_a = this.onBackgroundOpacityChange) == null ? void 0 : _a.call(this, opacity);
|
|
1951
1959
|
}
|
|
1952
1960
|
// ===== Background Legend Methods =====
|
|
1953
1961
|
/**
|
|
@@ -3741,22 +3749,33 @@ class LayerControl {
|
|
|
3741
3749
|
const style = this.map.getStyle();
|
|
3742
3750
|
if (!(style == null ? void 0 : style.layers)) return [];
|
|
3743
3751
|
const mapLayerIds = style.layers.map((l) => l.id);
|
|
3752
|
+
const indexById = new Map(mapLayerIds.map((id, i) => [id, i]));
|
|
3744
3753
|
const userLayerIds = Object.keys(this.state.layerStates).filter(
|
|
3745
3754
|
(id) => id !== "Background"
|
|
3746
3755
|
);
|
|
3747
|
-
const
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
(
|
|
3752
|
-
|
|
3753
|
-
|
|
3756
|
+
const mapIndexOf = (id) => {
|
|
3757
|
+
var _a;
|
|
3758
|
+
const direct = indexById.get(id);
|
|
3759
|
+
if (direct !== void 0) return direct;
|
|
3760
|
+
const nativeIds = (_a = this.customLayerRegistry) == null ? void 0 : _a.getNativeLayerIds(id);
|
|
3761
|
+
if (nativeIds && nativeIds.length > 0) {
|
|
3762
|
+
let best = -1;
|
|
3763
|
+
for (const nativeId of nativeIds) {
|
|
3764
|
+
const idx = indexById.get(nativeId);
|
|
3765
|
+
if (idx !== void 0 && idx > best) best = idx;
|
|
3766
|
+
}
|
|
3767
|
+
if (best !== -1) return best;
|
|
3754
3768
|
}
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3769
|
+
return Number.POSITIVE_INFINITY;
|
|
3770
|
+
};
|
|
3771
|
+
return userLayerIds.map((id, insertionIndex) => ({
|
|
3772
|
+
id,
|
|
3773
|
+
insertionIndex,
|
|
3774
|
+
mapIndex: mapIndexOf(id)
|
|
3775
|
+
})).sort((a, b) => {
|
|
3776
|
+
if (a.mapIndex !== b.mapIndex) return a.mapIndex > b.mapIndex ? -1 : 1;
|
|
3777
|
+
return a.insertionIndex - b.insertionIndex;
|
|
3778
|
+
}).map((entry) => entry.id);
|
|
3760
3779
|
}
|
|
3761
3780
|
/**
|
|
3762
3781
|
* Check if a layer is a MapLibre layer (not a custom layer)
|