I am currently working on an application using LitElement components. I would like to integrate Leaflet into it and am having issues with displaying the map. I have installed Leaflet in my project with npm and have created a class looking like this.
import {LitElement, html, css} from 'lit-element';
import './node_modules/leaflet/dist/leaflet';
class Map extends LitElement{
static get styles() {
return [css``];
}
constructor() {
super();
}
connectedCallback() {
super.connectedCallback();
let map = L.map('mapid').setView([51.505, -0.09], 13);
let urlTemplate = 'http://{s}.tile.osm.org/{z}/{x}/{y}.png';
map.addLayer(L.tileLayer(urlTemplate, {minZoom: 4}));
}
render() {
return html`
<link rel="stylesheet" href="./node_modules/leaflet/dist/leaflet.css">
<div id="mapid" style="height: 100%"></div>
`;
}
}
customElements.define("my-map", Map);
Running my application results in following error: Uncaught TypeError: Cannot set property 'L' of undefined. I am a little lost on how I could use Leaflet to display a map in my LitElement application and would be thankful for a nudge into the right direction.