diff --git a/packages/core/src/services/scene/ISceneService.ts b/packages/core/src/services/scene/ISceneService.ts index 9499cdc852..35d1bb4097 100644 --- a/packages/core/src/services/scene/ISceneService.ts +++ b/packages/core/src/services/scene/ISceneService.ts @@ -4,6 +4,7 @@ import { IMapConfig } from '../map/IMapService'; import { IRenderConfig } from '../renderer/IRendererService'; export interface ISceneService { + destroyed: boolean; on(type: string, handle: (...args: any[]) => void): void; off(type: string, handle: (...args: any[]) => void): void; removeAllListeners(event?: string): this; diff --git a/packages/core/src/services/scene/SceneService.ts b/packages/core/src/services/scene/SceneService.ts index 73a52d47cf..7c744c414f 100644 --- a/packages/core/src/services/scene/SceneService.ts +++ b/packages/core/src/services/scene/SceneService.ts @@ -28,6 +28,8 @@ import { ISceneService } from './ISceneService'; */ @injectable() export default class Scene extends EventEmitter implements ISceneService { + public destroyed: true; + @inject(TYPES.SceneID) private readonly id: string; /** @@ -203,7 +205,7 @@ export default class Scene extends EventEmitter implements ISceneService { } public async render() { - if (this.rendering) { + if (this.rendering && !this.destroyed) { return; } @@ -212,6 +214,9 @@ export default class Scene extends EventEmitter implements ISceneService { if (!this.inited) { // 还未初始化完成需要等待 await this.initPromise; + if (this.destroy) { + this.destroy(); + } // FIXME: 初始化 marker 容器,可以放到 map 初始化方法中? this.logger.info(' render inited'); @@ -249,15 +254,21 @@ export default class Scene extends EventEmitter implements ISceneService { } public destroy() { + if (!this.inited) { + this.destroyed = true; + return; + } this.emit('destroy'); - this.inited = false; + this.layerService.destroy(); this.rendererService.destroy(); + this.map.destroy(); + this.interactionService.destroy(); this.controlService.destroy(); this.markerService.destroy(); this.removeAllListeners(); - this.map.destroy(); + this.inited = false; unbind(this.$container as HTMLDivElement, this.handleWindowResized); window .matchMedia('screen and (min-resolution: 2dppx)') diff --git a/packages/core/src/utils/dom.ts b/packages/core/src/utils/dom.ts index 017773a29f..b45b91c5e8 100644 --- a/packages/core/src/utils/dom.ts +++ b/packages/core/src/utils/dom.ts @@ -16,7 +16,6 @@ export function createRendererContainer( z-index:2; height: 100%; width: 100%; - background: inherit; pointer-events: none; `; $container.id = `l7-scene-${containerCounter++}`; diff --git a/packages/maps/src/amap/map.ts b/packages/maps/src/amap/map.ts index d48ec3e35a..d1c69109ce 100644 --- a/packages/maps/src/amap/map.ts +++ b/packages/maps/src/amap/map.ts @@ -419,7 +419,7 @@ export default class AMapService private removeLogoControl(): void { // @ts-ignore const logo = document.getElementsByClassName('amap-logo'); - if (logo) { + if (logo && logo[0]) { logo[0].setAttribute('style', 'display: none !important'); } } diff --git a/packages/react/src/component/LayerAttribute/Source.tsx b/packages/react/src/component/LayerAttribute/Source.tsx index f4bd6d71bd..df42b23261 100644 --- a/packages/react/src/component/LayerAttribute/Source.tsx +++ b/packages/react/src/component/LayerAttribute/Source.tsx @@ -17,8 +17,6 @@ export default React.memo(function Chart(props: ISourceProps) { } else { layer.setData(data, sourceOption); } - // 临时解决:若开启,每次更新之后自适应缩放; - // TODO:是否可以统一到Layer的option里,目前问题是Layer的autoFit一直为true,无法触发更新 if (sourceOption.autoFit) { layer.fitBounds(); } diff --git a/packages/react/src/component/LayerAttribute/index.ts b/packages/react/src/component/LayerAttribute/index.ts index 0e359cd0e4..3625e3c20a 100644 --- a/packages/react/src/component/LayerAttribute/index.ts +++ b/packages/react/src/component/LayerAttribute/index.ts @@ -53,7 +53,7 @@ export interface IStyleOptions { export interface ISourceOptions extends ISourceCFG { data: any; // 每次更新数据之后是否自适应缩放 - autoFit: boolean; + autoFit?: boolean; } export interface IActiveOptions { diff --git a/stories/Layers/components/column.tsx b/stories/Layers/components/column.tsx index 07823fca6c..fefb1d6201 100644 --- a/stories/Layers/components/column.tsx +++ b/stories/Layers/components/column.tsx @@ -22,6 +22,7 @@ export default class Column extends React.Component { rotation: 134.9507, }), }); + scene.destroy(); this.scene = scene; fetch( 'https://gw.alipayobjects.com/os/basement_prod/893d1d5f-11d9-45f3-8322-ee9140d288ae.json', diff --git a/stories/Layers/components/polygon_line.tsx b/stories/Layers/components/polygon_line.tsx index 60b776d092..3687be8cc2 100644 --- a/stories/Layers/components/polygon_line.tsx +++ b/stories/Layers/components/polygon_line.tsx @@ -88,7 +88,7 @@ export default class World extends React.Component { .color('#fff') .style({ opacity: 1, - sttoke: '#FFF', + stroke: '#FFF', strokeWidth: 0, }); scene.addLayer(pointLayer);