我正试图在我的Leaflet地图中添加图例,这是我的选择:
html:
<div #LeafletMap></div>
ts:
@ViewChild('LeafletMap') mapDiv;
ngOnInit(){
this.map = L.map(this.mapDiv.nativeElement, {wheelDebounceTime: 400});
this.map.setView([0, 0], 12);
this.addLegend();
}
private addLegend() {
const legend = L.control({position: 'bottomright'});
legend.onAdd = function (this.map) {
const div = L.DomUtil.create('div', 'info legend');
div.innerHTML +=
'test legend';
};
legend.addTo(this.map);
}
问题是这返回一个错误,使我完全迷路:
TypeError: Cannot read property 'classList' of undefined
at addClass (leaflet-src.js:2320)
at NewClass.addTo (leaflet-src.js:4727)
我在做什么错了?