react-amap
react-amap copied to clipboard
网络较慢时报Cannot read property 'Q' of null,自定义DOM组件不显示
我只使用了自定义DOM组件,类似官网(代码如下)
render(){
return <div style={{width: '100%', height: '400px'}}>
<Map events={this.mapEvents} center={this.position}>
<Marker position={this.position} />
<div className="customLayer" style={styleA}>
<h4>A Custom Layer</h4>
<p>Current Center Is: {this.state.center}</p>
</div>
<div className="customLayer" style={styleB}>
<p> Another Custom Layer</p>
<Button onClick={()=>{alert('You Clicked!')}}>An Ant Design Button</Button>
</div>
</Map>
</div>
}
当网络较慢且第一次加载时,有大概率报Cannot read property 'Q' of null
,然后地图会继续慢慢加载出来,但是自定义的DOM组件不会跟着出现。
Chrome的network设置成Slow 3G可能会复现,如有翻墙工具,开全局翻墙基本能够复现
相同的问题 手动清除localStorage后再刷新页面,总是会抱这个错误
相同的问题 手动清除localStorage后再刷新页面,总是会抱这个错误
我目前的解决方案是加个刷新按钮,点击后重新渲染地图,让用户自己去刷新
相同的问题 手动清除localStorage后再刷新页面,总是会抱这个错误
我目前的解决方案是加个刷新按钮,点击后重新渲染地图,让用户自己去刷新
Map组件的center不能使undefined,如果center为undefined不要传center属性 就没问题了
使用map的getCenter方法可以看到会返回Q属性(如下图)猜测“Cannot read property 'Q' of null”报错原因应该是Map组件的center传入undefined后源码根据传入的center新建一个LatLng点,然后去获取该点的Q值时报错了