Skip to content

Commit de27683

Browse files
[fix]webmap支持获取弹窗信息
1 parent a52d135 commit de27683

File tree

7 files changed

+1556
-777
lines changed

7 files changed

+1556
-777
lines changed

src/common/mapping/WebMapBase.js

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

361+
/**
362+
* @version 12.0.2
363+
* @function WebMapBase.prototype.getPopupInfos
364+
* @description 获取地图上所有图层的弹窗信息。
365+
* @returns {Array} 弹窗信息数组。
366+
*/
367+
getPopupInfos() {
368+
return this._handler._getPopupInfos() || [];
369+
}
370+
361371
/**
362372
* @version 11.2.1
363373
* @function WebMapBase.prototype.getLayers

src/common/mapping/WebMapV2.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,33 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
182182
crsManager.registerCRS(crs);
183183
return epsgCode;
184184
}
185+
_getPopupInfos() {
186+
const { layers = [] } = this._mapInfo;
187+
return layers?.map((layer) => {
188+
const { popupInfo, enableFields, name, layerID: id, captions: fieldCaptions } = layer;
189+
if (popupInfo){
190+
let elements = popupInfo.elements || [];
191+
if (fieldCaptions) {
192+
elements = popupInfo.elements?.map(item=>{
193+
if (item.type === 'FIELD') {
194+
item.fieldCaption = fieldCaptions?.[item.fieldName] || item.fieldName;
195+
}
196+
return item;
197+
});
198+
}
199+
return { ...popupInfo, id, elements };
200+
}
201+
if (enableFields) {
202+
const elements = enableFields.map((fieldName) => ({
203+
type: 'FIELD',
204+
fieldName,
205+
fieldCaption: fieldCaptions?.[fieldName] || fieldName
206+
}));
207+
return { elements, id, title: name };
208+
}
209+
return null;
210+
}).filter(item => item !== null);
211+
}
185212

186213
_handleLayerInfo(mapInfo, _taskID) {
187214
mapInfo = this._setLayerID(mapInfo);

src/common/mapping/WebMapV3.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,37 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, crsMa
335335
}
336336
return epsgCode;
337337
}
338+
_getFieldCaption(msDatasetId) {
339+
const { datas = [] } = this._mapResourceInfo;
340+
let fieldCaptions = null;
341+
datas.forEach(data => {
342+
const index = data.datasets?.findIndex(dataset => dataset.msDatasetId === msDatasetId);
343+
if (index !== -1) {
344+
fieldCaptions = data.datasets[index].fieldsCaptions;
345+
}
346+
});
347+
return fieldCaptions;
348+
}
349+
_getPopupInfos() {
350+
const { catalogs = [] } = this._mapResourceInfo;
351+
return catalogs?.map((item) => {
352+
const {id, popupInfo, msDatasetId} = item;
353+
if (popupInfo) {
354+
const fieldCaptions = this._getFieldCaption(msDatasetId);
355+
if (fieldCaptions) {
356+
popupInfo.elements = popupInfo.elements?.map(item=>{
357+
if (item.type === 'FIELD') {
358+
item.fieldCaption = fieldCaptions[item.fieldName] || item.fieldName;
359+
}
360+
return item;
361+
});
362+
}
363+
popupInfo.id = id;
364+
return popupInfo
365+
}
366+
return null
367+
})?.filter(item => item !== null);
368+
}
338369

339370
/**
340371
* @private

0 commit comments

Comments
 (0)