diff --git a/src/common/_utils/__tests__/iServerRestService.spec.js b/src/common/_utils/__tests__/iServerRestService.spec.js index 7dae596c..57f67fdd 100644 --- a/src/common/_utils/__tests__/iServerRestService.spec.js +++ b/src/common/_utils/__tests__/iServerRestService.spec.js @@ -138,8 +138,8 @@ describe('iServerRestService', () => { service.on({ getdatasucceeded: function (data) { expect(data.features[0].geometry).toBeTruthy(); - expect(data.features[0].properties['名称']).toBeTruthy(); - expect(data.features[0].properties.NAME).toBeFalsy(); + expect(data.features[0].properties['NAME']).toBeTruthy(); + expect(data.features[0].properties['名称']).toBeFalsy(); expect(mockPostParams).toMatch(/'attributeFilter':"NAME LIKE '%25A%25'/); done(); } @@ -155,7 +155,8 @@ describe('iServerRestService', () => { ); service.on({ getdatasucceeded: data => { - expect(data.fields).toEqual(['SMID', '名称']); + expect(data.fields).toEqual(['SMID', 'NAME']); + expect(data.fieldCaptions).toEqual(['SMID', '名称']); done(); } }); @@ -169,7 +170,8 @@ describe('iServerRestService', () => { ); service.on({ getdatasucceeded: data => { - expect(data.fields).toEqual(['SMID', '名称']); + expect(data.fields).toEqual(['SMID', 'NAME']); + expect(data.fieldCaptions).toEqual(['SMID', '名称']); expect(mockPostParams).toMatch(/'attributeFilter':"NAME LIKE '%25A%25'/); done(); } diff --git a/src/common/_utils/iServerRestService.js b/src/common/_utils/iServerRestService.js index 6d607e29..d1b156e5 100644 --- a/src/common/_utils/iServerRestService.js +++ b/src/common/_utils/iServerRestService.js @@ -422,10 +422,11 @@ export default class iServerRestService extends Events { }); return; } - let fields = []; - let fieldCaptions = []; - let fieldTypes = []; + let fields, fieldCaptions, fieldTypes; if (results.result.datasetInfos) { + fields = []; + fieldCaptions = []; + fieldTypes = []; const fieldInfos = results.result.datasetInfos[0].fieldInfos; fieldInfos.forEach(fieldInfo => { if (fieldInfo.name) { diff --git a/src/common/_utils/statistics.js b/src/common/_utils/statistics.js index f1321f61..907cc9b9 100644 --- a/src/common/_utils/statistics.js +++ b/src/common/_utils/statistics.js @@ -2,25 +2,17 @@ export function statisticsFeatures(features, fields, fieldCaptions, fieldTypes) const data = { features, fields: fields || [], + fieldCaptions: fieldCaptions || [], fieldValues: [], fieldTypes }; - if(features && !!features.length) { - if(fieldCaptions && fieldCaptions.length) { - features.forEach(feature => { - const newProperties = {}; - for (const field in feature.properties) { - const index = fields.indexOf(field); - const fieldCaption = fieldCaptions[index]; - newProperties[fieldCaption || field] = feature.properties[field]; - } - feature.properties = newProperties; - }); - } + if (features && !!features.length && !fieldCaptions && !fields) { const properties = Object.assign({}, features[0].properties, features[features.length - 1].properties); - data.fields = Object.keys(properties); + for (let attr in properties) { + data.fieldCaptions.push(attr); + data.fields.push(attr); + } } - for (let m in data.fields) { const fieldValue = []; for (let j in features) { diff --git a/src/mapboxgl/query/__tests__/Query.spec.js b/src/mapboxgl/query/__tests__/Query.spec.js index 973ff0c3..b6093dbf 100644 --- a/src/mapboxgl/query/__tests__/Query.spec.js +++ b/src/mapboxgl/query/__tests__/Query.spec.js @@ -106,7 +106,7 @@ describe('query', () => { expect(wrapper.vm.mapTarget).toBe('map'); const spyquery = jest.spyOn(wrapper.vm, 'query'); wrapper.vm.viewModel.on('querysucceeded', res => { - expect(res.result.result[0].properties['名称']).toBe('四川省'); + expect(res.result.result[0].properties['NAME']).toBe('四川省'); done(); }); wrapper.find(SmButton).find('.sm-component-query__a-button').trigger('click'); @@ -133,7 +133,7 @@ describe('query', () => { const spyAddlayer = jest.spyOn(wrapper.vm.map, 'addLayer'); const spyquery = jest.spyOn(wrapper.vm, 'query'); wrapper.vm.viewModel.on('querysucceeded', res => { - expect(res.result.result[0].properties['名称']).toBe('四川省'); + expect(res.result.result[0].properties['NAME']).toBe('四川省'); expect(spyAddlayer).toBeCalled(); done(); }); @@ -334,7 +334,7 @@ describe('query', () => { expect(wrapper.vm.mapTarget).toBe('map'); const spyquery = jest.spyOn(wrapper.vm, 'query'); wrapper.vm.viewModel.on('querysucceeded', res => { - expect(res.result.result[0].properties['名称']).toBe('四川省'); + expect(res.result.result[0].properties['NAME']).toBe('四川省'); expect(wrapper.vm.activeTab).toBe('result'); wrapper.find('.sm-component-query__job-button').trigger('click'); expect(wrapper.vm.activeTab).toBe('job');