javascript - reactjs中引用高德地图点击地图vm报错?
本文介绍了javascript - reactjs中引用高德地图点击地图vm报错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
在componentDidUpdate中初始化地图控件,地图能够显示,点击地图中的点时能正确获取经纬度,但是控制台会不断的报错。
代码如下:
initMap(){
console.log("initMap===================");
let moduleProps = this.state.moduleProps;
var map = new AMap.Map("ma-container", {
resizeEnable: true,
center: [moduleProps.longitude,moduleProps.latitude],//地图中心点
zoom: 13 //地图显示的缩放级别
});
var marker = new AMap.Marker({
icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png",
position: [moduleProps.longitude,moduleProps.latitude]
});
marker.setMap(map);
//为地图注册click事件获取鼠标点击出的经纬度坐标
var clickEventListener = map.on('click', (e)=> {
moduleProps.longitude=e.lnglat.getLng();
moduleProps.latitude=e.lnglat.getLat();
console.log("aaaa====" + this.state.moduleProps.longitude);
this.setState({moduleProps: moduleProps}, ()=> {
console.log("hahah====" + this.state.moduleProps.longitude);
});
});
}
报错的是216行
解决方案
解决了,修改了一下结构。
这篇关于javascript - reactjs中引用高德地图点击地图vm报错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文