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

你好,路由切换之后getOverlays返回空数组 #34

Closed
F5F5 opened this issue Nov 16, 2017 · 2 comments
Closed

你好,路由切换之后getOverlays返回空数组 #34

F5F5 opened this issue Nov 16, 2017 · 2 comments

Comments

@F5F5
Copy link

F5F5 commented Nov 16, 2017

loadMap(map: any) {
    console.log('loaded');
    console.log(this.map);
    this.map = map;
    const BMap: any = window['BMap'];
    const marker = this.map.getOverlays()[0];
    const label = new BMap.Label('<div class="newPointLabel"><h1>此位置不对吗?</h1><p>快来拖动此图标到达正确位置</p></div>', {
      offset: new BMap.Size(-90, -116),
      enableMassClear: false
    });
    label.setStyle({
      backgroundColor: 'none',
      border: 0
    });
    marker.setLabel(label);
}

新手,请大牛见谅~

路由切换之后map.getOverlays()返回空数组导致无法获取maker,刷新则无问题,

我把这些写在loadMap里面可以吗?

请问一下可能是什么原因呢?

@leftstick
Copy link
Owner

因为marker是在创建完map之后才创建的,所以的确有这个可能性在loadMap回调里使用this.map.getOverlays()拿到的是空数组。至于你说页面刷新一下就没事了,我还真想不出来为什么。

不过看你的代码,应该是需要给marker上加一个label,那么我觉得和 #33 有相同的诉求,我会在下一个版本里为marker也加一个loaded事件,这样你用这个事件,就可以保证拿到你要的marker实例了。

需求敦促我加把劲,我尽快把这个功能做了并上线

@leftstick
Copy link
Owner

试试4.1.0吧,我给marker增加了loaded事件,你的操作写在那个里面

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

2 participants