Skip to content

Commit

Permalink
[fix]isvj-8819 经纬网 sourclist
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiao-supermap committed Sep 11, 2024
1 parent 65cc89f commit 5e9b59e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/mapboxgl/web-map/SourceListModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SourceListModel {
this.map = options.map;
this.layers = options.layers || [];
this.appendLayers = options.appendLayers || false;
this.excludeSourceNames = ['tdt-search-', 'tdt-route-', 'smmeasure', 'mapbox-gl-draw', /tracklayer-\d+-line/];
this.excludeSourceNames = ['tdt-search-', 'tdt-route-', 'smmeasure', 'mapbox-gl-draw', /tracklayer-\d+-line/, /graticuleLayer_\d+_line/];
}

getLayers() {
Expand Down Expand Up @@ -45,7 +45,7 @@ class SourceListModel {
layers.push({
id: overlayLayer.id,
visibility,
source,
source: overlayLayer.id.match(/graticuleLayer_/) ? null : source,
type: overlayLayer.type
});
}
Expand Down
66 changes: 49 additions & 17 deletions src/mapboxgl/web-map/WebMapV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ export default class WebMap extends WebMapBase {

private _parentEvents: Record<string, Function>;

private _cacheLayerId: Map<string, Array<{ layerId: string; name: string; ignore?: boolean; }>> = new Map();
private _cacheLayerId: Map<string, Array<{ layerId: string; name: string; ignore?: boolean }>> = new Map();

private _appendLayers = false;

private _graticuleLayer: any;

constructor(
id: string | number | Object,
options: webMapOptions = {},
Expand Down Expand Up @@ -307,6 +309,9 @@ export default class WebMap extends WebMapBase {
}
this.expectLayerLen += overLayers.length;
}
if (mapInfo.grid && mapInfo.grid.graticule) {
this.expectLayerLen++;
}
}

_shouldLoadBaseLayer(mapInfo, layerFilter) {
Expand Down Expand Up @@ -430,7 +435,10 @@ export default class WebMap extends WebMapBase {
layerIds.push(item.id);
}
});
this._cacheLayerId.set(layerInfo.layerID || layerInfo.name, layerIds.map((layerId: string) => ({ layerId, name: layerId })));
this._cacheLayerId.set(
layerInfo.layerID || layerInfo.name,
layerIds.map((layerId: string) => ({ layerId, name: layerId }))
);
addedCallback && addedCallback();
},
error => {
Expand Down Expand Up @@ -602,7 +610,13 @@ export default class WebMap extends WebMapBase {
const options = this._createGraticuleOptions(graticuleInfo);
const graticuleLayers = new mapboxgl.supermap.GraticuleLayer(options);
this.map.addLayer(graticuleLayers);
this._graticuleLayer = graticuleLayers;
this._cacheLayerId.set(graticuleLayers.id, [
{ layerId: graticuleLayers.id, name: 'GraticuleLayer' },
{ layerId: graticuleLayers.sourceId, name: graticuleLayers.sourceId }
]);
this._setGraticuleDash(graticuleInfo.lineDash, graticuleLayers);
this._addLayerSucceeded();
}

private _createGraticuleOptions(graticuleInfo) {
Expand Down Expand Up @@ -638,7 +652,8 @@ export default class WebMap extends WebMapBase {
extent,
interval: interval && interval[0],
lngLabelStyle: lonLabelStyle,
latLabelStyle
latLabelStyle,
layerID: `graticuleLayer_${+new Date()}`
};
}

Expand Down Expand Up @@ -700,8 +715,7 @@ export default class WebMap extends WebMapBase {
}

private async _createBingLayer(layerName: string, layerInfo: any, addedCallback?: Function): Promise<void> {
let metaInfoUrl =
`https://dev.virtualearth.net/REST/v1/Imagery/Metadata/RoadOnDemand?uriScheme=https&include=ImageryProviders&key=${this.bingMapsKey}&c=zh-cn`;
let metaInfoUrl = `https://dev.virtualearth.net/REST/v1/Imagery/Metadata/RoadOnDemand?uriScheme=https&include=ImageryProviders&key=${this.bingMapsKey}&c=zh-cn`;
const metaInfo = await this._fetchRequest(metaInfoUrl, 'json', {
withoutFormatSuffix: true
});
Expand All @@ -715,8 +729,7 @@ export default class WebMap extends WebMapBase {
const resource = metaInfo.resourceSets[0].resources[0];
const urls = [];
resource.imageUrlSubdomains.map(function (subdomain) {
const imageUrl = resource.imageUrl
.replace('{subdomain}', subdomain);
const imageUrl = resource.imageUrl.replace('{subdomain}', subdomain);
urls.push(imageUrl);
});

Expand Down Expand Up @@ -2242,25 +2255,42 @@ export default class WebMap extends WebMapBase {
return list;
}, []);
const layersFromMapInfo = [];
const layerList = [this._mapInfo.baseLayer].concat(this._mapInfo.layers);
if (this._graticuleLayer) {
const { id: layerID, visible } = this._graticuleLayer;
layerList.push({ layerID, visible, name: 'GraticuleLayer' });
}
// this._mapInfo.layers 是有序的
[this._mapInfo.baseLayer].concat(this._mapInfo.layers).forEach((layerInfo: Record<string, any>) => {
layerList.forEach((layerInfo: Record<string, any>) => {
const targetLayerId = layerInfo.layerID || layerInfo.name;
const targetLayerVisible = layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
const targetLayerVisible =
layerInfo.visible === void 0 || layerInfo.visible === 'visible' || layerInfo.visible === true;
const matchLayers = this._cacheLayerId.get(targetLayerId);
matchLayers?.forEach(({ layerId, name, ignore }) => {
ignore !== false && layersFromMapInfo.push({
...layerInfo,
id: layerId,
name,
visible: targetLayerVisible
});
ignore !== false &&
layersFromMapInfo.push({
...layerInfo,
id: layerId,
name,
visible: targetLayerVisible
});
});
if (this.map.getLayer(`${targetLayerId}-strokeLine`)) {
layersFromMapInfo.push({ id: `${targetLayerId}-strokeLine`, visible: targetLayerVisible });
}
const expandLayers = flatCacheLayerId.map(item => item.includes(targetLayerId));
for (let index = 1; index < expandLayers.length + 1; index++) {
const layerTypes = ['additional', 'additional-image', 'additional-svg', 'additional-linedasharray', 'additional-symbol', 'POINT', 'TEXT', 'LINESTRING', 'POLYGON'];
const layerTypes = [
'additional',
'additional-image',
'additional-svg',
'additional-linedasharray',
'additional-symbol',
'POINT',
'TEXT',
'LINESTRING',
'POLYGON'
];
const layers = layerTypes.filter(type => this.map.getLayer(`${targetLayerId}-${type}-${index}`));
if (layers.length) {
layers.forEach(layer => {
Expand All @@ -2281,7 +2311,9 @@ export default class WebMap extends WebMapBase {
});
const appreciableLayers = this.getAppreciableLayers();
this._rectifyLayersOrder(appreciableLayers);
const matchLayers = appreciableLayers.filter((item: Record<string, any>) => item.renderLayers.some((id: string) => flatCacheLayerId.some(layerId => layerId === id)));
const matchLayers = appreciableLayers.filter((item: Record<string, any>) =>
item.renderLayers.some((id: string) => flatCacheLayerId.some(layerId => layerId === id))
);
this._triggerEvent('addlayerssucceeded', {
map: this.map,
layers: matchLayers,
Expand Down
2 changes: 2 additions & 0 deletions src/mapboxgl/web-map/__tests__/WebMapViewModel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ describe('WebMapViewModel.spec', () => {
};
viewModel.map.fire('zoomend');
expect(data).not.toBeUndefined();
expect(viewModel._handler._cacheLayerId.get('GraticuleLayer').length).toBe(2);
expect(Object.keys(viewModel._handler._sourceListModel.getSourceList()).length).toBe(3);
done();
};
const viewModel = new WebMapViewModel(id, { ...commonOption });
Expand Down
6 changes: 4 additions & 2 deletions static/libs/iclient-mapboxgl/iclient-mapboxgl.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test/unit/mocks/supermap_mapboxgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ supermap.Util = {
supermap.GraticuleLayer = () => {
return {
id: 'GraticuleLayer',
visible: true,
overlay: true,
sourceId: 'GraticuleLayer',
setStrokeStyle: jest.fn()
Expand Down

0 comments on commit 5e9b59e

Please sign in to comment.