fix: 修复地图销毁后,更新 LayerPopup 配置报错问题 (#1480)

* fix: 修复通过 click 方式创建 Popup 同时触发 closeOnClick 问题

* feat: 修复地图销毁之后,调用 LayerPopup 方法报错问题

Co-authored-by: yanxiong <oujinhui.ojh@antgroup.com>
This commit is contained in:
heiyexing 2022-11-16 11:10:58 +08:00 committed by GitHub
parent d060794a19
commit d6ee3cd5cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 11 deletions

View File

@ -387,11 +387,14 @@ export default class Popup<O extends IPopupOption = IPopupOption>
* @protected
*/
protected updateCloseOnClick(onlyClear?: boolean) {
this.mapsService.off('click', this.onCloseButtonClick);
if (this.popupOption.closeOnClick && !onlyClear) {
requestAnimationFrame(() => {
this.mapsService.on('click', this.onCloseButtonClick);
});
const mapsService = this.mapsService;
if (mapsService) {
this.mapsService.off('click', this.onCloseButtonClick);
if (this.popupOption.closeOnClick && !onlyClear) {
requestAnimationFrame(() => {
this.mapsService.on('click', this.onCloseButtonClick);
});
}
}
}
@ -405,12 +408,14 @@ export default class Popup<O extends IPopupOption = IPopupOption>
}
protected updateFollowCursor(onlyClear?: boolean) {
const container = this.mapsService.getContainer()!;
container.removeEventListener('mousemove', this.onMouseMove);
if (this.popupOption.followCursor && !onlyClear) {
requestAnimationFrame(() => {
container.addEventListener('mousemove', this.onMouseMove);
});
const container = this.mapsService?.getContainer();
if (container) {
container.removeEventListener('mousemove', this.onMouseMove);
if (this.popupOption.followCursor && !onlyClear) {
requestAnimationFrame(() => {
container.addEventListener('mousemove', this.onMouseMove);
});
}
}
}