|
4 | 4 | import { FetchRequest } from '../util/FetchRequest'; |
5 | 5 | import { getLayerCatalogRenderLayers, getLayerInfosFromCatalogs, getMainLayerFromCatalog, isSameRasterLayer, mergeFeatures, transformUrl } from './utils/util'; |
6 | 6 | import { SourceListModelV3 } from './utils/SourceListModelV3'; |
| 7 | +import cloneDeep from 'lodash.clonedeep'; |
7 | 8 |
|
8 | 9 | const LEGEND_RENDER_TYPE = { |
9 | 10 | TEXT: 'TEXT', |
@@ -349,7 +350,57 @@ export function createWebMapV3Extending(SuperClass, { MapManager, mapRepo, mapRe |
349 | 350 | const crs = new mapRepo.CRS(name, wkt, extent, extent[2] > 180 ? 'meter' : 'degree'); |
350 | 351 | mapRepo.CRS.set(crs); |
351 | 352 | } |
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 | + } |
353 | 404 | /** |
354 | 405 | * @private |
355 | 406 | * @function WebMapV3.prototype._initLayers |
|
0 commit comments