maplibre-gl-layer-control 0.9.0 → 0.9.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 CHANGED
@@ -3,6 +3,8 @@
3
3
  [![npm version](https://img.shields.io/npm/v/maplibre-gl-layer-control.svg)](https://www.npmjs.com/package/maplibre-gl-layer-control)
4
4
  [![npm downloads](https://img.shields.io/npm/dm/maplibre-gl-layer-control.svg)](https://www.npmjs.com/package/maplibre-gl-layer-control)
5
5
  [![license](https://img.shields.io/npm/l/maplibre-gl-layer-control.svg)](https://github.com/opengeos/maplibre-gl-layer-control/blob/main/LICENSE)
6
+ [![Open in CodeSandbox](https://img.shields.io/badge/Open%20in-CodeSandbox-blue?logo=codesandbox)](https://codesandbox.io/p/github/opengeos/maplibre-gl-layer-control)
7
+ [![Open in StackBlitz](https://img.shields.io/badge/Open%20in-StackBlitz-blue?logo=stackblitz)](https://stackblitz.com/github/opengeos/maplibre-gl-layer-control)
6
8
 
7
9
  A comprehensive layer control for MapLibre GL with advanced styling capabilities. Built with TypeScript and React, providing both vanilla JavaScript and React integration options.
8
10
 
package/dist/index.cjs CHANGED
@@ -740,7 +740,8 @@ class LayerControl {
740
740
  currentY: 0,
741
741
  placeholder: null,
742
742
  draggedElement: null
743
- }
743
+ },
744
+ isStyleOperationInProgress: false
744
745
  };
745
746
  this.targetLayers = options.layers || Object.keys(this.state.layerStates);
746
747
  this.styleEditors = /* @__PURE__ */ new Map();
@@ -1674,13 +1675,20 @@ class LayerControl {
1674
1675
  this.toggleBackgroundVisibility(visible);
1675
1676
  return;
1676
1677
  }
1678
+ this.state.isStyleOperationInProgress = true;
1677
1679
  if (this.state.layerStates[layerId]) {
1678
1680
  this.state.layerStates[layerId].visible = visible;
1679
1681
  }
1680
1682
  if ((_a = this.customLayerRegistry) == null ? void 0 : _a.setVisibility(layerId, visible)) {
1683
+ setTimeout(() => {
1684
+ this.state.isStyleOperationInProgress = false;
1685
+ }, 200);
1681
1686
  return;
1682
1687
  }
1683
1688
  this.map.setLayoutProperty(layerId, "visibility", visible ? "visible" : "none");
1689
+ setTimeout(() => {
1690
+ this.state.isStyleOperationInProgress = false;
1691
+ }, 200);
1684
1692
  }
1685
1693
  /**
1686
1694
  * Change layer opacity
@@ -1691,16 +1699,23 @@ class LayerControl {
1691
1699
  this.changeBackgroundOpacity(opacity);
1692
1700
  return;
1693
1701
  }
1702
+ this.state.isStyleOperationInProgress = true;
1694
1703
  if (this.state.layerStates[layerId]) {
1695
1704
  this.state.layerStates[layerId].opacity = opacity;
1696
1705
  }
1697
1706
  if ((_a = this.customLayerRegistry) == null ? void 0 : _a.setOpacity(layerId, opacity)) {
1707
+ setTimeout(() => {
1708
+ this.state.isStyleOperationInProgress = false;
1709
+ }, 200);
1698
1710
  return;
1699
1711
  }
1700
1712
  const layerType = getLayerType(this.map, layerId);
1701
1713
  if (layerType) {
1702
1714
  setLayerOpacity(this.map, layerId, layerType, opacity);
1703
1715
  }
1716
+ setTimeout(() => {
1717
+ this.state.isStyleOperationInProgress = false;
1718
+ }, 200);
1704
1719
  }
1705
1720
  /**
1706
1721
  * Check if a layer is a user-added layer (vs basemap layer)
@@ -2509,6 +2524,9 @@ class LayerControl {
2509
2524
  * Check for new layers and add them to the control, remove deleted layers
2510
2525
  */
2511
2526
  checkForNewLayers() {
2527
+ if (this.state.isStyleOperationInProgress) {
2528
+ return;
2529
+ }
2512
2530
  try {
2513
2531
  const style = this.map.getStyle();
2514
2532
  if (!style || !style.layers) {
@@ -3164,6 +3182,7 @@ class LayerControl {
3164
3182
  */
3165
3183
  applyUIOrderToMap() {
3166
3184
  var _a;
3185
+ this.state.isStyleOperationInProgress = true;
3167
3186
  const items = this.panel.querySelectorAll(".layer-control-item");
3168
3187
  const uiLayerIds = [];
3169
3188
  items.forEach((item) => {
@@ -3185,6 +3204,9 @@ class LayerControl {
3185
3204
  }
3186
3205
  }
3187
3206
  (_a = this.onLayerReorder) == null ? void 0 : _a.call(this, uiLayerIds);
3207
+ setTimeout(() => {
3208
+ this.state.isStyleOperationInProgress = false;
3209
+ }, 200);
3188
3210
  }
3189
3211
  }
3190
3212
  exports.CustomLayerRegistry = CustomLayerRegistry;