maplibre-gl-layer-control 0.17.4 → 0.17.5
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 +44 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +44 -5
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -43,6 +43,13 @@ class CustomLayerRegistry {
|
|
|
43
43
|
});
|
|
44
44
|
return ids;
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Get each adapter's layer IDs as a separate list, in adapter order.
|
|
48
|
+
* @returns One array of layer IDs per registered adapter
|
|
49
|
+
*/
|
|
50
|
+
getLayerIdGroups() {
|
|
51
|
+
return Array.from(this.adapters.values(), (adapter) => adapter.getLayerIds());
|
|
52
|
+
}
|
|
46
53
|
/**
|
|
47
54
|
* Check if a layer ID is managed by any adapter.
|
|
48
55
|
* @param layerId The layer ID to check
|
|
@@ -3859,6 +3866,7 @@ class LayerControl {
|
|
|
3859
3866
|
* Includes both MapLibre layers and custom layers managed by adapters.
|
|
3860
3867
|
*/
|
|
3861
3868
|
getUserLayerIdsInMapOrder() {
|
|
3869
|
+
var _a;
|
|
3862
3870
|
const style = this.map.getStyle();
|
|
3863
3871
|
if (!(style == null ? void 0 : style.layers)) return [];
|
|
3864
3872
|
const mapLayerIds = style.layers.map((l) => l.id);
|
|
@@ -3866,11 +3874,11 @@ class LayerControl {
|
|
|
3866
3874
|
const userLayerIds = Object.keys(this.state.layerStates).filter(
|
|
3867
3875
|
(id) => id !== "Background"
|
|
3868
3876
|
);
|
|
3869
|
-
const
|
|
3870
|
-
var
|
|
3877
|
+
const resolvedIndexOf = (id) => {
|
|
3878
|
+
var _a2;
|
|
3871
3879
|
const direct = indexById.get(id);
|
|
3872
3880
|
if (direct !== void 0) return direct;
|
|
3873
|
-
const nativeIds = (
|
|
3881
|
+
const nativeIds = (_a2 = this.customLayerRegistry) == null ? void 0 : _a2.getNativeLayerIds(id);
|
|
3874
3882
|
if (nativeIds && nativeIds.length > 0) {
|
|
3875
3883
|
let best = -1;
|
|
3876
3884
|
for (const nativeId of nativeIds) {
|
|
@@ -3879,14 +3887,45 @@ class LayerControl {
|
|
|
3879
3887
|
}
|
|
3880
3888
|
if (best !== -1) return best;
|
|
3881
3889
|
}
|
|
3882
|
-
return
|
|
3890
|
+
return void 0;
|
|
3891
|
+
};
|
|
3892
|
+
const anchors = /* @__PURE__ */ new Map();
|
|
3893
|
+
for (const group of ((_a = this.customLayerRegistry) == null ? void 0 : _a.getLayerIdGroups()) ?? []) {
|
|
3894
|
+
const resolved = group.map(resolvedIndexOf);
|
|
3895
|
+
const known = resolved.filter((idx) => idx !== void 0);
|
|
3896
|
+
if (known.length === 0) continue;
|
|
3897
|
+
const ids = known[0] > known[known.length - 1] ? [...group].reverse() : group;
|
|
3898
|
+
const indexes = ids === group ? resolved : [...resolved].reverse();
|
|
3899
|
+
ids.forEach((id, position) => {
|
|
3900
|
+
if (indexes[position] !== void 0) return;
|
|
3901
|
+
for (let below = position - 1; below >= 0; below--) {
|
|
3902
|
+
const idx = indexes[below];
|
|
3903
|
+
if (idx !== void 0) {
|
|
3904
|
+
anchors.set(id, { mapIndex: idx, offset: position - below });
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
}
|
|
3908
|
+
for (let above = position + 1; above < ids.length; above++) {
|
|
3909
|
+
const idx = indexes[above];
|
|
3910
|
+
if (idx !== void 0) {
|
|
3911
|
+
anchors.set(id, { mapIndex: idx, offset: position - above });
|
|
3912
|
+
return;
|
|
3913
|
+
}
|
|
3914
|
+
}
|
|
3915
|
+
});
|
|
3916
|
+
}
|
|
3917
|
+
const stackKeyOf = (id) => {
|
|
3918
|
+
const resolved = resolvedIndexOf(id);
|
|
3919
|
+
if (resolved !== void 0) return { mapIndex: resolved, offset: 0 };
|
|
3920
|
+
return anchors.get(id) ?? { mapIndex: Number.POSITIVE_INFINITY, offset: 0 };
|
|
3883
3921
|
};
|
|
3884
3922
|
return userLayerIds.map((id, insertionIndex) => ({
|
|
3885
3923
|
id,
|
|
3886
3924
|
insertionIndex,
|
|
3887
|
-
|
|
3925
|
+
...stackKeyOf(id)
|
|
3888
3926
|
})).sort((a, b) => {
|
|
3889
3927
|
if (a.mapIndex !== b.mapIndex) return a.mapIndex > b.mapIndex ? -1 : 1;
|
|
3928
|
+
if (a.offset !== b.offset) return b.offset - a.offset;
|
|
3890
3929
|
return a.insertionIndex - b.insertionIndex;
|
|
3891
3930
|
}).map((entry) => entry.id);
|
|
3892
3931
|
}
|