maplibre-gl-layer-control 0.17.1 → 0.17.3
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 +21 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +21 -3
- package/dist/index.mjs.map +1 -1
- package/dist/types/index.d.ts +14 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -179,6 +179,8 @@ function MapComponent() {
|
|
|
179
179
|
| `enableBackgroundPresets` | `boolean` | `true` | Show the "Saved configurations" controls in the Background Layers panel |
|
|
180
180
|
| `backgroundPresetStorageKey` | `string` | `'maplibre-layer-control:background-presets'` | `localStorage` key under which background visibility presets are stored |
|
|
181
181
|
| `onBackgroundPresetsChange` | `(presets: BackgroundPresets) => void` | `undefined` | Called whenever the saved preset set changes (created or deleted); applying a preset does not change the set, so it does not fire |
|
|
182
|
+
| `onBackgroundVisibilityChange` | `(visible: boolean) => void` | `undefined` | Called when the Background (basemap) group is toggled via the checkbox; mirror it into your own store to keep external basemap UI in sync |
|
|
183
|
+
| `onBackgroundOpacityChange` | `(opacity: number) => void` | `undefined` | Called when the Background (basemap) group opacity slider changes; mirror it into your own store to keep external basemap UI in sync |
|
|
182
184
|
|
|
183
185
|
### LayerState
|
|
184
186
|
|
package/dist/index.cjs
CHANGED
|
@@ -724,6 +724,8 @@ class LayerControl {
|
|
|
724
724
|
__publicField(this, "onLayerRename");
|
|
725
725
|
__publicField(this, "onLayerReorder");
|
|
726
726
|
__publicField(this, "onLayerRemove");
|
|
727
|
+
__publicField(this, "onBackgroundVisibilityChange");
|
|
728
|
+
__publicField(this, "onBackgroundOpacityChange");
|
|
727
729
|
// Background-layer visibility presets
|
|
728
730
|
__publicField(this, "enableBackgroundPresets");
|
|
729
731
|
__publicField(this, "backgroundPresetStorageKey");
|
|
@@ -744,6 +746,8 @@ class LayerControl {
|
|
|
744
746
|
this.onLayerRename = options.onLayerRename;
|
|
745
747
|
this.onLayerReorder = options.onLayerReorder;
|
|
746
748
|
this.onLayerRemove = options.onLayerRemove;
|
|
749
|
+
this.onBackgroundVisibilityChange = options.onBackgroundVisibilityChange;
|
|
750
|
+
this.onBackgroundOpacityChange = options.onBackgroundOpacityChange;
|
|
747
751
|
this.enableBackgroundPresets = options.enableBackgroundPresets !== false;
|
|
748
752
|
this.backgroundPresetStorageKey = options.backgroundPresetStorageKey || "maplibre-layer-control:background-presets";
|
|
749
753
|
this.onBackgroundPresetsChange = options.onBackgroundPresetsChange;
|
|
@@ -1586,7 +1590,7 @@ class LayerControl {
|
|
|
1586
1590
|
if (!state) {
|
|
1587
1591
|
return;
|
|
1588
1592
|
}
|
|
1589
|
-
if (this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
|
|
1593
|
+
if (layerId === "Background" || this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
|
|
1590
1594
|
this.addLayerItem(layerId, state);
|
|
1591
1595
|
}
|
|
1592
1596
|
});
|
|
@@ -1906,6 +1910,7 @@ class LayerControl {
|
|
|
1906
1910
|
* Toggle visibility for all background layers (basemap layers)
|
|
1907
1911
|
*/
|
|
1908
1912
|
toggleBackgroundVisibility(visible) {
|
|
1913
|
+
var _a;
|
|
1909
1914
|
if (this.state.layerStates["Background"]) {
|
|
1910
1915
|
this.state.layerStates["Background"].visible = visible;
|
|
1911
1916
|
}
|
|
@@ -1933,11 +1938,13 @@ class LayerControl {
|
|
|
1933
1938
|
});
|
|
1934
1939
|
}
|
|
1935
1940
|
}
|
|
1941
|
+
(_a = this.onBackgroundVisibilityChange) == null ? void 0 : _a.call(this, visible);
|
|
1936
1942
|
}
|
|
1937
1943
|
/**
|
|
1938
1944
|
* Change opacity for all background layers (basemap layers)
|
|
1939
1945
|
*/
|
|
1940
1946
|
changeBackgroundOpacity(opacity) {
|
|
1947
|
+
var _a;
|
|
1941
1948
|
if (this.state.layerStates["Background"]) {
|
|
1942
1949
|
this.state.layerStates["Background"].opacity = opacity;
|
|
1943
1950
|
}
|
|
@@ -1950,6 +1957,7 @@ class LayerControl {
|
|
|
1950
1957
|
}
|
|
1951
1958
|
}
|
|
1952
1959
|
});
|
|
1960
|
+
(_a = this.onBackgroundOpacityChange) == null ? void 0 : _a.call(this, opacity);
|
|
1953
1961
|
}
|
|
1954
1962
|
// ===== Background Legend Methods =====
|
|
1955
1963
|
/**
|
|
@@ -3345,6 +3353,7 @@ class LayerControl {
|
|
|
3345
3353
|
const isAutoDetectMode = this.targetLayers.length === 0 || this.targetLayers.length === 1 && this.targetLayers[0] === "Background" || this.targetLayers.every(
|
|
3346
3354
|
(id) => id === "Background" || this.state.layerStates[id]
|
|
3347
3355
|
);
|
|
3356
|
+
let layersAdded = false;
|
|
3348
3357
|
const newLayers = [];
|
|
3349
3358
|
const useBasemapStyleDetection = this.basemapLayerIds !== null && this.basemapLayerIds.size > 0;
|
|
3350
3359
|
const useInitialLayerDetection = !useBasemapStyleDetection && this.initialLayerIds !== null && this.initialLayerIds.size > 0;
|
|
@@ -3424,7 +3433,10 @@ class LayerControl {
|
|
|
3424
3433
|
opacity,
|
|
3425
3434
|
name: this.generateFriendlyName(layerId)
|
|
3426
3435
|
};
|
|
3427
|
-
this.
|
|
3436
|
+
if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
|
|
3437
|
+
this.targetLayers.push(layerId);
|
|
3438
|
+
}
|
|
3439
|
+
layersAdded = true;
|
|
3428
3440
|
});
|
|
3429
3441
|
}
|
|
3430
3442
|
if (this.customLayerRegistry) {
|
|
@@ -3440,7 +3452,10 @@ class LayerControl {
|
|
|
3440
3452
|
isCustomLayer: true,
|
|
3441
3453
|
customLayerType: this.customLayerRegistry.getSymbolType(layerId) || void 0
|
|
3442
3454
|
};
|
|
3443
|
-
this.
|
|
3455
|
+
if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
|
|
3456
|
+
this.targetLayers.push(layerId);
|
|
3457
|
+
}
|
|
3458
|
+
layersAdded = true;
|
|
3444
3459
|
}
|
|
3445
3460
|
}
|
|
3446
3461
|
});
|
|
@@ -3461,6 +3476,9 @@ class LayerControl {
|
|
|
3461
3476
|
}
|
|
3462
3477
|
});
|
|
3463
3478
|
}
|
|
3479
|
+
if (layersAdded) {
|
|
3480
|
+
this.buildLayerItems();
|
|
3481
|
+
}
|
|
3464
3482
|
} catch (error) {
|
|
3465
3483
|
console.warn("Failed to check for new layers:", error);
|
|
3466
3484
|
}
|