Skip to content

Commit

Permalink
[fix]webmap追加数据不对
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Nov 26, 2024
1 parent d2804b7 commit db15203
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/common/mapping/WebMapV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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'
) {
Expand Down Expand Up @@ -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);
Expand Down
40 changes: 36 additions & 4 deletions test/mapboxgl/mapping/WebMapV2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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({})));
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit db15203

Please sign in to comment.