diff --git a/src/common/_utils/WebMapService.ts b/src/common/_utils/WebMapService.ts index 4629f7c0..21410091 100644 --- a/src/common/_utils/WebMapService.ts +++ b/src/common/_utils/WebMapService.ts @@ -1,5 +1,6 @@ import { Events } from 'vue-iclient/src/common/_types/event/Events'; import { isXField, isYField, urlAppend, numberEqual } from 'vue-iclient/src/common/_utils/util'; +import { statisticsFeatures } from 'vue-iclient/src/common/_utils/statistics'; import * as convert from 'xml-js'; import max from 'lodash.max'; import min from 'lodash.min'; @@ -1239,6 +1240,20 @@ export default class WebMapService extends Events { withCredentials: this.handleWithCredentials(proxy, url, false), eventListeners: { processCompleted: getFeaturesEventArgs => { + let result = getFeaturesEventArgs.result; + if(result && result.datasetInfos) { + let fields = []; let fieldCaptions = []; let fieldTypes = []; + const fieldInfos = result.datasetInfos[0].fieldInfos; + fieldInfos.forEach(fieldInfo => { + if(fieldInfo.name) { + fields.push(fieldInfo.name.toUpperCase()); + fieldCaptions.push(fieldInfo.caption.toUpperCase()); + fieldTypes.push(fieldInfo.type); + } + }); + let data = statisticsFeatures(result.features.features, fields, fieldCaptions, fieldTypes); + getFeaturesEventArgs.result.features.features = data.features; + } processCompleted && processCompleted(getFeaturesEventArgs); }, processFailed: e => { diff --git a/src/common/_utils/__tests__/WebMapService.spec.js b/src/common/_utils/__tests__/WebMapService.spec.js index a2ec2a38..d90470b7 100644 --- a/src/common/_utils/__tests__/WebMapService.spec.js +++ b/src/common/_utils/__tests__/WebMapService.spec.js @@ -380,7 +380,33 @@ describe('WebMapService.spec', () => { const service = new WebMapService(mapId, options); expect.assertions(1); return service.getLayerFeatures(type, layer, baseProjection).then(data => { - expect(data).toStrictEqual(result); + expect(data.features[0].geometry).toStrictEqual(result.features[0].geometry); + done(); + }); + }); + + it('features will apply caption field when with caption config', async done => { + const type = 'rest_data'; + const layer = { + dataSource: { + url: 'https://fakeiportal.supermap.io/iportal/processCompleted' + }, + enableFields: ['latitude'] + }; + const baseProjection = 'EPSG:3857'; + const result = { + features: [ + { + geometry: { coordinates: [101.84004968, 26.0859968692659], type: 'Point' }, + properties: { NAME: '四川省', SMID: '1', index: '0', lat: 26.0859968692659, lon: 101.84004968 }, + type: 'Feature' + } + ], + type: 'feature' + }; + const service = new WebMapService(mapId, options); + return service.getLayerFeatures(type, layer, baseProjection).then(data => { + expect(data.features[0].properties['名称']).toBe('四川省'); done(); }); });