fix: 修改 scene destroy、兼容 L7React scene 和 layer 同时销毁导致的问题

This commit is contained in:
2912401452 2021-12-28 10:57:33 +08:00
parent 6250302f9e
commit 4e3cb3a1de
2 changed files with 12 additions and 5 deletions

View File

@ -405,7 +405,12 @@ export default class Scene extends EventEmitter implements ISceneService {
this.emit('destroy');
this.layerService.destroy();
this.rendererService.destroy();
// this.rendererService.destroy();
setTimeout(() => {
// Tip: 把这一部分销毁放到写下一个事件循环中执行,兼容 L7React 中 scene 和 layer 同时销毁的情况
this.rendererService.destroy();
})
this.map.destroy();
this.interactionService.destroy();

View File

@ -100,7 +100,7 @@ export default React.memo(function Map() {
return (
<>
{showScene && (
{showScene && (
<AMapScene
map={{
center: [110.19382669582967, 50.258134],
@ -116,9 +116,11 @@ export default React.memo(function Map() {
bottom: 0,
}}
onSceneLoaded={(scene) => {
// setTimeout(() => {
// scene.removeAllLayer()
// }, 3000)
setTimeout(() => {
// scene.removeAllLayer()
// scene.destroy()
}, 3000)
// setTimeout(() => scene.destroy(), 5000)
}}
>