From ab8d5cca180b23a6dff90b3fc358bc866565d134 Mon Sep 17 00:00:00 2001 From: qiwei Date: Wed, 22 Nov 2023 10:45:43 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90fix=E3=80=91=20=E4=BF=AE=E5=A4=8Dw?= =?UTF-8?q?ebmap=20=E5=9B=BE=E5=B1=82=E6=95=B0=E6=8D=AE=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=88=AB=E5=90=8D=E6=9C=AA=E7=94=9F=E6=95=88=20review=20by=20l?= =?UTF-8?q?uox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/_utils/WebMapService.ts | 15 ++++++++++ .../_utils/__tests__/WebMapService.spec.js | 28 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) 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(); }); }); From 13514f236de99884f58a4dfdda95e30e2b12d980 Mon Sep 17 00:00:00 2001 From: chenxianhui Date: Wed, 22 Nov 2023 12:42:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90fix=E3=80=91=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=98=BE=E7=A4=BA=E5=AD=97=E6=AE=B5=E5=88=AB?= =?UTF-8?q?=E5=90=8D=20review=20by=20qiw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mapboxgl/query/QueryViewModel.js | 19 +++++++++++ src/mapboxgl/query/__tests__/Query.spec.js | 8 +++-- test/unit/mocks/services.js | 39 ++++------------------ test/unit/mocks/supermap.js | 3 ++ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/mapboxgl/query/QueryViewModel.js b/src/mapboxgl/query/QueryViewModel.js index e1e4b291..895a4d3d 100644 --- a/src/mapboxgl/query/QueryViewModel.js +++ b/src/mapboxgl/query/QueryViewModel.js @@ -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 @@ -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); /** @@ -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 }); diff --git a/src/mapboxgl/query/__tests__/Query.spec.js b/src/mapboxgl/query/__tests__/Query.spec.js index 7b786a1b..560e57d5 100644 --- a/src/mapboxgl/query/__tests__/Query.spec.js +++ b/src/mapboxgl/query/__tests__/Query.spec.js @@ -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(); }); }); @@ -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(); }); diff --git a/test/unit/mocks/services.js b/test/unit/mocks/services.js index 50db7982..463d4798 100644 --- a/test/unit/mocks/services.js +++ b/test/unit/mocks/services.js @@ -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: { @@ -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', @@ -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' ] } ], diff --git a/test/unit/mocks/supermap.js b/test/unit/mocks/supermap.js index 1f4da6ac..6fc5e0c4 100644 --- a/test/unit/mocks/supermap.js +++ b/test/unit/mocks/supermap.js @@ -618,6 +618,9 @@ var QueryBySQLService = (SuperMap.QueryBySQLService = (url, options) => { fields: { 0: 'SmID' }, + fieldCaptions: { + 0: 'SmID' + }, features: { type: 'FeatureCollection', features: [