refactor: use type="base" instead of slot="base" for control-layers
slot is a reserved HTML global attribute with shadow-DOM semantics; using it was misleading even though it happened to work. Switch to type="base" / type="overlay", which is conventional and carries no side effects.
This commit is contained in:
parent
e45162b0be
commit
eba6b2e6ad
@ -16,20 +16,20 @@
|
|||||||
<leaflet-map id="map" lat="51.5" lng="-0.09" zoom="12">
|
<leaflet-map id="map" lat="51.5" lng="-0.09" zoom="12">
|
||||||
<leaflet-control-layers position="topright" collapsed>
|
<leaflet-control-layers position="topright" collapsed>
|
||||||
<leaflet-tile-layer
|
<leaflet-tile-layer
|
||||||
slot="base"
|
type="base"
|
||||||
name="OpenStreetMap"
|
name="OpenStreetMap"
|
||||||
checked
|
checked
|
||||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||||
attribution="© OpenStreetMap"
|
attribution="© OpenStreetMap"
|
||||||
></leaflet-tile-layer>
|
></leaflet-tile-layer>
|
||||||
<leaflet-tile-layer
|
<leaflet-tile-layer
|
||||||
slot="base"
|
type="base"
|
||||||
name="Light"
|
name="Light"
|
||||||
url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
|
url="https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png"
|
||||||
attribution="© CARTO"
|
attribution="© CARTO"
|
||||||
></leaflet-tile-layer>
|
></leaflet-tile-layer>
|
||||||
<leaflet-tile-layer
|
<leaflet-tile-layer
|
||||||
slot="base"
|
type="base"
|
||||||
name="Dark"
|
name="Dark"
|
||||||
url="https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
|
url="https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png"
|
||||||
attribution="© CARTO"
|
attribution="© CARTO"
|
||||||
|
|||||||
@ -19,7 +19,7 @@ export class LeafletControlLayers extends WithProps(HTMLElement, PROPS) {
|
|||||||
const layer = (child as unknown as { leafletObject?: Layer }).leafletObject;
|
const layer = (child as unknown as { leafletObject?: Layer }).leafletObject;
|
||||||
const name = child.getAttribute('name');
|
const name = child.getAttribute('name');
|
||||||
if (!name || !layer) continue;
|
if (!name || !layer) continue;
|
||||||
const base = child.getAttribute('slot') === 'base';
|
const base = child.getAttribute('type') === 'base';
|
||||||
const checked = child.hasAttribute('checked');
|
const checked = child.hasAttribute('checked');
|
||||||
(base ? baseLayers : overlays)[name] = layer;
|
(base ? baseLayers : overlays)[name] = layer;
|
||||||
if (!checked) uncheckedLayers.push(layer);
|
if (!checked) uncheckedLayers.push(layer);
|
||||||
@ -81,7 +81,7 @@ export class LeafletControlLayers extends WithProps(HTMLElement, PROPS) {
|
|||||||
const layer = e.detail.leafletObject;
|
const layer = e.detail.leafletObject;
|
||||||
const name = el.getAttribute('name');
|
const name = el.getAttribute('name');
|
||||||
if (!name || !layer) return;
|
if (!name || !layer) return;
|
||||||
const base = el.getAttribute('slot') === 'base';
|
const base = el.getAttribute('type') === 'base';
|
||||||
const checked = el.hasAttribute('checked');
|
const checked = el.hasAttribute('checked');
|
||||||
if (base) this.#obj!.addBaseLayer(layer, name);
|
if (base) this.#obj!.addBaseLayer(layer, name);
|
||||||
else this.#obj!.addOverlay(layer, name);
|
else this.#obj!.addOverlay(layer, name);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user