Skip to content

Commit f80122d

Browse files
committed
【fix】mapboxgl里layer的maxzoom应该比地图大一级 但是layer有24级的限制,所以map的maxzoom最大只能是23
1 parent 7e61910 commit f80122d

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

src/common/mapping/WebMapV2.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3133,7 +3133,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
31333133
const unit = crs.unit;
31343134
const scaleBase = 1.0 / Util.getScaleFromResolutionDpi((extent[2] - extent[0]) / tileSize, 96, unit);
31353135
const scaleDenominator = scale.split(':')[1];
3136-
return Math.min(24, +Math.log2(scaleBase / +scaleDenominator).toFixed(2));
3136+
return Math.min(23, +Math.log2(scaleBase / +scaleDenominator).toFixed(2));
31373137
}
31383138

31393139
_updateLayer(layerInfo) {

test/mapboxgl/mapping/WebMapV22Spec.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,4 +631,99 @@ describe('mapboxgl_WebMapV2_2', () => {
631631
}
632632
});
633633
});
634+
it('ISVJ-11511_maxzoom<=24', (done) => {
635+
// mapboxgl map的maxzoom是闭区间 layer的mazzoom是开区间。layer maxzoom的最大值是24
636+
// 为保证地图在maxzoom=24时能正常显示,地图的maxzoom不能设置为24,否则会导致图层无法显示,所以地图的maxzoom最大只能设置为23。
637+
let options = {
638+
server: server
639+
};
640+
const mapJSON = {
641+
"extent": {
642+
"leftBottom": {
643+
"x": 118.02310000000011,
644+
"y": 27.044700000000034
645+
},
646+
"rightTop": {
647+
"x": 122.94200000000001,
648+
"y": 31.180900000000065
649+
}
650+
},
651+
"maxScale": "1:0.9626322617192434",
652+
"level": 1,
653+
"center": {
654+
"x": 120.48255000000006,
655+
"y": 29.11280000000005
656+
},
657+
"baseLayer": {
658+
"layerType": "TILE",
659+
"name": "quxian",
660+
"url": "http://fack:8090/iserver/services/map-shapefile-quxian/rest/maps/quxian"
661+
},
662+
"layers": [],
663+
"description": "",
664+
"projection": "GEOGCS[\"China Geodetic Coordinate System 2000\", \r\n DATUM[\"China 2000\", \r\n SPHEROID[\"CGCS2000\", 6378137.0, 298.257222101, AUTHORITY[\"EPSG\",\"1024\"]], \r\n AUTHORITY[\"EPSG\",\"1043\"]], \r\n PRIMEM[\"Greenwich\", 0.0, AUTHORITY[\"EPSG\",\"8901\"]], \r\n UNIT[\"degree\", 0.017453292519943295], \r\n AXIS[\"lat\", NORTH], \r\n AXIS[\"lon\", EAST], \r\n AUTHORITY[\"EPSG\",\"4490\"]]",
665+
"minScale": "1:4037572.3458580696",
666+
"title": "maxzoom",
667+
"version": "2.4.3",
668+
"rootUrl": "http://fack:8190/iportal/"
669+
};
670+
const restmapjson = {
671+
"scale": 1.9900535920750805E-8,
672+
"prjCoordSys": {
673+
"epsgCode": 4490,
674+
},
675+
"minScale": 0,
676+
"visibleScales": [],
677+
"dpi": 96,
678+
"visibleScalesEnabled": false,
679+
680+
"center": {
681+
"x": 120.48255000000006,
682+
"y": 29.11280000000005
683+
},
684+
"name": "quxian",
685+
"bounds": {
686+
"top": 31.180900000000065,
687+
"left": 118.02310000000011,
688+
"bottom": 27.044700000000034,
689+
"leftBottom": {
690+
"x": 118.02310000000011,
691+
"y": 27.044700000000034
692+
},
693+
"right": 122.94200000000001,
694+
"rightTop": {
695+
"x": 122.94200000000001,
696+
"y": 31.180900000000065
697+
}
698+
}
699+
700+
};
701+
spyOn(FetchRequest, 'get').and.callFake((url) => {
702+
if (url.indexOf('map.json') > -1) {
703+
return Promise.resolve(new Response(JSON.stringify(mapJSON)));
704+
}
705+
if (url.indexOf('portal.json') > -1) {
706+
return Promise.resolve(new Response(JSON.stringify(portalConfig)));
707+
}
708+
if (url.indexOf('/quxian.json')> -1) {
709+
return Promise.resolve(new Response(JSON.stringify(restmapjson)));
710+
}
711+
console.log('FetchRequest', url);
712+
return Promise.resolve(new Response(JSON.stringify({})));
713+
});
714+
715+
var datavizWebmap = new WebMap(id, options);
716+
717+
datavizWebmap.on('mapcreatesucceeded', (data) => {
718+
try {
719+
expect(datavizWebmap.map.getMaxZoom()).toBe(23);
720+
expect(datavizWebmap.map.getStyle().layers.length).toBe(1);
721+
expect(datavizWebmap.map.getStyle().layers[0].maxzoom).toBe(24);
722+
done();
723+
} catch (error) {
724+
console.log(error);
725+
done();
726+
}
727+
});
728+
});
634729
});

test/tool/mock_mapboxgl_map.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ CRS.defaultWKTs = {
504504
};
505505
CRS.EPSG3857 = new CRS('EPSG:3857', [-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892]);
506506
CRS.EPSG4326 = new CRS('EPSG:4326', [-180, -90, 180, 90]);
507+
CRS.EPSG4490 = new CRS('EPSG:4490', [-180, -90, 180, 90]);
508+
507509

508510
function revertCRS() {
509511
keyCache.forEach((key) => {

0 commit comments

Comments
 (0)