From ccdb87dc4d8ce2f2f049ab078b81665130956689 Mon Sep 17 00:00:00 2001 From: chenxianhui Date: Fri, 21 Jun 2024 08:58:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=20DV=E5=9C=B0=E5=9B=BE=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0=EF=BC=8CMD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=90=8E=E6=9B=B4=E6=96=B0=E6=97=A0=E6=95=88=20review?= =?UTF-8?q?=20by=20luox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mapboxgl/web-map/WebMapViewModel.ts | 3 ++ .../web-map/__tests__/WebMapViewModel.spec.js | 45 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/mapboxgl/web-map/WebMapViewModel.ts b/src/mapboxgl/web-map/WebMapViewModel.ts index 1b593f35..e5414897 100644 --- a/src/mapboxgl/web-map/WebMapViewModel.ts +++ b/src/mapboxgl/web-map/WebMapViewModel.ts @@ -1471,6 +1471,9 @@ export default class WebMapViewModel extends WebMapBase { }; if (!this.map.getSource(layerID)) { this.map.addSource(layerID, source); + } else { + // @ts-ignore + this.map.getSource(layerID).setData(source.data); } const iconID = `imageIcon-${layerID}`; if (style.type === 'IMAGE_POINT') { diff --git a/src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js b/src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js index 2535a307..9c7a9e09 100644 --- a/src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js +++ b/src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js @@ -129,6 +129,7 @@ const commonMap = { on: () => {}, fire: () => {}, setLayoutProperty: () => jest.fn(), + setPaintProperty: jest.fn(), addStyle: () => jest.fn(), remove: () => jest.fn(), setRenderWorldCopies: () => jest.fn(), @@ -1337,6 +1338,50 @@ describe('WebMapViewModel.spec', () => { viewModel.on({ addlayerssucceeded: callback }); }); + it('updateOverlayLayer GraphicLayer', done => { + const fetchResource = { + 'https://fakeiportal.supermap.io/iportal/web/datas/1920557079/content.json?pageSize=9999999¤tPage=1&parentResType=MAP&parentResId=undefined': + layerData_CSV, + 'https://fakeiportal.supermap.io/iportal/web/datas/13136933/content.json?pageSize=9999999¤tPage=1&parentResType=MAP&parentResId=undefined': + layerData_geojson['POINT_GEOJSON'] + }; + mockFetch(fetchResource); + const id = vectorLayer_point; + const viewModel = new WebMapViewModel(id, { ...commonOption }, undefined, { ...commonMap }); + const callback = function (data) { + const sourceData1 = data.map.getSource('浙江省高等院校(3)')._data.features; + expect(sourceData1.length).toBe(2); + const layerInfo = { ...vectorLayer_point.layers[0], id: vectorLayer_point.layers[0].name }; + const features = [ + { + type: 'Feature', + properties: { + '机场': '上海/浦东', + 'X坐标': '121.812361 ', + 'Y坐标': '31.093992 ', + '名次': '2', + '2017旅客吞吐量(人次)': '70,001,237 ', + '2016旅客吞吐量(人次)': '66,002,414 ', + '同比增速%': '3.5 ', + '2017货邮吞吐量(吨)': '3,824,279.9 ', + '2016货邮吞吐量(吨)': '3,440,279.7 ', + '2017起降架次(架次)': '496,774 ', + '2016起降架次(架次)': '479,902 ', + index: 1 + }, + geometry: { type: 'Point', coordinates: [Array] } + } + ] + const spy = jest.spyOn(viewModel, '_createGraphicLayer'); + viewModel.updateOverlayLayer(layerInfo, features); + expect(spy).toBeCalled(); + const sourceData2 = data.map.getSource('浙江省高等院校(3)')._data.features; + expect(sourceData2.length).toBe(1); + done(); + }; + viewModel.on({ addlayerssucceeded: callback }); + }); + it('add baselayer which is baidu', done => { const callback = function (data) { expect(data).not.toBeUndefined();