Skip to content

Commit

Permalink
[fix] 修改图层列表显隐不对;图层顺序不对问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Apr 19, 2024
1 parent 6b991eb commit c9c10fb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/mapboxgl/web-map/WebMapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 添加图层成功。
Expand All @@ -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,
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/mapboxgl/web-map/WebMapViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default class WebMapViewModel extends Events {

private _appreciableLayers: Array<any> = [];

private _layerList: Array<any> = [];

private _handler: InstanceType<typeof WebMapV2>;

protected webMapService: WebMapService;
Expand Down Expand Up @@ -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服务也可获取要素
Expand All @@ -316,7 +318,7 @@ export default class WebMapViewModel extends Events {
}

public getLayerList() {
return this._handler ? this._handler.getLayerCatalog() : [];
return this._layerList;
}

public changeItemVisible(item) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c9c10fb

Please sign in to comment.