Skip to content

Commit ef6525a

Browse files
[fix]webmap获取弹窗配置项
1 parent 42bc145 commit ef6525a

7 files changed

Lines changed: 12860 additions & 2903 deletions

File tree

src/common/mapping/WebMapBase.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,16 @@ export function createWebMapBaseExtending(SuperClass, { mapRepo }) {
372372
pitch && this.setPitch(pitch);
373373
}
374374

375+
/**
376+
* @version 12.0.2
377+
* @function WebMapBase.prototype.getPopupInfos
378+
* @description 获取地图上所有图层的弹窗信息。
379+
* @returns {Array} 弹窗信息数组。
380+
*/
381+
getPopupInfos() {
382+
return (this._handler && this._handler._getPopupInfos()) || [];
383+
}
384+
375385
/**
376386
* @version 11.2.1
377387
* @function WebMapBase.prototype.getLayers

src/common/mapping/WebMapV2.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,33 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
208208
this._loadLayers(mapInfo, _taskID);
209209
}
210210
}
211+
_getPopupInfos() {
212+
const { layers = [] } = this._mapInfo;
213+
return layers.map((layer) => {
214+
const { popupInfo, enableFields, name, layerID: layerId, captions: fieldCaptions } = layer;
215+
if (popupInfo){
216+
let elements = popupInfo.elements || [];
217+
if (fieldCaptions) {
218+
elements = (popupInfo.elements || []).map(item => {
219+
if (item.type === 'FIELD') {
220+
item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName;
221+
}
222+
return item;
223+
});
224+
}
225+
return { ...popupInfo, layerId: [layerId], elements, title: name };
226+
}
227+
if (enableFields) {
228+
const elements = enableFields.map((fieldName) => ({
229+
type: 'FIELD',
230+
fieldName,
231+
fieldCaption: fieldCaptions ? (fieldCaptions[fieldName] || fieldName) : fieldName
232+
}));
233+
return { elements, layerId: [layerId], title: name };
234+
}
235+
return null;
236+
}).filter(item => item !== null);
237+
}
211238

212239
_handleLayerInfo(mapInfo, _taskID) {
213240
mapInfo = this._setLayerID(mapInfo);

src/common/mapping/WebMapV3.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { FetchRequest } from '../util/FetchRequest';
55
import { getLayerCatalogRenderLayers, getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util';
66
import { SourceListModelV3 } from './utils/SourceListModelV3';
7+
import cloneDeep from 'lodash.clonedeep';
78

89
const LEGEND_RENDER_TYPE = {
910
TEXT: 'TEXT',
@@ -349,7 +350,57 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe
349350
const crs = new mapRepo.CRS(name, wkt, extent, extent[2] > 180 ? 'meter' : 'degree');
350351
mapRepo.CRS.set(crs);
351352
}
352-
353+
_getFieldCaption(msDatasetId) {
354+
const { datas = [] } = this._mapResourceInfo;
355+
let fieldCaptions = null;
356+
datas.forEach(data => {
357+
if (data.datasets) {
358+
const index = data.datasets.findIndex(dataset => dataset.msDatasetId === msDatasetId);
359+
if (index !== -1) {
360+
fieldCaptions = data.datasets[index].fieldsCaptions;
361+
}
362+
}
363+
});
364+
return fieldCaptions;
365+
}
366+
_getPopupInfoContent(data, msDatasetId) {
367+
const popupInfo = cloneDeep(data);
368+
const fieldCaptions = this._getFieldCaption(msDatasetId);
369+
if (fieldCaptions) {
370+
popupInfo.elements = popupInfo.elements ? popupInfo.elements.map(item => {
371+
if (item.type === 'FIELD') {
372+
item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName;
373+
}
374+
return item;
375+
}) : [];
376+
}
377+
return popupInfo;
378+
}
379+
_getPopupInfoByCatalog(catalog, res = []) {
380+
const { catalogType, children } = catalog;
381+
if(catalogType === 'group' && children) {
382+
children.forEach(child => {
383+
this._getPopupInfoByCatalog(child, res);
384+
})
385+
}
386+
if (catalogType === 'layer') {
387+
const { popupInfo, msDatasetId, title, layersContent } = catalog;
388+
if (popupInfo) {
389+
const popupInfoVal = this._getPopupInfoContent(popupInfo, msDatasetId);
390+
if (popupInfoVal) {
391+
res.push({...popupInfoVal, layerId: layersContent, title});
392+
}
393+
}
394+
}
395+
}
396+
_getPopupInfos(_mapResourceInfo = this._mapResourceInfo) {
397+
const { catalogs = [] } = _mapResourceInfo;
398+
const res = [];
399+
catalogs.forEach((item) => {
400+
this._getPopupInfoByCatalog(item, res);
401+
})
402+
return res;
403+
}
353404
/**
354405
* @private
355406
* @function WebMapV3.prototype._initLayers

0 commit comments

Comments
 (0)