Skip to content

Commit

Permalink
add layerConnectedHandlers to l-map
Browse files Browse the repository at this point in the history
this resolves issue 54 with the controls
  • Loading branch information
mo-martinwilson committed Nov 27, 2024
1 parent bffc76a commit 49c3cd3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/l-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,19 @@ class LMap extends HTMLElement {
this.map.locate(parse(schema, this));
}

const layerConnectedHandlers = {
"l-control-layers": (layer, map) => layer.addTo(map),
"default": (layer, map) => map.addLayer(layer),
};

this.addEventListener(layerConnected, (ev) => {
const layer = ev.detail.layer;
this.map.addLayer(layer);
const { layer } = ev.detail;
const target = ev.target.localName ;

const layerConnectedHandler = layerConnectedHandlers[target] || layerConnectedHandlers["default"];
layerConnectedHandler(layer, this.map);
});


this.addEventListener(layerRemoved, (ev) => {
if (this.map !== null) {
Expand Down

0 comments on commit 49c3cd3

Please sign in to comment.