Skip to content

Commit

Permalink
【faeture】webmap 支持copylayer
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongjiaojiao committed Jun 28, 2024
1 parent 24ec0c5 commit f5d51d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/mapboxgl/web-map/WebMapViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface MapHandler {
_updateRasterSource?: (sourceId: string, options: { tileSize: number }) => void;
echartsLayerResize?: () => void;
updateOverlayLayer?: (layerInfo: Record<string, any>, features: any, mergeByField?: string) => void;
copyLayer?: (id: string, layerInfo: Record<string, any>) => boolean;
}

export default class WebMapViewModel extends Events {
Expand Down Expand Up @@ -691,4 +692,8 @@ export default class WebMapViewModel extends Events {
return ids;
}, []);
}

copyLayer(id: string, layerInfo: Record<string, any>) {
return this._handler?.copyLayer?.(id, layerInfo);
}
}
15 changes: 15 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,21 @@ describe('WebMapViewModel.spec', () => {
};
viewModel.on({ addlayerssucceeded: callback });
});

it('copy layer', done => {
const fetchResource = {
'https://fakeiportal.supermap.io/iportal/web/datas/123456/content.json?pageSize=9999999&currentPage=1&parentResType=MAP&parentResId=undefined':
layerData_geojson['MARKER_GEOJSON']
};
mockFetch(fetchResource);
const id = markerLayer;
const viewModel = new WebMapViewModel(id, { ...commonOption }, { ...commonMapOptions }, { ...commonMap });
const callback = function (data) {
expect(viewModel.copyLayer('layer1')).not.toThrow();
done();
};
viewModel.on({ addlayerssucceeded: callback });
});
});


Expand Down
4 changes: 2 additions & 2 deletions src/mapboxgl/web-map/control/legend/LegendViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class LegendViewModel extends mapboxgl.Evented {
}

getStyle(layerName) {
const appreciableLayers = this.webmap.getAppreciableLayers();
const legendInfo = this.webmap.getLegendInfo();
const appreciableLayers = this.webmap?.getAppreciableLayers() || [];
const legendInfo = this.webmap?.getLegendInfo() || [];
return legendInfo.filter(info => {
return (
info.layerId === layerName &&
Expand Down
23 changes: 23 additions & 0 deletions src/mapboxgl/web-map/control/legend/__tests__/legend.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,28 @@ describe('Legend.vue', () => {
};
mapWrapper.vm.viewModel.on({ addlayerssucceeded: addCallback });
});

it('map not load', async done => {
const fetchResource = {
'https://fakeiportal.supermap.io/iportal/web/config/portal.json': iportal_serviceProxy,
'https://fakeiportal.supermap.io/iportal/web/maps/123/map.json': uniqueLayer_point,
'https://fakeiportal.supermap.io/iportal/web/datas/676516522/content.json?pageSize=9999999&currentPage=1&parentResType=MAP&parentResId=123':
layerData
};
mockFetch(fetchResource);
mapWrapper = mount(SmWebMap, {
propsData: {
serverUrl: 'https://fakeiportal.supermap.io/iportal',
mapId: '123'
}
});
const addCallback = async function (data) {
wrapper = mount(SmLegend);
await wrapper.setProps({ layerNames: ['民航数据'] })
await wrapper.vm.$nextTick();
expect(wrapper.vm.legendList['民航数据']).toBeUndefined();
done();
};
});
});

2 changes: 1 addition & 1 deletion static/libs/iclient-mapboxgl/iclient-mapboxgl.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions test/unit/mocks/mapboxgl_iclient_webmapv3.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class WebMapV3 extends Evented {
return this._generateLayerCatalog();
}

copyLayer() {}

clean() {}

_initLayers() {
Expand Down

0 comments on commit f5d51d6

Please sign in to comment.