Skip to content

Commit 9ca62b2

Browse files
committed
【fix】当map maxzoom为24时 有些图层maxzoom会处理为25 超出24的最大限制,场景webmap3切换webmap2
AI-GEN: 10% Claude
1 parent 04a256c commit 9ca62b2

2 files changed

Lines changed: 269 additions & 15 deletions

File tree

src/common/mapping/WebMapV2.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
557557
const { minScale, maxScale } = layer.visibleScale;
558558
const crs = this.map.getCRS();
559559
layer.minzoom = Math.max(this._transformScaleToZoom(minScale, crs, layer.tileSize), 0);
560-
layer.maxzoom = Math.min(this.map.getMaxZoom()+1, this._transformScaleToZoom(maxScale, crs, layer.tileSize) + 0.0000001);
560+
layer.maxzoom = Math.min(this.map.getMaxZoom()+1, this._transformScaleToZoom(maxScale, crs, layer.tileSize) + 0.0000001, 24);
561561
}
562562

563563
if (type === 'tile') {
@@ -1499,7 +1499,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
14991499
},
15001500
layout,
15011501
minzoom: minzoom || 0,
1502-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1502+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
15031503
},
15041504
layerInfo.layerID
15051505
);
@@ -1551,7 +1551,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
15511551
visibility: layerInfo.visible
15521552
},
15531553
minzoom: minzoom || 0,
1554-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1554+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
15551555
};
15561556
if (filter) {
15571557
layerOptions.filter = filter;
@@ -1606,7 +1606,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
16061606
'icon-rotate': iconRotateExpression || ((layerInfo.style.rotation || 0) * 180) / Math.PI
16071607
},
16081608
minzoom: minzoom || 0,
1609-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1609+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
16101610
};
16111611
if (filter) {
16121612
layerOptions.filter = filter;
@@ -1658,7 +1658,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
16581658
'icon-color': style.fillColor
16591659
},
16601660
minzoom: minzoom || 0,
1661-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1661+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
16621662
};
16631663
if (filter) {
16641664
layerOptions.filter = filter;
@@ -1962,7 +1962,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
19621962
visibility: visible
19631963
},
19641964
minzoom: minzoom || 0,
1965-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1965+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
19661966
};
19671967
if (filterExpression.length > 1) {
19681968
layerOptions.filter = filterExpression;
@@ -2080,7 +2080,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
20802080
'icon-rotate': symbolStyle.rotation || 0
20812081
},
20822082
minzoom: minzoom || 0,
2083-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2083+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
20842084
filter: imagefilterExpression
20852085
},
20862086
layerID
@@ -2115,7 +2115,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
21152115
'icon-color': symbolStyle.fillColor
21162116
},
21172117
minzoom: minzoom || 0,
2118-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2118+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
21192119
filter: svgfilterExpression
21202120
},
21212121
layerID
@@ -2286,7 +2286,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
22862286
paint: this._transformStyleToMapBoxGl(defaultStyle, geomType),
22872287
layout: {},
22882288
minzoom: minzoom || 0,
2289-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2289+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
22902290
},
22912291
markerLayerID
22922292
);
@@ -2304,7 +2304,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
23042304
visibility: layerInfo.visible
23052305
},
23062306
minzoom: minzoom || 0,
2307-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2307+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
23082308
},
23092309
markerLayerID
23102310
);
@@ -2408,7 +2408,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
24082408
visibility: layerInfo.visible
24092409
},
24102410
minzoom: minzoom || 0,
2411-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2411+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
24122412
});
24132413
if (addToMap) {
24142414
this._addLayerSucceeded({ layerInfo, features });
@@ -2615,7 +2615,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
26152615
paint: layerStyle.style,
26162616
layout: layerStyle.layout || {},
26172617
minzoom: minzoom || 0,
2618-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2618+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
26192619
};
26202620
if (filter) {
26212621
style.filter = filter;
@@ -2639,7 +2639,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
26392639
type: 'raster',
26402640
tiles: url,
26412641
minzoom: minzoom || 0,
2642-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2642+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
26432643
tileSize: isIserver ? this.rasterTileSize : tileSize,
26442644
rasterSource: isIserver ? 'iserver' : '',
26452645
prjCoordSys:
@@ -2662,7 +2662,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
26622662
type: 'raster',
26632663
source: sourceId,
26642664
minzoom: minzoom || 0,
2665-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2665+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
26662666
layout: {
26672667
visibility: this._getVisibility(visibility)
26682668
}
@@ -2845,7 +2845,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
28452845
visibility: layerInfo.visible ? 'visible' : 'none'
28462846
},
28472847
minzoom: minzoom || 0,
2848-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2848+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
28492849
});
28502850
this._addLayerSucceeded();
28512851
}

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,4 +4674,258 @@ describe('mapboxgl_WebMapV2', () => {
46744674
expect(map.addLocalIdeographFontFamily).toHaveBeenCalledWith('sans-serif,微软雅黑,supermapol-icons');
46754675
webMapV2.clean(false);
46764676
});
4677+
it('layermaxzoom <=24', (done) => {
4678+
const mapInfo = {
4679+
"maxScale": "1:144447.92746805",
4680+
"baseLayer": {
4681+
"layerType": "MAPBOXSTYLE",
4682+
"name": "Capital@World33font",
4683+
"dataSource": {
4684+
"type": "EXTERNAL",
4685+
"url": "http://localhost:8195/portalproxy/ad4c697aec15c20c/iserver/services/map-mvt-CapitalWorld33font/restjsr/v1/vectortile/maps/Capital%40World33font"
4686+
}
4687+
},
4688+
"projection": "EPSG:4326",
4689+
"minScale": "1:591658710.909131",
4690+
"title": "Capital@World33font",
4691+
"version": "2.3.0",
4692+
}
4693+
const layerInfo = {
4694+
layerType: 'RANGE',
4695+
visible: 'visible',
4696+
themeSetting: {
4697+
themeField: 'TAX',
4698+
customSettings: {},
4699+
segmentMethod: 'offset',
4700+
segmentCount: 6,
4701+
colors: ['#ffc6c4', '#f4a3a8', '#e38191', '#cc607d', '#ad466c', '#8b3058', '#672044']
4702+
},
4703+
name: 'DataSource:DEMARCACION_TERRITORIAL_Tax',
4704+
featureType: 'POLYGON',
4705+
style: {
4706+
strokeWidth: 1,
4707+
fillColor: '#8b3058',
4708+
fillOpacity: 0.9,
4709+
lineDash: 'solid',
4710+
strokeColor: '#ffffff',
4711+
type: 'POLYGON',
4712+
strokeOpacity: 1
4713+
},
4714+
projection: 'EPSG:4326',
4715+
enableFields: ['TAX'],
4716+
dataSource: {
4717+
type: 'REST_DATA',
4718+
url: 'http://test:8090/iserver/services/data-JSON_test/rest/data',
4719+
dataSourceName: 'DataSource:DEMARCACION_TERRITORIAL_Tax'
4720+
},
4721+
layerID: 'DataSource:DEMARCACION_TERRITORIAL_Tax'
4722+
};
4723+
const features = [
4724+
{
4725+
type: 'Feature',
4726+
properties: {
4727+
TAX: '2.0E18',
4728+
index: '0'
4729+
},
4730+
geometry: {
4731+
type: 'MultiPolygon'
4732+
},
4733+
id: 1
4734+
},
4735+
{
4736+
type: 'Feature',
4737+
properties: {
4738+
TAX: '2.00000000000098E12',
4739+
index: '1'
4740+
},
4741+
geometry: {
4742+
type: 'MultiPolygon'
4743+
},
4744+
id: 2
4745+
},
4746+
{
4747+
type: 'Feature',
4748+
properties: {
4749+
TAX: '2.000000000098E10',
4750+
index: '2'
4751+
},
4752+
geometry: {
4753+
type: 'MultiPolygon'
4754+
},
4755+
id: 3
4756+
},
4757+
{
4758+
type: 'Feature',
4759+
properties: {
4760+
TAX: '2.000000000098E10',
4761+
index: '3'
4762+
},
4763+
geometry: {
4764+
type: 'MultiPolygon'
4765+
},
4766+
id: 4
4767+
},
4768+
{
4769+
type: 'Feature',
4770+
properties: {
4771+
TAX: '2.000000000098E10',
4772+
index: '4'
4773+
},
4774+
geometry: {
4775+
type: 'MultiPolygon'
4776+
},
4777+
id: 5
4778+
},
4779+
{
4780+
type: 'Feature',
4781+
properties: {
4782+
TAX: '2.000000000098E10',
4783+
index: '5'
4784+
},
4785+
geometry: {
4786+
type: 'MultiPolygon'
4787+
},
4788+
id: 6
4789+
},
4790+
{
4791+
type: 'Feature',
4792+
properties: {
4793+
TAX: '2.000000000098E10',
4794+
index: '6'
4795+
},
4796+
geometry: {
4797+
type: 'MultiPolygon'
4798+
},
4799+
id: 7
4800+
},
4801+
{
4802+
type: 'Feature',
4803+
properties: {
4804+
TAX: '2.000000000098E10',
4805+
index: '7'
4806+
},
4807+
geometry: {
4808+
type: 'MultiPolygon'
4809+
},
4810+
id: 8
4811+
},
4812+
{
4813+
type: 'Feature',
4814+
properties: {
4815+
TAX: '2.000000000098E10',
4816+
index: '8'
4817+
},
4818+
geometry: {
4819+
type: 'MultiPolygon'
4820+
},
4821+
id: 9
4822+
},
4823+
{
4824+
type: 'Feature',
4825+
properties: {
4826+
TAX: '2.000000000098E10',
4827+
index: '9'
4828+
},
4829+
geometry: {
4830+
type: 'MultiPolygon'
4831+
},
4832+
id: 10
4833+
},
4834+
{
4835+
type: 'Feature',
4836+
properties: {
4837+
TAX: '2.000000000098E10',
4838+
index: '10'
4839+
},
4840+
geometry: {
4841+
type: 'MultiPolygon'
4842+
},
4843+
id: 11
4844+
},
4845+
{
4846+
type: 'Feature',
4847+
properties: {
4848+
TAX: '2.000000000098E10',
4849+
index: '11'
4850+
},
4851+
geometry: {
4852+
type: 'MultiPolygon'
4853+
},
4854+
id: 12
4855+
},
4856+
{
4857+
type: 'Feature',
4858+
properties: {
4859+
TAX: '2.000000000098E10',
4860+
index: '12'
4861+
},
4862+
geometry: {
4863+
type: 'MultiPolygon'
4864+
},
4865+
id: 13
4866+
},
4867+
{
4868+
type: 'Feature',
4869+
properties: {
4870+
TAX: '2.000000000098E10',
4871+
index: '13'
4872+
},
4873+
geometry: {
4874+
type: 'MultiPolygon'
4875+
},
4876+
id: 14
4877+
},
4878+
{
4879+
type: 'Feature',
4880+
properties: {
4881+
TAX: '2.000000000098E10',
4882+
index: '14'
4883+
},
4884+
geometry: {
4885+
type: 'MultiPolygon'
4886+
},
4887+
id: 15
4888+
},
4889+
{
4890+
type: 'Feature',
4891+
properties: {
4892+
TAX: '2.000000000098E10',
4893+
index: '15'
4894+
},
4895+
geometry: {
4896+
type: 'MultiPolygon'
4897+
},
4898+
id: 16
4899+
}
4900+
];
4901+
spyOn(FetchRequest, 'get').and.callFake((url) => {
4902+
if (url.indexOf('portal.json') > -1) {
4903+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
4904+
}
4905+
if (url.indexOf('123/map.json') > -1) {
4906+
return Promise.resolve(
4907+
new Response(
4908+
JSON.stringify(mapInfo)
4909+
)
4910+
);
4911+
}
4912+
if (url.indexOf('/style.json')) {
4913+
return Promise.resolve(new Response(JSON.stringify(vectorTile_style)));
4914+
}
4915+
return Promise.resolve(new Response(JSON.stringify({})));
4916+
});
4917+
datavizWebmap = new WebMap('123', {
4918+
target: 'map',
4919+
serverUrl: 'http://fake/fakeiportal',
4920+
withCredentials: false
4921+
});
4922+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
4923+
expect(map).not.toBeUndefined();
4924+
expect(map.getStyle().layers.length).toBe(1);
4925+
map.setMaxZoom(24);
4926+
datavizWebmap._handler._createVectorLayer(layerInfo,features);
4927+
expect(map.getStyle().layers[1].maxzoom).toBe(24);
4928+
done();
4929+
});
4930+
});
46774931
});

0 commit comments

Comments
 (0)