Skip to content

Commit 716d351

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

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
@@ -509,7 +509,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
509509
const { minScale, maxScale } = layer.visibleScale;
510510
const crs = this.map.getCRS();
511511
layer.minzoom = Math.max(this._transformScaleToZoom(minScale, crs), 0);
512-
layer.maxzoom = Math.min(this.map.getMaxZoom() + 1, this._transformScaleToZoom(maxScale, crs) + 0.0000001);
512+
layer.maxzoom = Math.min(this.map.getMaxZoom() + 1, this._transformScaleToZoom(maxScale, crs) + 0.0000001, 24);
513513
}
514514

515515
if (type === 'tile') {
@@ -1391,7 +1391,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
13911391
},
13921392
layout,
13931393
minzoom: minzoom || 0,
1394-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1394+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
13951395
},
13961396
layerInfo.layerID
13971397
);
@@ -1443,7 +1443,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
14431443
visibility: layerInfo.visible
14441444
},
14451445
minzoom: minzoom || 0,
1446-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1446+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
14471447
};
14481448
if (filter) {
14491449
layerOptions.filter = filter;
@@ -1498,7 +1498,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
14981498
'icon-rotate': iconRotateExpression || ((layerInfo.style.rotation || 0) * 180) / Math.PI
14991499
},
15001500
minzoom: minzoom || 0,
1501-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1501+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
15021502
};
15031503
if (filter) {
15041504
layerOptions.filter = filter;
@@ -1550,7 +1550,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
15501550
'icon-color': style.fillColor
15511551
},
15521552
minzoom: minzoom || 0,
1553-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1553+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
15541554
};
15551555
if (filter) {
15561556
layerOptions.filter = filter;
@@ -1854,7 +1854,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
18541854
visibility: visible
18551855
},
18561856
minzoom: minzoom || 0,
1857-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
1857+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
18581858
};
18591859
if (filterExpression.length > 1) {
18601860
layerOptions.filter = filterExpression;
@@ -1972,7 +1972,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
19721972
'icon-rotate': symbolStyle.rotation || 0
19731973
},
19741974
minzoom: minzoom || 0,
1975-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
1975+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
19761976
filter: imagefilterExpression
19771977
},
19781978
layerID
@@ -2007,7 +2007,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
20072007
'icon-color': symbolStyle.fillColor
20082008
},
20092009
minzoom: minzoom || 0,
2010-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2010+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
20112011
filter: svgfilterExpression
20122012
},
20132013
layerID
@@ -2178,7 +2178,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
21782178
paint: this._transformStyleToMapBoxGl(defaultStyle, geomType),
21792179
layout: {},
21802180
minzoom: minzoom || 0,
2181-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2181+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
21822182
},
21832183
markerLayerID
21842184
);
@@ -2196,7 +2196,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
21962196
visibility: layerInfo.visible
21972197
},
21982198
minzoom: minzoom || 0,
2199-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2199+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
22002200
},
22012201
markerLayerID
22022202
);
@@ -2300,7 +2300,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
23002300
visibility: layerInfo.visible
23012301
},
23022302
minzoom: minzoom || 0,
2303-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2303+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
23042304
});
23052305
if (addToMap) {
23062306
this._addLayerSucceeded({ layerInfo, features });
@@ -2507,7 +2507,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
25072507
paint: layerStyle.style,
25082508
layout: layerStyle.layout || {},
25092509
minzoom: minzoom || 0,
2510-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2510+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
25112511
};
25122512
if (filter) {
25132513
style.filter = filter;
@@ -2530,7 +2530,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
25302530
type: 'raster',
25312531
tiles: url,
25322532
minzoom: minzoom || 0,
2533-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2533+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
25342534
tileSize: isIserver ? this.rasterTileSize : 256,
25352535
rasterSource: isIserver ? 'iserver' : '',
25362536
prjCoordSys:
@@ -2553,7 +2553,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
25532553
type: 'raster',
25542554
source: sourceId,
25552555
minzoom: minzoom || 0,
2556-
maxzoom: maxzoom || this.map.getMaxZoom() + 1,
2556+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24),
25572557
layout: {
25582558
visibility: this._getVisibility(visibility)
25592559
}
@@ -2736,7 +2736,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
27362736
visibility: layerInfo.visible ? 'visible' : 'none'
27372737
},
27382738
minzoom: minzoom || 0,
2739-
maxzoom: maxzoom || this.map.getMaxZoom() + 1
2739+
maxzoom: Math.min(maxzoom || this.map.getMaxZoom() + 1, 24)
27402740
});
27412741
this._addLayerSucceeded();
27422742
}

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,4 +3791,258 @@ describe('mapboxgl_WebMapV2', () => {
37913791
expect(webMapV2._appendLayers).toBe(true);
37923792
expect(map.addLocalIdeographFontFamily).toHaveBeenCalledWith('sans-serif,微软雅黑,supermapol-icons');
37933793
});
3794+
it('layermaxzoom <=24', (done) => {
3795+
const mapInfo = {
3796+
"maxScale": "1:144447.92746805",
3797+
"baseLayer": {
3798+
"layerType": "MAPBOXSTYLE",
3799+
"name": "Capital@World33font",
3800+
"dataSource": {
3801+
"type": "EXTERNAL",
3802+
"url": "http://localhost:8195/portalproxy/ad4c697aec15c20c/iserver/services/map-mvt-CapitalWorld33font/restjsr/v1/vectortile/maps/Capital%40World33font"
3803+
}
3804+
},
3805+
"projection": "EPSG:4326",
3806+
"minScale": "1:591658710.909131",
3807+
"title": "Capital@World33font",
3808+
"version": "2.3.0",
3809+
}
3810+
const layerInfo = {
3811+
layerType: 'RANGE',
3812+
visible: 'visible',
3813+
themeSetting: {
3814+
themeField: 'TAX',
3815+
customSettings: {},
3816+
segmentMethod: 'offset',
3817+
segmentCount: 6,
3818+
colors: ['#ffc6c4', '#f4a3a8', '#e38191', '#cc607d', '#ad466c', '#8b3058', '#672044']
3819+
},
3820+
name: 'DataSource:DEMARCACION_TERRITORIAL_Tax',
3821+
featureType: 'POLYGON',
3822+
style: {
3823+
strokeWidth: 1,
3824+
fillColor: '#8b3058',
3825+
fillOpacity: 0.9,
3826+
lineDash: 'solid',
3827+
strokeColor: '#ffffff',
3828+
type: 'POLYGON',
3829+
strokeOpacity: 1
3830+
},
3831+
projection: 'EPSG:4326',
3832+
enableFields: ['TAX'],
3833+
dataSource: {
3834+
type: 'REST_DATA',
3835+
url: 'http://test:8090/iserver/services/data-JSON_test/rest/data',
3836+
dataSourceName: 'DataSource:DEMARCACION_TERRITORIAL_Tax'
3837+
},
3838+
layerID: 'DataSource:DEMARCACION_TERRITORIAL_Tax'
3839+
};
3840+
const features = [
3841+
{
3842+
type: 'Feature',
3843+
properties: {
3844+
TAX: '2.0E18',
3845+
index: '0'
3846+
},
3847+
geometry: {
3848+
type: 'MultiPolygon'
3849+
},
3850+
id: 1
3851+
},
3852+
{
3853+
type: 'Feature',
3854+
properties: {
3855+
TAX: '2.00000000000098E12',
3856+
index: '1'
3857+
},
3858+
geometry: {
3859+
type: 'MultiPolygon'
3860+
},
3861+
id: 2
3862+
},
3863+
{
3864+
type: 'Feature',
3865+
properties: {
3866+
TAX: '2.000000000098E10',
3867+
index: '2'
3868+
},
3869+
geometry: {
3870+
type: 'MultiPolygon'
3871+
},
3872+
id: 3
3873+
},
3874+
{
3875+
type: 'Feature',
3876+
properties: {
3877+
TAX: '2.000000000098E10',
3878+
index: '3'
3879+
},
3880+
geometry: {
3881+
type: 'MultiPolygon'
3882+
},
3883+
id: 4
3884+
},
3885+
{
3886+
type: 'Feature',
3887+
properties: {
3888+
TAX: '2.000000000098E10',
3889+
index: '4'
3890+
},
3891+
geometry: {
3892+
type: 'MultiPolygon'
3893+
},
3894+
id: 5
3895+
},
3896+
{
3897+
type: 'Feature',
3898+
properties: {
3899+
TAX: '2.000000000098E10',
3900+
index: '5'
3901+
},
3902+
geometry: {
3903+
type: 'MultiPolygon'
3904+
},
3905+
id: 6
3906+
},
3907+
{
3908+
type: 'Feature',
3909+
properties: {
3910+
TAX: '2.000000000098E10',
3911+
index: '6'
3912+
},
3913+
geometry: {
3914+
type: 'MultiPolygon'
3915+
},
3916+
id: 7
3917+
},
3918+
{
3919+
type: 'Feature',
3920+
properties: {
3921+
TAX: '2.000000000098E10',
3922+
index: '7'
3923+
},
3924+
geometry: {
3925+
type: 'MultiPolygon'
3926+
},
3927+
id: 8
3928+
},
3929+
{
3930+
type: 'Feature',
3931+
properties: {
3932+
TAX: '2.000000000098E10',
3933+
index: '8'
3934+
},
3935+
geometry: {
3936+
type: 'MultiPolygon'
3937+
},
3938+
id: 9
3939+
},
3940+
{
3941+
type: 'Feature',
3942+
properties: {
3943+
TAX: '2.000000000098E10',
3944+
index: '9'
3945+
},
3946+
geometry: {
3947+
type: 'MultiPolygon'
3948+
},
3949+
id: 10
3950+
},
3951+
{
3952+
type: 'Feature',
3953+
properties: {
3954+
TAX: '2.000000000098E10',
3955+
index: '10'
3956+
},
3957+
geometry: {
3958+
type: 'MultiPolygon'
3959+
},
3960+
id: 11
3961+
},
3962+
{
3963+
type: 'Feature',
3964+
properties: {
3965+
TAX: '2.000000000098E10',
3966+
index: '11'
3967+
},
3968+
geometry: {
3969+
type: 'MultiPolygon'
3970+
},
3971+
id: 12
3972+
},
3973+
{
3974+
type: 'Feature',
3975+
properties: {
3976+
TAX: '2.000000000098E10',
3977+
index: '12'
3978+
},
3979+
geometry: {
3980+
type: 'MultiPolygon'
3981+
},
3982+
id: 13
3983+
},
3984+
{
3985+
type: 'Feature',
3986+
properties: {
3987+
TAX: '2.000000000098E10',
3988+
index: '13'
3989+
},
3990+
geometry: {
3991+
type: 'MultiPolygon'
3992+
},
3993+
id: 14
3994+
},
3995+
{
3996+
type: 'Feature',
3997+
properties: {
3998+
TAX: '2.000000000098E10',
3999+
index: '14'
4000+
},
4001+
geometry: {
4002+
type: 'MultiPolygon'
4003+
},
4004+
id: 15
4005+
},
4006+
{
4007+
type: 'Feature',
4008+
properties: {
4009+
TAX: '2.000000000098E10',
4010+
index: '15'
4011+
},
4012+
geometry: {
4013+
type: 'MultiPolygon'
4014+
},
4015+
id: 16
4016+
}
4017+
];
4018+
spyOn(FetchRequest, 'get').and.callFake((url) => {
4019+
if (url.indexOf('portal.json') > -1) {
4020+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
4021+
}
4022+
if (url.indexOf('123/map.json') > -1) {
4023+
return Promise.resolve(
4024+
new Response(
4025+
JSON.stringify(mapInfo)
4026+
)
4027+
);
4028+
}
4029+
if (url.indexOf('/style.json')) {
4030+
return Promise.resolve(new Response(JSON.stringify(vectorTile_style)));
4031+
}
4032+
return Promise.resolve(new Response(JSON.stringify({})));
4033+
});
4034+
datavizWebmap = new WebMap('123', {
4035+
target: 'map',
4036+
serverUrl: 'http://fake/fakeiportal',
4037+
withCredentials: false
4038+
});
4039+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
4040+
expect(map).not.toBeUndefined();
4041+
expect(map.getStyle().layers.length).toBe(1);
4042+
map.setMaxZoom(24);
4043+
datavizWebmap._handler._createVectorLayer(layerInfo,features);
4044+
expect(map.getStyle().layers[1].maxzoom).toBe(24);
4045+
done();
4046+
});
4047+
});
37944048
});

0 commit comments

Comments
 (0)