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.mjs CHANGED
@@ -1588,7 +1588,7 @@ class LayerControl {
1588
1588
  if (!state) {
1589
1589
  return;
1590
1590
  }
1591
- if (this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1591
+ if (layerId === "Background" || this.targetLayers.length === 0 || this.targetLayers.includes(layerId)) {
1592
1592
  this.addLayerItem(layerId, state);
1593
1593
  }
1594
1594
  });
@@ -3351,6 +3351,7 @@ class LayerControl {
3351
3351
  const isAutoDetectMode = this.targetLayers.length === 0 || this.targetLayers.length === 1 && this.targetLayers[0] === "Background" || this.targetLayers.every(
3352
3352
  (id) => id === "Background" || this.state.layerStates[id]
3353
3353
  );
3354
+ let layersAdded = false;
3354
3355
  const newLayers = [];
3355
3356
  const useBasemapStyleDetection = this.basemapLayerIds !== null && this.basemapLayerIds.size > 0;
3356
3357
  const useInitialLayerDetection = !useBasemapStyleDetection && this.initialLayerIds !== null && this.initialLayerIds.size > 0;
@@ -3430,7 +3431,10 @@ class LayerControl {
3430
3431
  opacity,
3431
3432
  name: this.generateFriendlyName(layerId)
3432
3433
  };
3433
- 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;
3434
3438
  });
3435
3439
  }
3436
3440
  if (this.customLayerRegistry) {
@@ -3446,7 +3450,10 @@ class LayerControl {
3446
3450
  isCustomLayer: true,
3447
3451
  customLayerType: this.customLayerRegistry.getSymbolType(layerId) || void 0
3448
3452
  };
3449
- 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;
3450
3457
  }
3451
3458
  }
3452
3459
  });
@@ -3467,6 +3474,9 @@ class LayerControl {
3467
3474
  }
3468
3475
  });
3469
3476
  }
3477
+ if (layersAdded) {
3478
+ this.buildLayerItems();
3479
+ }
3470
3480
  } catch (error) {
3471
3481
  console.warn("Failed to check for new layers:", error);
3472
3482
  }