maplibre-gl-layer-control 0.17.2 → 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.cjs CHANGED
@@ -1590,7 +1590,7 @@ class LayerControl {
1590
1590
  if (!state) {
1591
1591
  return;
1592
1592
  }
1593
- if (this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1593
+ if (layerId === "Background" || this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1594
1594
  this.addLayerItem(layerId, state);
1595
1595
  }
1596
1596
  });
@@ -3353,6 +3353,7 @@ class LayerControl {
3353
3353
  const isAutoDetectMode = this.targetLayers.length === 0 || this.targetLayers.length === 1 && this.targetLayers[0] === "Background" || this.targetLayers.every(
3354
3354
  (id) => id === "Background" || this.state.layerStates[id]
3355
3355
  );
3356
+ let layersAdded = false;
3356
3357
  const newLayers = [];
3357
3358
  const useBasemapStyleDetection = this.basemapLayerIds !== null && this.basemapLayerIds.size > 0;
3358
3359
  const useInitialLayerDetection = !useBasemapStyleDetection && this.initialLayerIds !== null && this.initialLayerIds.size > 0;
@@ -3432,7 +3433,10 @@ class LayerControl {
3432
3433
  opacity,
3433
3434
  name: this.generateFriendlyName(layerId)
3434
3435
  };
3435
- this.addLayerItem(layerId, this.state.layerStates[layerId]);
3436
+ if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
3437
+ this.targetLayers.push(layerId);
3438
+ }
3439
+ layersAdded = true;
3436
3440
  });
3437
3441
  }
3438
3442
  if (this.customLayerRegistry) {
@@ -3448,7 +3452,10 @@ class LayerControl {
3448
3452
  isCustomLayer: true,
3449
3453
  customLayerType: this.customLayerRegistry.getSymbolType(layerId) || void 0
3450
3454
  };
3451
- this.addLayerItem(layerId, this.state.layerStates[layerId]);
3455
+ if (this.targetLayers.length > 0 && !this.targetLayers.includes(layerId)) {
3456
+ this.targetLayers.push(layerId);
3457
+ }
3458
+ layersAdded = true;
3452
3459
  }
3453
3460
  }
3454
3461
  });
@@ -3469,6 +3476,9 @@ class LayerControl {
3469
3476
  }
3470
3477
  });
3471
3478
  }
3479
+ if (layersAdded) {
3480
+ this.buildLayerItems();
3481
+ }
3472
3482
  } catch (error) {
3473
3483
  console.warn("Failed to check for new layers:", error);
3474
3484
  }