I have been attempting to utilize the example provided in the Leaflet quickstart guide within Angular 7. However, I keep encountering the error message
ERROR ReferenceError: L is not defined
. It is worth noting that I have not included Leaflet via JS files, but rather installed it through npm using the command npm install leaflet
. I can confirm that it is present in my node_modules
directory.
import { Component, OnInit } from '@angular/core';
declare let L;
@Component({
selector: 'app-mapvisual',
templateUrl: './mapvisual.component.html',
styleUrls: ['./mapvisual.component.css']
})
export class MapvisualComponent implements OnInit {
constructor() { }
ngOnInit() {
const map = L.map('map').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);
}
}
EDIT: I managed to find the solution by following the instructions provided here.