Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

网络较慢时报Cannot read property 'Q' of null,自定义DOM组件不显示 #233

Open
Qujh97 opened this issue Aug 12, 2020 · 4 comments

Comments

@Qujh97
Copy link

Qujh97 commented Aug 12, 2020

我只使用了自定义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可能会复现,如有翻墙工具,开全局翻墙基本能够复现

@Qujh97 Qujh97 changed the title 网络较慢时报Cannot read property 'Q' of null,自定义DOM组件不现实 网络较慢时报Cannot read property 'Q' of null,自定义DOM组件不显示 Aug 12, 2020
@turengege
Copy link

相同的问题
手动清除localStorage后再刷新页面,总是会抱这个错误

@Qujh97
Copy link
Author

Qujh97 commented Aug 18, 2020

相同的问题
手动清除localStorage后再刷新页面,总是会抱这个错误

我目前的解决方案是加个刷新按钮,点击后重新渲染地图,让用户自己去刷新

@yucheng1207
Copy link

相同的问题
手动清除localStorage后再刷新页面,总是会抱这个错误

我目前的解决方案是加个刷新按钮,点击后重新渲染地图,让用户自己去刷新

Map组件的center不能使undefined,如果center为undefined不要传center属性 就没问题了

@yucheng1207
Copy link

yucheng1207 commented Mar 16, 2022

使用map的getCenter方法可以看到会返回Q属性(如下图)猜测“Cannot read property 'Q' of null”报错原因应该是Map组件的center传入undefined后源码根据传入的center新建一个LatLng点,然后去获取该点的Q值时报错了
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants