diff --git a/src/common/mapping/WebMapV2.js b/src/common/mapping/WebMapV2.js index 7c26d898f..145132f51 100644 --- a/src/common/mapping/WebMapV2.js +++ b/src/common/mapping/WebMapV2.js @@ -473,7 +473,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { } } - _initOverlayLayer(layerInfo, features = [], mergeByField) { + _initOverlayLayer(layerInfo, features = [], mergeByField, featureProjection) { const { layerID, layerType, visible, style, featureType, projection } = layerInfo; layerInfo.visible = visible ? 'visible' : 'none'; features = mergeFeatures({ sourceId: layerID, features, mergeByField, map: this.map }); @@ -491,10 +491,11 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { if (features && features[0] && features[0].geometry && features[0].geometry.type === 'Polygon') { features = this._handleMultyPolygon(features); } + const realProjection = featureProjection || projection; if ( features && - projection && - projection !== 'EPSG:4326' && + realProjection && + realProjection !== 'EPSG:4326' && layerInfo.dataSource && layerInfo.dataSource.type !== 'REST_DATA' ) { @@ -2979,12 +2980,12 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo }) { this.map.triggerRepaint(); } - updateOverlayLayer(layerInfo, features, mergeByField) { + updateOverlayLayer(layerInfo, features, mergeByField, featureProjection) { const originLayerInfo = this._mapInfo.layers.find((layer) => { return layer.layerID === layerInfo.id; }); if (features) { - this._initOverlayLayer(originLayerInfo, features, mergeByField); + this._initOverlayLayer(originLayerInfo, features, mergeByField, featureProjection); } else { const type = this.webMapService.getDatasourceType(originLayerInfo); this.getLayerFeatures(originLayerInfo, this._taskID, type); diff --git a/test/mapboxgl/mapping/WebMapV2Spec.js b/test/mapboxgl/mapping/WebMapV2Spec.js index ef2e78948..9347196fd 100644 --- a/test/mapboxgl/mapping/WebMapV2Spec.js +++ b/test/mapboxgl/mapping/WebMapV2Spec.js @@ -1414,6 +1414,38 @@ describe('mapboxgl_WebMapV2', () => { datavizWebmap.on('mapcreatesucceeded', callback); }); + it('updateOverlayLayer featureProjection', (done) => { + spyOn(FetchRequest, 'get').and.callFake((url) => { + if (url.indexOf('portal.json') > -1) { + return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy))); + } else if (url.indexOf('1788054202/map.json') > -1) { + return Promise.resolve(new Response(JSON.stringify(uniqueLayer_polygon))); + } else if (url.indexOf('datas/1960447494/content.json') > -1) { + return Promise.resolve(new Response(layerData_CSV)); + } else if (url.indexOf('datas/144371940/content.json')) { + return Promise.resolve(new Response(JSON.stringify(layerData_geojson['LINE_GEOJSON']))); + } + }); + datavizWebmap = new WebMap(id, { ...commonOption, map: commonMap }, { ...commonMapOptions }); + + const callback = function (data) { + const spy = spyOn(datavizWebmap._handler, 'transformFeatures').and.callThrough(); + datavizWebmap.updateOverlayLayer( + { id: 'test', projection: 'EPSG:3857' }, + { + type: 'FeatureCollection', + features: [{ type: 'Feature', geometry: { type: 'Point', coordinates: [110, 10] } }] + }, + '', + 'EPSG:4326' + ); + expect(spy).not.toHaveBeenCalled(); + done(); + }; + datavizWebmap.on('mapcreatesucceeded', callback); + done(); + }); + it('updateOverlayLayer unique', (done) => { spyOn(FetchRequest, 'get').and.callFake((url) => { if (url.indexOf('portal.json') > -1) { @@ -2983,7 +3015,7 @@ describe('mapboxgl_WebMapV2', () => { minzoom: 0 }); return Promise.resolve(new Response(JSON.stringify(nextStyleJSON))); - } + } if (url.indexOf('China.json') > -1) { return Promise.resolve(new Response(JSON.stringify({}))); } @@ -3169,11 +3201,11 @@ describe('mapboxgl_WebMapV2', () => { let style = map.getStyle(); expect(style.layers.length).toBeGreaterThan(layers.length); const sourceIds = Object.keys(style.sources); - const layerIds = style.layers.map(item => item.id); + const layerIds = style.layers.map((item) => item.id); webMap1.cleanLayers(); style = map.getStyle(); - expect(style.layers.some(layer => layerIds.some(id => id === layer.id))).toBeFalsy(); - expect(Object.keys(style.sources).some(sourceId => sourceIds.some(id => id === sourceId))).toBeFalsy(); + expect(style.layers.some((layer) => layerIds.some((id) => id === layer.id))).toBeFalsy(); + expect(Object.keys(style.sources).some((sourceId) => sourceIds.some((id) => id === sourceId))).toBeFalsy(); const webMap2 = new WebMap(106007908, { server, map: firstMap }); webMap2.once('mapcreatesucceeded', ({ layers }) => { expect(layers.length).toBe(2);