【发布时间】:2019-08-19 15:30:48
【问题描述】:
我正在尝试在 ionic 中使用传单 leaflet。
我这样导入传单:import leaflet from 'leaflet';
为了构建地图,我写了这个:
loadmap() {
setTimeout(() => {
this.map = new leaflet.Map('map').setView([this.lat, this.lng], this.zoomLevel);
leaflet.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
// tslint:disable-next-line
attribution: 'Map data © <a '
+ 'href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a '
+ 'href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery '
+ '© <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18
}).addTo(this.map);
}, 50);
}
这工作得很好。接下来我要做的是向地图添加标记,如下所示:leaflet.L.marker([this.lat, this.lng]).addTo(this.map).bindPopup('Hello!');
但这不起作用,我收到以下错误消息
ERROR TypeError: Cannot read property 'marker' of undefined
如何寻址'L',我已经尝试了一些不同的方法,但没有成功。 有什么建议吗?
最好的问候!
【问题讨论】: