Skip to content

Commit

Permalink
【fix】 修复webmap 图层数据字段别名未生效 review by luox
Browse files Browse the repository at this point in the history
  • Loading branch information
xilanhuaweidapao committed Nov 22, 2023
1 parent b7a2730 commit ab8d5cc
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/common/_utils/WebMapService.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 => {
Expand Down
28 changes: 27 additions & 1 deletion src/common/_utils/__tests__/WebMapService.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit ab8d5cc

Please sign in to comment.