The JS based custom element below appear to work but can not find the mapid
div that I add to the shadow DOM root. Is there a way in Leaflet or custom elements to allow stock Leaflet (version 1.4 which is the latest as of this writing) to find and use a shadow DOM-based mapid
div?
error:
Uncaught Error: Map container not found.
at NewClass._initContainer (Map.js:1102)
at NewClass.initialize (Map.js:136)
at new NewClass (Class.js:22)
at Module.createMap (Map.js:1717)
at new GDMap (gd-map.js:16)
at gd-map.js:30
at gd-map.js:31
I'm going on the approach that this simply is a case where Leaflet is looking for the mapid div in the dom root and can't find it in the shadow dom.
Javascript
import * as L from './leaflet/leaflet-src.esm.js';
(function () {
class GDMap extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `<div style="height:180px" id="mapid"></div>`;
var map = L.map('mapid').setView([51.505, -0.09], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.marker([51.5, -0.09]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
}
}
window.customElements.define('geodex-map', GDMap);
})();
edited post to align div id as pointed out.. still same issue though.