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/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;
@@ -1584,7 +1588,7 @@ class LayerControl {
1584
1588
  if (!state) {
1585
1589
  return;
1586
1590
  }
1587
- if (this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1591
+ if (layerId === "Background" || this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1588
1592
  this.addLayerItem(layerId, state);
1589
1593
  }
1590
1594
  });
@@ -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
  /**
@@ -3343,6 +3351,7 @@ class LayerControl {
3343
3351
  const isAutoDetectMode = this.targetLayers.length === 0 || this.targetLayers.length === 1 && this.targetLayers[0] === "Background" || this.targetLayers.every(
3344
3352
  (id) => id === "Background" || this.state.layerStates[id]
3345
3353
  );
3354
+ let layersAdded = false;
3346
3355
  const newLayers = [];
3347
3356
  const useBasemapStyleDetection = this.basemapLayerIds !== null && this.basemapLayerIds.size > 0;
3348
3357
  const useInitialLayerDetection = !useBasemapStyleDetection && this.initialLayerIds !== null && this.initialLayerIds.size > 0;
@@ -3422,7 +3431,10 @@ class LayerControl {
3422
3431
  opacity,
3423
3432
  name: this.generateFriendlyName(layerId)
3424
3433
  };
3425
- this.addLayerItem(layerId, this.state.layerStates[layerId]);
3434
+ if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
3435
+ this.targetLayers.push(layerId);
3436
+ }
3437
+ layersAdded = true;
3426
3438
  });
3427
3439
  }
3428
3440
  if (this.customLayerRegistry) {
@@ -3438,7 +3450,10 @@ class LayerControl {
3438
3450
  isCustomLayer: true,
3439
3451
  customLayerType: this.customLayerRegistry.getSymbolType(layerId) || void 0
3440
3452
  };
3441
- this.addLayerItem(layerId, this.state.layerStates[layerId]);
3453
+ if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
3454
+ this.targetLayers.push(layerId);
3455
+ }
3456
+ layersAdded = true;
3442
3457
  }
3443
3458
  }
3444
3459
  });
@@ -3459,6 +3474,9 @@ class LayerControl {
3459
3474
  }
3460
3475
  });
3461
3476
  }
3477
+ if (layersAdded) {
3478
+ this.buildLayerItems();
3479
+ }
3462
3480
  } catch (error) {
3463
3481
  console.warn("Failed to check for new layers:", error);
3464
3482
  }