diff --git a/src/mapboxgl/web-map/WebMapV2.ts b/src/mapboxgl/web-map/WebMapV2.ts index 1fed980c..99358aa9 100644 --- a/src/mapboxgl/web-map/WebMapV2.ts +++ b/src/mapboxgl/web-map/WebMapV2.ts @@ -2178,9 +2178,7 @@ export default class WebMap extends WebMapBase { } private _sendMapToUser(count: number, layersLen: number): void { - console.log('_sendMapToUser', count, layersLen); if (count === layersLen) { - console.log('_sendMapToUser finished', count, layersLen); /** * @event WebMapViewModel#addlayerssucceeded * @description 添加图层成功。 @@ -2198,10 +2196,10 @@ export default class WebMap extends WebMapBase { // @ts-ignore this._appreciableLayers = this._mapInfo.layers.map(layerInfo => { - const { layerID, dataSource, name, themeSetting, visible } = layerInfo; + const { layerID, dataSource, name, themeSetting, visible, serverId } = layerInfo; return { id: layerID, - dataSource, + dataSource: dataSource || { serverId }, title: name, themeSetting, visible, @@ -2254,11 +2252,14 @@ export default class WebMap extends WebMapBase { } private _rectifyLayersOrder() { - const exsitLayers = this._appreciableLayers.filter(layer => !!this.map.getLayer(layer.layerID)); + const renderLayers = this._appreciableLayers.reduce((layers, layer) => { + return layers.concat(layer.renderLayers); + }, []); + const exsitLayers = renderLayers.filter(layerId => !!this.map.getLayer(layerId)); const mapLayers = this.map.getStyle().layers; for (let index = exsitLayers.length - 1; index > -1; index--) { - const targetlayerId = exsitLayers[index].layerID; - let beforLayerId = exsitLayers[index + 1] ? exsitLayers[index + 1].layerID : undefined; + const targetlayerId = exsitLayers[index]; + let beforLayerId = exsitLayers[index + 1] ? exsitLayers[index + 1] : undefined; this._moveLayer(targetlayerId, beforLayerId); this._moveLayer(`${targetlayerId}-strokeLine`, beforLayerId); for (let index = 1; index < this.expectLayerLen + 1; index++) { @@ -2917,7 +2918,7 @@ export default class WebMap extends WebMapBase { updateOverlayLayer(layerInfo: any, features: any, mergeByField?: string) { // @ts-ignore const originLayerInfo = this._mapInfo.layers.find(layer => { - return layer.layerID === layerInfo.layerID; + return layer.layerID === layerInfo.id; }); if (features) { this._initOverlayLayer(originLayerInfo, features, mergeByField); diff --git a/src/mapboxgl/web-map/WebMapViewModel.ts b/src/mapboxgl/web-map/WebMapViewModel.ts index 30d67f97..12b2de89 100644 --- a/src/mapboxgl/web-map/WebMapViewModel.ts +++ b/src/mapboxgl/web-map/WebMapViewModel.ts @@ -113,6 +113,8 @@ export default class WebMapViewModel extends Events { private _appreciableLayers: Array = []; + private _layerList: Array = []; + private _handler: InstanceType; protected webMapService: WebMapService; @@ -294,7 +296,7 @@ export default class WebMapViewModel extends Events { const isGeojson = item.renderSource.type === 'geojson'; if (isGeojson) { // @ts-ignore - return Promise.resolve(source.getData().features); + return Promise.resolve(this.map.getSource(item.renderSource.id).getData().features); } else { const dataId = item.dataSource.serverId; // TODO iserver服务也可获取要素 @@ -316,7 +318,7 @@ export default class WebMapViewModel extends Events { } public getLayerList() { - return this._handler ? this._handler.getLayerCatalog() : []; + return this._layerList; } public changeItemVisible(item) { @@ -461,6 +463,7 @@ export default class WebMapViewModel extends Events { this._sourceListModel = sourceListModel; this._appreciableLayers = layers; this._cacheLayerId.push(...layers.map(layer => layer.renderLayers).flat()); + this._layerList = this._handler.getLayerCatalog(); this.triggerEvent('addlayerssucceeded', { map: map, mapparams: this.mapParams @@ -556,6 +559,7 @@ export default class WebMapViewModel extends Events { this.mapParams = mapparams; this._appreciableLayers = layers; this._cacheLayerId.push(...layers.map(layer => layer.renderLayers).flat()); + this._layerList = this._handler.getLayerCatalog(); this.triggerEvent('addlayerssucceeded', { map: this.map, mapparams: this.mapParams