angular – 在clickevent上的坐标
我是@ asymmetrik / ngx-leaflet和Angular的新手,所以这可能只是一个新手问题……
我有一个使用@asymmetrik/ngx-leaflet-tutorial-ngcli的Angular.io(v5)项目 现在我想得到我在地图上点击的点的坐标.根据Issue #51 get coordinates on click?,我补充说: map.on('click',() => { console.log(e.latlng); }); 至: onMapReady(map: Map) { map.fitBounds(this.route.getBounds(),{ padding: point(24,24),maxZoom: 12,animate: true }); map.on('click',() => { console.log(e.latlng); }); } 这给了我一个运行时错误: 哪种对我有意义.所以,我将代码更改为: map.on(‘click’,(e)=> {console.log(e.latlng);}); 但这也给了我一个错误:’LeafletEvent’类型中不存在属性’latlng’ 当我把e放到控制台console.log(e)时,我可以看到latlng-Property存在… 我的项目正在使用: “@ angular / cli”:“1.4.7”, 解决方法
编译器推断事件类型是
LeafletEvent,它没有latlng属性.这就是你得到这个错误的原因.
Leaflet文档表明此事件实际上是LeafletMouseEvent类型,它扩展了LeafletEvent.因此,您可以转换事件以获取对LeafletMouseEvent属性的访问权限(如下所示: map.on('click',(<LeafletMouseEvent>e) => { console.log(e.latlng); }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |