Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/SuperMap/vue-iclient into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shallowdream218 committed Nov 22, 2023
2 parents bf49b28 + 13514f2 commit 6d08ee0
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 35 deletions.
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
19 changes: 19 additions & 0 deletions src/mapboxgl/query/QueryViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getFeatureCenter, getValueCaseInsensitive } from 'vue-iclient/src/commo
import bbox from '@turf/bbox';
import envelope from '@turf/envelope';
import transformScale from '@turf/transform-scale';
import { statisticsFeatures } from 'vue-iclient/src/common/_utils/statistics';

/**
* @class QueryViewModel
Expand Down Expand Up @@ -170,6 +171,12 @@ export default class QueryViewModel extends mapboxgl.Evented {
let result = serviceResult.result;
if (result && result.totalCount !== 0) {
let resultFeatures = result.recordsets[0].features.features;
if(result.recordsets[0].fieldCaptions) {
let fields = result.recordsets[0].fields;
let fieldCaptions = result.recordsets[0].fieldCaptions;
let features = result.recordsets[0].features.features;
resultFeatures = statisticsFeatures(features, fields, fieldCaptions).features;
}
resultFeatures.length > 0 && (this.queryResult = { name: restMapParameter.name, result: resultFeatures });
this._addResultLayer(this.queryResult);
/**
Expand All @@ -194,6 +201,18 @@ export default class QueryViewModel extends mapboxgl.Evented {
let result = serviceResult.result;
if (result && result.totalCount !== 0) {
let resultFeatures = result.features.features;
if(result.datasetInfos) {
let fields = [];
let fieldCaptions = [];
const fieldInfos = result.datasetInfos[0].fieldInfos;
fieldInfos.forEach(fieldInfo => {
if(fieldInfo.name) {
fields.push(fieldInfo.name.toUpperCase());
fieldCaptions.push(fieldInfo.caption.toUpperCase());
}
});
resultFeatures = statisticsFeatures(resultFeatures, fields, fieldCaptions).features;
}
resultFeatures.length > 0 && (this.queryResult = { name: restDataParameter.name, result: resultFeatures });
this._addResultLayer(this.queryResult);
this.fire('querysucceeded', { result: this.queryResult });
Expand Down
8 changes: 6 additions & 2 deletions src/mapboxgl/query/__tests__/Query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,12 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click');
wrapper.vm.viewModel.on('querysucceeded', (res) => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
done();
});
wrapper.vm.$nextTick(() => {
expect(spyquery).toBeCalled();
done();
});
});

Expand All @@ -111,7 +114,8 @@ describe('query', () => {
expect(wrapper.vm.mapTarget).toBe('map');
const spyAddlayer = jest.spyOn(wrapper.vm.map, 'addLayer');
const spyquery = jest.spyOn(wrapper.vm, 'query');
wrapper.vm.viewModel.on('querysucceeded', () => {
wrapper.vm.viewModel.on('querysucceeded', (res) => {
expect(res.result.result[0].properties['名称']).toBe('四川省');
expect(spyAddlayer).toBeCalled();
done();
});
Expand Down
39 changes: 7 additions & 32 deletions test/unit/mocks/services.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import airport from './data/airport.json';
const fakeDataServiceResult = {
result: {
datasetInfos: [{
fieldInfos:[{name: "SmID", caption: "SmID", type: "INT32"}, {name: "NAME", caption: "名称", type: "WTEXT"}]
}],
currentCount: 1,
totalCount: 1,
features: {
Expand Down Expand Up @@ -78,22 +81,8 @@ const fakeMapServiceResult = {
]
},
fieldCaptions: [
'SmID',
'SmX',
'SmY',
'SmLibTileID',
'SmUserID',
'SmGeometrySize',
'USERID',
'POP',
'CAPITAL_LO',
'CAPITAL_CH',
'COUNTRY_CH',
'CAPITAL_EN',
'COUNTRY_EN',
'COUNTRY',
'CAP_POP',
'CAPITAL'
'SMID',
'名称'
],
fieldTypes: [
'INT32',
Expand All @@ -114,22 +103,8 @@ const fakeMapServiceResult = {
'WTEXT'
],
fields: [
'SmID',
'SmX',
'SmY',
'SmLibTileID',
'SmUserID',
'SmGeometrySize',
'USERID',
'POP',
'CAPITAL_LO',
'CAPITAL_CH',
'COUNTRY_CH',
'CAPITAL_EN',
'COUNTRY_EN',
'COUNTRY',
'CAP_POP',
'CAPITAL'
'SMID',
'NAME'
]
}
],
Expand Down
3 changes: 3 additions & 0 deletions test/unit/mocks/supermap.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ var QueryBySQLService = (SuperMap.QueryBySQLService = (url, options) => {
fields: {
0: 'SmID'
},
fieldCaptions: {
0: 'SmID'
},
features: {
type: 'FeatureCollection',
features: [
Expand Down

0 comments on commit 6d08ee0

Please sign in to comment.