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,6 +387,8 @@ export default class Popup<O extends IPopupOption = IPopupOption>
* @protected
*/
protected updateCloseOnClick(onlyClear?: boolean) {
const mapsService = this.mapsService;
if (mapsService) {
this.mapsService.off('click', this.onCloseButtonClick);
if (this.popupOption.closeOnClick && !onlyClear) {
requestAnimationFrame(() => {
@ -394,6 +396,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
});
}
}
}
protected updateCloseOnEsc(onlyClear?: boolean) {
window.removeEventListener('keydown', this.onKeyDown);
@ -405,7 +408,8 @@ export default class Popup<O extends IPopupOption = IPopupOption>
}
protected updateFollowCursor(onlyClear?: boolean) {
const container = this.mapsService.getContainer()!;
const container = this.mapsService?.getContainer();
if (container) {
container.removeEventListener('mousemove', this.onMouseMove);
if (this.popupOption.followCursor && !onlyClear) {
requestAnimationFrame(() => {
@ -413,6 +417,7 @@ export default class Popup<O extends IPopupOption = IPopupOption>
});
}
}
}
protected onKeyDown = (e: KeyboardEvent) => {
if (e.keyCode === 27) {