diff --git a/dev-demos/features/line/demos/line.tsx b/dev-demos/features/line/demos/line.tsx index fd5f6322b2..88899f9b7e 100644 --- a/dev-demos/features/line/demos/line.tsx +++ b/dev-demos/features/line/demos/line.tsx @@ -124,6 +124,7 @@ export default () => { scene.on('loaded', () => { scene.addLayer(layer); + scene.render(); }); }, []); return ( diff --git a/dev-demos/features/line/demos/lineArc3d.tsx b/dev-demos/features/line/demos/lineArc3d.tsx index 43ff8dc5fe..47603314b1 100644 --- a/dev-demos/features/line/demos/lineArc3d.tsx +++ b/dev-demos/features/line/demos/lineArc3d.tsx @@ -120,6 +120,7 @@ export default () => { scene.addLayer(dotPoint); scene.addLayer(flyLine2); scene.addLayer(flyLine); + }); }); }, []); diff --git a/dev-demos/features/point/pointCircle.md b/dev-demos/features/point/pointCircle.md index 09647a01ca..2265dd6d95 100644 --- a/dev-demos/features/point/pointCircle.md +++ b/dev-demos/features/point/pointCircle.md @@ -55,6 +55,7 @@ export default () => { }); scene.addLayer(pointLayer); + scene.render(); }, ) }) diff --git a/dev-demos/gallery/scale/diverging.tsx b/dev-demos/gallery/scale/diverging.tsx index 452cb4a9f5..5bc404d18c 100644 --- a/dev-demos/gallery/scale/diverging.tsx +++ b/dev-demos/gallery/scale/diverging.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useEuropeData, addEuropeLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/dev-demos/gallery/scale/linear.tsx b/dev-demos/gallery/scale/linear.tsx index b7fa4f6c31..c6507e584e 100644 --- a/dev-demos/gallery/scale/linear.tsx +++ b/dev-demos/gallery/scale/linear.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useData, addLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/dev-demos/gallery/scale/quantile.tsx b/dev-demos/gallery/scale/quantile.tsx index 61034be468..62e791a281 100644 --- a/dev-demos/gallery/scale/quantile.tsx +++ b/dev-demos/gallery/scale/quantile.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useData, addLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/dev-demos/gallery/scale/quantize.tsx b/dev-demos/gallery/scale/quantize.tsx index 723247f40e..fc5a529c3e 100644 --- a/dev-demos/gallery/scale/quantize.tsx +++ b/dev-demos/gallery/scale/quantize.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useData, addLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/dev-demos/gallery/scale/sequential.tsx b/dev-demos/gallery/scale/sequential.tsx index 9b6337a5a7..6387009f06 100644 --- a/dev-demos/gallery/scale/sequential.tsx +++ b/dev-demos/gallery/scale/sequential.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useData, addLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/dev-demos/gallery/scale/threshold.tsx b/dev-demos/gallery/scale/threshold.tsx index 6891c35963..e623a573fc 100644 --- a/dev-demos/gallery/scale/threshold.tsx +++ b/dev-demos/gallery/scale/threshold.tsx @@ -1,5 +1,5 @@ import { PolygonLayer, Scene } from '@antv/l7'; -import { Mapbox } from '@antv/l7-maps'; +import { Map } from '@antv/l7-maps'; import React, { useEffect } from 'react'; import { useData, addLayers } from './useLine'; @@ -9,7 +9,7 @@ export default () => { useEffect(() => { const scene = new Scene({ id: 'map', - map: new Mapbox({ + map: new Map({ pitch: 0, style: 'light', center: [-96, 37.8], diff --git a/packages/core/src/services/layer/ILayerService.ts b/packages/core/src/services/layer/ILayerService.ts index 98b7195aad..b8dfb31641 100644 --- a/packages/core/src/services/layer/ILayerService.ts +++ b/packages/core/src/services/layer/ILayerService.ts @@ -1,5 +1,5 @@ // @ts-ignore -import { SyncBailHook, SyncHook, SyncWaterfallHook } from '@antv/async-hook'; +import { SyncBailHook, SyncHook, SyncWaterfallHook,AsyncSeriesBailHook } from '@antv/async-hook'; import { IColorRamp, Tile, TilesetManager } from '@antv/l7-utils'; import { Container } from 'inversify'; import Clock from '../../utils/clock'; @@ -282,7 +282,7 @@ export interface ILayer { encodeDataLength: number; pickedFeatureID: number | null; hooks: { - init: SyncBailHook; + init: AsyncSeriesBailHook; afterInit: SyncBailHook; beforeRenderData: SyncWaterfallHook; beforeRender: SyncBailHook; @@ -354,7 +354,7 @@ export interface ILayer { values?: StyleAttributeOption, updateOptions?: Partial, ): void; - init(): ILayer; + init(): Promise; scale(field: string | number | IScaleOptions, cfg?: IScale): ILayer; getScale(name: string): any; size(field: StyleAttrField, value?: StyleAttributeOption): ILayer; @@ -607,7 +607,7 @@ export interface ILayerService { clear(): void; add(layer: ILayer): void; addMask(mask: ILayer): void; - initLayers(): void; + initLayers(): Promise; startAnimate(): void; stopAnimate(): void; getSceneInited(): boolean; diff --git a/packages/core/src/services/layer/LayerService.ts b/packages/core/src/services/layer/LayerService.ts index 1d938ad0c7..ff66a737c8 100644 --- a/packages/core/src/services/layer/LayerService.ts +++ b/packages/core/src/services/layer/LayerService.ts @@ -49,12 +49,23 @@ export default class LayerService implements ILayerService { public add(layer: ILayer) { + // if (this.sceneInited) { + // layer.init(); + // } + // todo if (this.sceneInited) { + layer.on('inited',()=>{ + this.updateLayerRenderList(); + this.renderLayers(); + }) layer.init(); + } - this.layers.push(layer); - this.updateLayerRenderList(); + + // this.updateLayerRenderList(); + + } public addMask(mask: ILayer) { @@ -63,14 +74,15 @@ export default class LayerService implements ILayerService { } } - public initLayers() { + public async initLayers() { this.sceneInited = true; - this.layers.forEach((layer) => { + this.layers.forEach(async (layer) => { if (!layer.inited) { - layer.init(); + await layer.init(); + this.updateLayerRenderList(); } }); - this.updateLayerRenderList(); + } public getSceneInited() { @@ -134,7 +146,6 @@ export default class LayerService implements ILayerService { } this.alreadyInRendering = true; this.clear(); - for (const layer of this.layerList) { layer.hooks.beforeRenderData.call(); layer.hooks.beforeRender.call(); @@ -168,8 +179,7 @@ export default class LayerService implements ILayerService { public updateLayerRenderList() { // Tip: 每次更新都是从 layers 重新构建 this.layerList = []; - this.layers - .filter((layer) => layer.inited) + this.layers.filter((layer) => layer.inited) .filter((layer) => layer.isVisible()) .sort((pre: ILayer, next: ILayer) => { // 根据 zIndex 对渲染顺序进行排序 diff --git a/packages/core/src/services/scene/SceneService.ts b/packages/core/src/services/scene/SceneService.ts index 4d1e4143b1..a03f8298eb 100644 --- a/packages/core/src/services/scene/SceneService.ts +++ b/packages/core/src/services/scene/SceneService.ts @@ -314,9 +314,8 @@ export default class Scene extends EventEmitter implements ISceneService { if (this.destroyed) { this.destroy(); } - // FIXME: 初始化 marker 容器,可以放到 map 初始化方法中? - this.layerService.initLayers(); + await this.layerService.initLayers(); this.controlService.addControls(); this.loaded = true; this.emit('loaded'); @@ -324,6 +323,7 @@ export default class Scene extends EventEmitter implements ISceneService { } // 尝试初始化未初始化的图层 + this.layerService.initLayers(); this.layerService.updateLayerRenderList(); this.layerService.renderLayers(); diff --git a/packages/core/src/services/source/ISourceService.ts b/packages/core/src/services/source/ISourceService.ts index cb9a81194f..d6a33d4ee6 100644 --- a/packages/core/src/services/source/ISourceService.ts +++ b/packages/core/src/services/source/ISourceService.ts @@ -1,6 +1,7 @@ import { TilesetManager } from '@antv/l7-utils'; import { BBox } from '@turf/helpers'; export type DataType = string | object[] | object; +export type SourceEventType = 'inited' | 'sourceUpdate' export interface IParserCfg { type: string; x?: string; @@ -83,9 +84,9 @@ export interface ISource { ): void; destroy(): void; // Event - on(type: string, handler: (...args: any[]) => void): void; - off(type: string, handler: (...args: any[]) => void): void; - once(type: string, handler: (...args: any[]) => void): void; + on(type: SourceEventType | string, handler: (...args: any[]) => void): void; + off(type: SourceEventType | string, handler: (...args: any[]) => void): void; + once(type: SourceEventType | string, handler: (...args: any[]) => void): void; } export interface IRasterCfg { extent: [number, number, number, number]; diff --git a/packages/layers/src/core/BaseLayer.ts b/packages/layers/src/core/BaseLayer.ts index 851022b7b7..0763b1929e 100644 --- a/packages/layers/src/core/BaseLayer.ts +++ b/packages/layers/src/core/BaseLayer.ts @@ -1,5 +1,10 @@ // @ts-ignore -import { SyncBailHook, SyncHook, SyncWaterfallHook } from '@antv/async-hook'; +import { + SyncBailHook, + SyncHook, + SyncWaterfallHook, + AsyncSeriesBailHook, +} from '@antv/async-hook'; import { BlendType, IActiveOption, @@ -104,7 +109,7 @@ export default class BaseLayer }; // 生命周期钩子 public hooks = { - init: new SyncBailHook(), + init: new AsyncSeriesBailHook(), afterInit: new SyncBailHook(), beforeRender: new SyncBailHook(), beforeRenderData: new SyncWaterfallHook(), @@ -305,7 +310,7 @@ export default class BaseLayer return this; } - public init() { + public async init(): Promise { // 设置配置项 const sceneId = this.container.get(TYPES.SceneID); // 初始化图层配置项 @@ -403,10 +408,12 @@ export default class BaseLayer } // 触发 init 生命周期插件 - this.hooks.init.call(); + await this.hooks.init.promise(); + // this.pickingPassRender = this.normalPassFactory('pixelPicking'); // this.pickingPassRender.init(this); this.hooks.afterInit.call(); + this.inited = true; // 触发初始化完成事件; this.emit('inited', { target: this, @@ -416,8 +423,6 @@ export default class BaseLayer target: this, type: 'add', }); - - return this; } public updateModelData(data: IAttributeAndElements) { diff --git a/packages/layers/src/mask/index.ts b/packages/layers/src/mask/index.ts index 4801ab50ad..ccd28c0a2c 100644 --- a/packages/layers/src/mask/index.ts +++ b/packages/layers/src/mask/index.ts @@ -24,7 +24,7 @@ export default class MaskLayer extends BaseLayer { }; }; - public init() { + public async init(): Promise { // 设置配置项 const sceneId = this.container.get(TYPES.SceneID); @@ -95,10 +95,11 @@ export default class MaskLayer extends BaseLayer { } // 触发 init 生命周期插件 - this.hooks.init.call(); + await this.hooks.init.promise(); this.hooks.afterInit.call(); - - return this; + this.inited = true; + this.emit('inited'); + // TODO } public buildModels() { diff --git a/packages/layers/src/plugins/DataMappingPlugin.ts b/packages/layers/src/plugins/DataMappingPlugin.ts index 615cbfdda3..1eedcbf53d 100644 --- a/packages/layers/src/plugins/DataMappingPlugin.ts +++ b/packages/layers/src/plugins/DataMappingPlugin.ts @@ -31,16 +31,9 @@ export default class DataMappingPlugin implements ILayerPlugin { styleAttributeService, }: { styleAttributeService: IStyleAttributeService }, ) { - layer.hooks.init.tap('DataMappingPlugin', () => { + layer.hooks.init.tapPromise('DataMappingPlugin', async () => { // 初始化重新生成 map - const source = layer.getSource(); - if (source.inited) { - this.generateMaping(layer, { styleAttributeService }); - } else { - source.once('sourceUpdate', () => { - this.generateMaping(layer, { styleAttributeService }); - }); - } + this.generateMaping(layer, { styleAttributeService }); }); layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => { diff --git a/packages/layers/src/plugins/DataSourcePlugin.ts b/packages/layers/src/plugins/DataSourcePlugin.ts index c03855ab40..62b5452d03 100644 --- a/packages/layers/src/plugins/DataSourcePlugin.ts +++ b/packages/layers/src/plugins/DataSourcePlugin.ts @@ -8,20 +8,28 @@ export default class DataSourcePlugin implements ILayerPlugin { protected mapService: IMapService; public apply(layer: ILayer) { this.mapService = layer.getContainer().get(TYPES.IMapService); - layer.hooks.init.tap('DataSourcePlugin', () => { + layer.hooks.init.tapPromise('DataSourcePlugin', async () => { let source = layer.getSource(); if (!source) { // Tip: 用户没有传入 source 的时候使用图层的默认数据 const { data, options } = layer.sourceOption || layer.defaultSourceConfig; source = new Source(data, options); - layer.setSource(source); + await new Promise((resolve) => { + source.on('inited', () => { + layer.setSource(source); + resolve(null); + }); + }); } if (source.inited) { this.updateClusterData(layer); } else { - source.once('sourceUpdate', () => { - this.updateClusterData(layer); + await new Promise((resolve) => { + source.on('inited', () => { + this.updateClusterData(layer); + resolve(null); + }); }); } }); diff --git a/packages/layers/src/plugins/FeatureScalePlugin.ts b/packages/layers/src/plugins/FeatureScalePlugin.ts index a9475c6ca9..83237999b0 100644 --- a/packages/layers/src/plugins/FeatureScalePlugin.ts +++ b/packages/layers/src/plugins/FeatureScalePlugin.ts @@ -59,17 +59,15 @@ export default class FeatureScalePlugin implements ILayerPlugin { styleAttributeService, }: { styleAttributeService: IStyleAttributeService }, ) { - layer.hooks.init.tap('FeatureScalePlugin', () => { + layer.hooks.init.tapPromise('FeatureScalePlugin', async () => { this.scaleOptions = layer.getScaleOptions(); const attributes = styleAttributeService.getLayerStyleAttributes(); - - this.getSourceData(layer, ({ dataArray }) => { - if (Array.isArray(dataArray) && dataArray.length === 0) { - return; - } else { - this.caculateScalesForAttributes(attributes || [], dataArray); - } - }); + const dataArray = layer.getSource()?.data.dataArray; + if (Array.isArray(dataArray) && dataArray.length === 0) { + return; + } else { + this.caculateScalesForAttributes(attributes || [], dataArray); + } }); // 检测数据是否需要更新 diff --git a/packages/layers/src/plugins/LayerModelPlugin.ts b/packages/layers/src/plugins/LayerModelPlugin.ts index af3d05e7e3..310111c1aa 100644 --- a/packages/layers/src/plugins/LayerModelPlugin.ts +++ b/packages/layers/src/plugins/LayerModelPlugin.ts @@ -25,8 +25,9 @@ export default class LayerModelPlugin implements ILayerPlugin { } public apply(layer: ILayer) { - layer.hooks.init.tap('LayerModelPlugin', () => { - layer.inited = true; + layer.hooks.init.tapPromise('LayerModelPlugin', () => { + // TODO + // layer.inited = true; layer.modelLoaded = false; const source = layer.getSource(); if (source.inited) { diff --git a/packages/layers/src/plugins/MultiPassRendererPlugin.ts b/packages/layers/src/plugins/MultiPassRendererPlugin.ts index f5e7539db9..f81287a5df 100644 --- a/packages/layers/src/plugins/MultiPassRendererPlugin.ts +++ b/packages/layers/src/plugins/MultiPassRendererPlugin.ts @@ -38,7 +38,7 @@ export default class MultiPassRendererPlugin implements ILayerPlugin { normalPassFactory: (name: string) => IPass; }, ) { - layer.hooks.init.tap('MultiPassRendererPlugin', () => { + layer.hooks.init.tapPromise('MultiPassRendererPlugin', () => { const { enableMultiPassRenderer, passes = [] } = layer.getLayerConfig(); // SceneConfig 的 enableMultiPassRenderer 配置项可以统一关闭 diff --git a/packages/layers/src/plugins/PixelPickingPlugin.ts b/packages/layers/src/plugins/PixelPickingPlugin.ts index 06a11db22a..f69346fadc 100644 --- a/packages/layers/src/plugins/PixelPickingPlugin.ts +++ b/packages/layers/src/plugins/PixelPickingPlugin.ts @@ -33,7 +33,7 @@ export default class PixelPickingPlugin implements ILayerPlugin { }, ) { // TODO: 由于 Shader 目前无法根据是否开启拾取进行内容修改,因此即使不开启也需要生成 a_PickingColor - layer.hooks.init.tap('PixelPickingPlugin', () => { + layer.hooks.init.tapPromise('PixelPickingPlugin', () => { const { enablePicking } = layer.getLayerConfig(); styleAttributeService.registerStyleAttribute({ name: 'pickingColor', diff --git a/packages/layers/src/plugins/RegisterStyleAttributePlugin.ts b/packages/layers/src/plugins/RegisterStyleAttributePlugin.ts index 515c2f79b2..e994eb8d73 100644 --- a/packages/layers/src/plugins/RegisterStyleAttributePlugin.ts +++ b/packages/layers/src/plugins/RegisterStyleAttributePlugin.ts @@ -20,7 +20,7 @@ export default class RegisterStyleAttributePlugin implements ILayerPlugin { styleAttributeService, }: { styleAttributeService: IStyleAttributeService }, ) { - layer.hooks.init.tap('RegisterStyleAttributePlugin', () => { + layer.hooks.init.tapPromise('RegisterStyleAttributePlugin', () => { this.registerBuiltinAttributes(styleAttributeService, layer); }); } diff --git a/packages/layers/src/plugins/UpdateStyleAttributePlugin.ts b/packages/layers/src/plugins/UpdateStyleAttributePlugin.ts index 64c08ac208..2a3e85cf34 100644 --- a/packages/layers/src/plugins/UpdateStyleAttributePlugin.ts +++ b/packages/layers/src/plugins/UpdateStyleAttributePlugin.ts @@ -13,7 +13,7 @@ export default class UpdateStyleAttributePlugin implements ILayerPlugin { styleAttributeService, }: { styleAttributeService: IStyleAttributeService }, ) { - layer.hooks.init.tap('UpdateStyleAttributePlugin', () => { + layer.hooks.init.tapPromise('UpdateStyleAttributePlugin', () => { this.initStyleAttribute(layer, { styleAttributeService }); }); @@ -22,7 +22,7 @@ export default class UpdateStyleAttributePlugin implements ILayerPlugin { if ( layer.layerModelNeedUpdate || layer.tileLayer || - usage === 'basemap' + usage === 'basemap' // TODO: Chore 不走该流程 应从外部统一控制,而不是打补丁 ) { return; } diff --git a/packages/layers/src/tile/manager/tileLayerManager.ts b/packages/layers/src/tile/manager/tileLayerManager.ts index 659f23567f..2afeff565e 100644 --- a/packages/layers/src/tile/manager/tileLayerManager.ts +++ b/packages/layers/src/tile/manager/tileLayerManager.ts @@ -15,6 +15,7 @@ import { generateColorRamp, IColorRamp } from '@antv/l7-utils'; import { getLayerShape, getMaskValue, updateLayersConfig } from '../utils'; import TileConfigManager, { ITileConfigManager } from './tileConfigManager'; import TilePickManager from './tilePickerManager'; +// TODO: 命名问题,基类和父类看不出关联性 tile-tilelayer 概念混淆 export class TileLayerManager extends TileManager implements ITileLayerManager { public tilePickManager: ITilePickManager; public tileConfigManager: ITileConfigManager; diff --git a/packages/layers/src/tile/manager/tilePickerManager.ts b/packages/layers/src/tile/manager/tilePickerManager.ts index 90c3bb5bca..521ac6a064 100644 --- a/packages/layers/src/tile/manager/tilePickerManager.ts +++ b/packages/layers/src/tile/manager/tilePickerManager.ts @@ -26,7 +26,7 @@ export default class TilePickManager extends EventEmitter this.pickingService = pickingService; this.children = children; } - + // TODO:chore: 命名问题什么叫normal render /** * * @param layers diff --git a/packages/layers/src/tile/tileFactory/base.ts b/packages/layers/src/tile/tileFactory/base.ts index 051a1a6ec7..c834e458d0 100644 --- a/packages/layers/src/tile/tileFactory/base.ts +++ b/packages/layers/src/tile/tileFactory/base.ts @@ -84,6 +84,7 @@ export default class TileFactory implements ITileFactory { let geofeatures = []; if(layerType === 'LineLayer' && shape === 'simple') { features.map(feature => { + const cloneFeature = clone(feature); if(cloneFeature.geometry.type === 'MultiPolygon') { // @ts-ignore @@ -190,7 +191,8 @@ export default class TileFactory implements ITileFactory { layer.addMaskLayer(masklayer); } - // regist layer + + // regist layer registerLayers(this.parentLayer, layers); this.layers = [layer]; @@ -278,7 +280,7 @@ export default class TileFactory implements ITileFactory { protected emitEvent(layers: ILayer[], isVector?: boolean) { layers.map((layer) => { - layer.once('modelLoaded', () => { + layer.on('inited', () => { layer.on('click', (e) => { this.eventCache.click = 1; if (this.parentLayer.type === 'RasterLayer') { @@ -390,6 +392,7 @@ export default class TileFactory implements ITileFactory { isVector?: boolean, tile?: any, ) { + if (isVector === false) { // raster tile get rgb // e.pickedColors = readPixel(e.x, e.y, this.rendererService); diff --git a/packages/layers/src/tile/tileFactory/line.ts b/packages/layers/src/tile/tileFactory/line.ts index 8ed68ba8ef..9cf434672d 100644 --- a/packages/layers/src/tile/tileFactory/line.ts +++ b/packages/layers/src/tile/tileFactory/line.ts @@ -29,7 +29,8 @@ export default class VectorLineTile extends TileFactory { vectorTileLayer, source: source as Source, }); - layer.once('modelLoaded', () => { + + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/mask.ts b/packages/layers/src/tile/tileFactory/mask.ts index 45b452e709..b3b39ac8eb 100644 --- a/packages/layers/src/tile/tileFactory/mask.ts +++ b/packages/layers/src/tile/tileFactory/mask.ts @@ -30,7 +30,7 @@ export default class VectorMaskTile extends TileFactory { source: source as Source, needListen: false }); - layer.once('modelLoaded', () => { + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/point.ts b/packages/layers/src/tile/tileFactory/point.ts index fd9066975a..6938df95f8 100644 --- a/packages/layers/src/tile/tileFactory/point.ts +++ b/packages/layers/src/tile/tileFactory/point.ts @@ -30,7 +30,8 @@ export default class VectorPointTile extends TileFactory { source: source as Source, needListen: false }); - layer.once('modelLoaded', () => { + // layer.once('modelLoaded', () + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/polygon.ts b/packages/layers/src/tile/tileFactory/polygon.ts index 389a5763de..fe7338e10a 100644 --- a/packages/layers/src/tile/tileFactory/polygon.ts +++ b/packages/layers/src/tile/tileFactory/polygon.ts @@ -29,7 +29,7 @@ export default class VectorPolygonTile extends TileFactory { vectorTileLayer, source: source as Source, }); - layer.once('modelLoaded', () => { + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/raster.ts b/packages/layers/src/tile/tileFactory/raster.ts index 413dcb7bfa..fb3cdab526 100644 --- a/packages/layers/src/tile/tileFactory/raster.ts +++ b/packages/layers/src/tile/tileFactory/raster.ts @@ -21,12 +21,12 @@ export default class RasterTile extends TileFactory { }); const layer = this.createLayer({ - L7Layer: ImageLayer, + L7Layer: ImageLayer, tile, initOptions, source, }); - layer.once('modelLoaded', () => { + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/rasterData.ts b/packages/layers/src/tile/tileFactory/rasterData.ts index 24ec56411c..68b08f9fec 100644 --- a/packages/layers/src/tile/tileFactory/rasterData.ts +++ b/packages/layers/src/tile/tileFactory/rasterData.ts @@ -47,7 +47,6 @@ export default class RasterTiffTile extends TileFactory { .style({ colorTexture, opacity, - // TODO: 目前从 domain 从父瓦片图层的 style 进行配置,后续考虑从每个时机请求的栅格文件中进行配置 domain, clampHigh, clampLow, @@ -55,7 +54,7 @@ export default class RasterTiffTile extends TileFactory { this.emitEvent([layer], false); registerLayers(this.parentLayer, [layer]); - layer.once('modelLoaded', () => { + layer.on('inited', () => { tile.layerLoad(); }) return { diff --git a/packages/layers/src/tile/tileFactory/vectorLayer.ts b/packages/layers/src/tile/tileFactory/vectorLayer.ts index cf0fede28e..5441d0f53d 100644 --- a/packages/layers/src/tile/tileFactory/vectorLayer.ts +++ b/packages/layers/src/tile/tileFactory/vectorLayer.ts @@ -42,7 +42,7 @@ export default class VectorLayer extends BaseLayer< private pickedID: number | null = null; - public init() { + public async init(): Promise { // 设置配置项 const sceneId = this.container.get(TYPES.SceneID); this.configService.setLayerConfig(sceneId, this.id, this.rawConfig); @@ -118,10 +118,18 @@ export default class VectorLayer extends BaseLayer< } // 触发 init 生命周期插件 - this.hooks.init.call(); + await this.hooks.init.promise(); + this.inited = true; this.hooks.afterInit.call(); + this.emit('inited', { + target: this, + type: 'inited', + }); + this.emit('add', { + target: this, + type: 'add', + }); - return this; } public renderModels(isPicking?: boolean) { @@ -213,7 +221,6 @@ export default class VectorLayer extends BaseLayer< return pointFillModel; } } - protected getConfigSchema() { return { properties: { diff --git a/packages/layers/src/tile/tileLayer/baseMapTileLayer.ts b/packages/layers/src/tile/tileLayer/baseMapTileLayer.ts index bd15cf82cb..5c9f7fac2b 100644 --- a/packages/layers/src/tile/tileLayer/baseMapTileLayer.ts +++ b/packages/layers/src/tile/tileLayer/baseMapTileLayer.ts @@ -10,7 +10,6 @@ import { import { Tile, TilesetManager } from '@antv/l7-utils'; import { BaseMapTileLayerManager } from '../manager/baseMapTileLayerManager'; import { debounce } from 'lodash'; - export default class BaseTileLayer implements IBaseTileLayer { public get children() { return this.tileLayerManager.children; diff --git a/packages/layers/src/tile/tmsTileLayer.ts b/packages/layers/src/tile/tmsTileLayer.ts index 2c174ea50c..a0c9506d6a 100644 --- a/packages/layers/src/tile/tmsTileLayer.ts +++ b/packages/layers/src/tile/tmsTileLayer.ts @@ -28,7 +28,6 @@ export class TMSTileLayer extends BaseTileLayer { ); tile.parentLayerIDList.push(this.parent.id); tile.layerIDList.push(...layerIDList); - this.tileLayerManager.addChilds(layers); this.setPickState(layers); } else { diff --git a/packages/layers/src/tile/utils.ts b/packages/layers/src/tile/utils.ts index 0e5e872415..2245d1dbbe 100644 --- a/packages/layers/src/tile/utils.ts +++ b/packages/layers/src/tile/utils.ts @@ -167,6 +167,7 @@ export function tileAllLoad(tile: Tile, callback: () => void) { }, 36); } +// TODO 类方法 不是util export function updateLayersConfig(layers: ILayer[], key: string, value: any) { layers.map((layer) => { if (key === 'mask') { @@ -201,7 +202,6 @@ function updateImmediately(layers: ILayer[]) { }); return immediately; } - export function updateTileVisible( tile: Tile, layers: ILayer[], diff --git a/packages/source/src/source.ts b/packages/source/src/source.ts index 12443d7a0b..430cdf2bdc 100644 --- a/packages/source/src/source.ts +++ b/packages/source/src/source.ts @@ -75,7 +75,10 @@ export default class Source extends EventEmitter implements ISource { this.originData = data; this.initCfg(cfg); - this.init(); + this.init().then(()=>{ + this.inited = true; + this.emit('inited') + }); } public getClusters(zoom: number): any { @@ -187,7 +190,10 @@ export default class Source extends EventEmitter implements ISource { this.originData = data; this.dataArrayChanged = false; this.initCfg(options); - this.init(); + this.init().then(()=>{ + this.emit('sourceUpdate') + }); + } public destroy() { @@ -199,7 +205,7 @@ export default class Source extends EventEmitter implements ISource { this.tileset?.destroy(); } - private handleData() { + private async handleData() { return new Promise((resolve, reject) => { try { this.excuteParser(); @@ -233,13 +239,10 @@ export default class Source extends EventEmitter implements ISource { } } - private init() { + private async init() { // this.hooks.init.call(this); this.inited = false; - this.handleData().then(() => { - this.inited = true; - this.emit('sourceUpdate'); - }); + await this.handleData(); } /** diff --git a/packages/source/src/transform/map.ts b/packages/source/src/transform/map.ts index 2aedb29814..3ac0385f8e 100644 --- a/packages/source/src/transform/map.ts +++ b/packages/source/src/transform/map.ts @@ -1,5 +1,4 @@ import { IParserData } from '@antv/l7-core'; -type CallBack = (...args: any[]) => any; export function map(data: IParserData, options: { [key: string]: any }) { const { callback } = options; if (callback) {