Skip to content

Commit 8573a1b

Browse files
committed
【fix】栅格图层非4326投影bounds转换不正确导致出图空白; review by songym
1 parent c3195e5 commit 8573a1b

File tree

3 files changed

+232
-44
lines changed

3 files changed

+232
-44
lines changed

src/common/mapping/WebMapV2.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -778,24 +778,21 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
778778
}
779779
}
780780

781-
_createDynamicTiledLayer(layerInfo, addedCallback) {
781+
async _createDynamicTiledLayer(layerInfo, addedCallback) {
782782
const url = layerInfo.url;
783783
const layerId = layerInfo.layerID || layerInfo.name;
784784
const { minzoom, maxzoom } = layerInfo;
785-
this.getBounds(`${url}.json`, {
785+
const reqOptions = {
786786
withoutFormatSuffix: true,
787787
withCredentials: this.webMapService.handleWithCredentials('', url, false)
788-
}).then((res) => {
789-
let bounds = null;
790-
if (res && res.bounds) {
791-
bounds = [
792-
res.bounds.left,
793-
res.bounds.bottom,
794-
res.bounds.right,
795-
res.bounds.top
796-
];
797-
const epsgCode = res.prjCoordSys.epsgCode;
798-
if (epsgCode !== 4326) {
788+
};
789+
let res = await this.getBounds(`${url}.json`, reqOptions)
790+
let bounds = null;
791+
if (res && res.bounds) {
792+
bounds = this._getBoundList(res);
793+
const epsgCode = res.prjCoordSys.epsgCode;
794+
if (epsgCode !== 4326) {
795+
if (`EPSG:${epsgCode}` === this.baseProjection || this._mapInfo.baseLayer.url === url) {
799796
const [left, bottom] = this._unproject(
800797
[res.bounds.left, res.bounds.bottom]
801798
);
@@ -808,19 +805,22 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
808805
right,
809806
top
810807
];
808+
} else {
809+
res = await this.getBounds(`${url}.json?prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`, reqOptions)
810+
bounds = this._getBoundList(res);
811811
}
812812
}
813-
this._addBaselayer({
814-
url: [url],
815-
layerID: layerId,
816-
visibility: layerInfo.visible,
817-
minzoom,
818-
maxzoom,
819-
isIserver: true,
820-
bounds
821-
});
822-
addedCallback && addedCallback();
813+
}
814+
this._addBaselayer({
815+
url: [url],
816+
layerID: layerId,
817+
visibility: layerInfo.visible,
818+
minzoom,
819+
maxzoom,
820+
isIserver: true,
821+
bounds
823822
});
823+
addedCallback && addedCallback();
824824
}
825825

826826
_createWMSLayer(layerInfo, addedCallback) {
@@ -2870,6 +2870,17 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
28702870
return this._fetchRequest(baseUrl, 'json', options);
28712871
}
28722872

2873+
_getBoundList(res) {
2874+
if (res && res.bounds) {
2875+
return [
2876+
res.bounds.left,
2877+
res.bounds.bottom,
2878+
res.bounds.right,
2879+
res.bounds.top
2880+
];
2881+
}
2882+
}
2883+
28732884
_addLayer(layerInfo, parentLayerId = layerInfo.id, beforeId) {
28742885
const { id } = layerInfo;
28752886
if (this.map.getLayer(id)) {

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 139 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,9 @@ describe('mapboxgl_WebMapV2', () => {
312312
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
313313
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
314314
window.jsonsql = { query: () => [{}] };
315-
spyOn(Canvg, 'from').and.callFake((ctx, url, callback) =>
316-
Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
317-
);
315+
spyOn(Canvg, 'from').and.callFake((ctx, url, callback) =>
316+
Promise.resolve({ stop: jasmine.createSpy('stop'), start: jasmine.createSpy('start') })
317+
);
318318
window.geostats = class {
319319
setSerie() {}
320320
};
@@ -2840,10 +2840,7 @@ describe('mapboxgl_WebMapV2', () => {
28402840
expect(xyzLayer.id).toBe('2326底图');
28412841
expect(xyzLayer.type).toBe('raster');
28422842
expect(sources['2326底图'].bounds).toEqual([
2843-
113.77925526971052,
2844-
22.086139328930617,
2845-
114.53407583886273,
2846-
22.61831019233164
2843+
113.77925526971052, 22.086139328930617, 114.53407583886273, 22.61831019233164
28472844
]);
28482845
done();
28492846
});
@@ -3659,4 +3656,139 @@ describe('mapboxgl_WebMapV2', () => {
36593656
done();
36603657
});
36613658
});
3659+
3660+
it('overlay is TILE, baselayer is TILE bounds', (done) => {
3661+
const wkt4496 = `PROJCS["GK Zone 18 (CGCS2000)",GEOGCS["GCS_China_2000",DATUM["D_China_2000",SPHEROID["CGCS2000",6378137.0,298.257222101,AUTHORITY["EPSG","7044"]]],PRIMEM["Greenwich",0.0,AUTHORITY["EPSG","8901"]],UNIT["DEGREE",0.017453292519943295],AUTHORITY["EPSG","4490"]],PROJECTION["Transverse_Mercator",AUTHORITY["EPSG","9807"]],PARAMETER["False_Easting",1.85E7],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",105.0],PARAMETER["Latitude_Of_Origin",0.0],PARAMETER["Scale_Factor",1.0],UNIT["METER",1.0],AUTHORITY["EPSG","4496"]]`;
3662+
spyOn(FetchRequest, 'get').and.callFake((url) => {
3663+
if (url.indexOf('portal.json') > -1) {
3664+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
3665+
}
3666+
if (url.indexOf('123/map.json') > -1) {
3667+
return Promise.resolve(new Response(JSON.stringify(dynamicProjectionMapInfo)));
3668+
}
3669+
if (url.indexOf(`test.json?prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`) > -1) {
3670+
return Promise.resolve(
3671+
new Response(
3672+
JSON.stringify({
3673+
prjCoordSys: { epsgCode: 4326 },
3674+
bounds: {
3675+
top: 2.3755571276430945,
3676+
left: 113.5091647206238,
3677+
bottom: 2.087888705520514,
3678+
leftBottom: {
3679+
x: 113.5091647206238,
3680+
y: 2.087888705520514
3681+
},
3682+
right: 113.84235808224173,
3683+
rightTop: {
3684+
x: 113.84235808224173,
3685+
y: 2.3755571276430945
3686+
}
3687+
}
3688+
})
3689+
)
3690+
);
3691+
}
3692+
if (url.indexOf(`test.json`) > -1) {
3693+
return Promise.resolve(
3694+
new Response(
3695+
JSON.stringify({
3696+
prjCoordSys: { epsgCode: 4496 },
3697+
bounds: {
3698+
top: 262679.13362826034,
3699+
left: 25493.744181281887,
3700+
bottom: 230878.98887457885,
3701+
leftBottom: {
3702+
x: 25493.744181281887,
3703+
y: 230878.98887457885
3704+
},
3705+
right: 62548.98751319852,
3706+
rightTop: {
3707+
x: 62548.98751319852,
3708+
y: 262679.13362826034
3709+
}
3710+
}
3711+
})
3712+
)
3713+
);
3714+
}
3715+
if (url.indexOf(`China_Dark.json`) > -1) {
3716+
return Promise.resolve(
3717+
new Response(
3718+
JSON.stringify({
3719+
prjCoordSys: { epsgCode: -1 },
3720+
bounds: {
3721+
top: 20037508.342789087,
3722+
left: -20037508.342789248,
3723+
bottom: -25819498.513543323,
3724+
leftBottom: {
3725+
x: -20037508.342789248,
3726+
y: -25819498.513543323
3727+
},
3728+
right: 20037508.342789244,
3729+
rightTop: {
3730+
x: 20037508.342789244,
3731+
y: 20037508.342789087
3732+
}
3733+
}
3734+
})
3735+
)
3736+
);
3737+
}
3738+
if (url.indexOf(`china.json`) > -1) {
3739+
return Promise.resolve(
3740+
new Response(
3741+
JSON.stringify({
3742+
prjCoordSys: { epsgCode: 3857 },
3743+
bounds: {
3744+
top: 5127400.782113583,
3745+
left: 10607760.850223977,
3746+
bottom: 2755785.4693220854,
3747+
leftBottom: {
3748+
x: 10607760.850223977,
3749+
y: 2755785.4693220854
3750+
},
3751+
right: 12979376.163015474,
3752+
rightTop: {
3753+
x: 12979376.163015474,
3754+
y: 5127400.782113583
3755+
}
3756+
}
3757+
})
3758+
)
3759+
);
3760+
}
3761+
if (url.indexOf('prjCoordSys.wkt')) {
3762+
return Promise.resolve(new Response(wkt4496));
3763+
}
3764+
});
3765+
datavizWebmap = new WebMap('123', {
3766+
target: 'map',
3767+
serverUrl: 'http://fake/fakeiportal',
3768+
withCredentials: false
3769+
});
3770+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
3771+
const style = map.getStyle();
3772+
expect(map.getStyle().layers.length).toBe(3);
3773+
const expectedBaselayerBounds = [-180.00000000000006, -88, 180.00000000000003, 85.05112877980648];
3774+
const actualBaselayerBounds = style.sources['中国暗色地图'].bounds;
3775+
expect(actualBaselayerBounds.length).toBe(expectedBaselayerBounds.length);
3776+
actualBaselayerBounds.forEach((val, i) => {
3777+
expect(val).toBeCloseTo(expectedBaselayerBounds[i], 6);
3778+
});
3779+
const expectedOverlayer1Bounds = [95.29113702040888, 24.019508369205386, 116.5957198557339, 41.77544139596302];
3780+
const actualOverlayer1Bounds = style.sources.china.bounds;
3781+
expect(actualOverlayer1Bounds.length).toBe(expectedOverlayer1Bounds.length);
3782+
actualOverlayer1Bounds.forEach((val, i) => {
3783+
expect(val).toBeCloseTo(expectedOverlayer1Bounds[i], 6);
3784+
});
3785+
const expectedOverlayer2Bounds = [113.5091647206238, 2.087888705520514, 113.84235808224173, 2.3755571276430945];
3786+
const actualOverlayer2Bounds = style.sources.test.bounds;
3787+
expect(actualOverlayer2Bounds.length).toBe(expectedOverlayer2Bounds.length);
3788+
actualOverlayer2Bounds.forEach((val, i) => {
3789+
expect(val).toBeCloseTo(expectedOverlayer2Bounds[i], 6);
3790+
});
3791+
done();
3792+
});
3793+
});
36623794
});

test/resources/WebMapV5.js

Lines changed: 59 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)