Skip to content

Commit 724a801

Browse files
[fix]zxy底图2326投影问题 review by qiw
1 parent b2266f4 commit 724a801

File tree

2 files changed

+59
-33
lines changed

2 files changed

+59
-33
lines changed

src/common/mapping/WebMapV2.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
130130
extent: [extent.leftBottom.x, extent.leftBottom.y, extent.rightTop.x, extent.rightTop.y],
131131
wkt: this._getProjectionWKT(projection)
132132
};
133-
if (!crsManager.getCRS(epsgCode)) {
133+
if (!crsManager.getCRS(epsgCode) && baseLayer.layerType !== 'ZXY_TILE') {
134134
switch (baseLayer.layerType) {
135135
case 'MAPBOXSTYLE': {
136136
let url = baseLayer.dataSource.url;

test/mapboxgl/mapping/WebMapV2Spec.js

+58-32
Original file line numberDiff line numberDiff line change
@@ -1822,8 +1822,9 @@ describe('mapboxgl_WebMapV2', () => {
18221822
};
18231823
datavizWebmap = new WebMap({
18241824
...wmsLayer,
1825-
projection: 'PROJCS[\"Hong Kong 1980 Grid System\", \r\n GEOGCS[\"Hong Kong 1980\", \r\n DATUM[\"Hong Kong 1980\", \r\n SPHEROID[\"International 1924\", 6378388.0, 297.0, AUTHORITY[\"EPSG\",\"7022\"]], \r\n TOWGS84[-162.619, -276.959, -161.764, 0.067753, -2.243649, -1.158827, -1.094246], \r\n AUTHORITY[\"EPSG\",\"6611\"]], \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\",\"4611\"]], \r\n PROJECTION[\"Transverse_Mercator\", AUTHORITY[\"EPSG\",\"9807\"]], \r\n PARAMETER[\"central_meridian\", 114.17855555555556], \r\n PARAMETER[\"latitude_of_origin\", 22.312133333333335], \r\n PARAMETER[\"scale_factor\", 1.0], \r\n PARAMETER[\"false_easting\", 836694.05], \r\n PARAMETER[\"false_northing\", 819069.8], \r\n UNIT[\"m\", 1.0], \r\n AXIS[\"Northing\", NORTH], \r\n AXIS[\"Easting\", EAST], \r\n AUTHORITY[\"EPSG\",\"2326\"]]',
1826-
center: { x: 113.90326937827093,y: 22.285836066567555 },
1825+
projection:
1826+
'PROJCS["Hong Kong 1980 Grid System", \r\n GEOGCS["Hong Kong 1980", \r\n DATUM["Hong Kong 1980", \r\n SPHEROID["International 1924", 6378388.0, 297.0, AUTHORITY["EPSG","7022"]], \r\n TOWGS84[-162.619, -276.959, -161.764, 0.067753, -2.243649, -1.158827, -1.094246], \r\n AUTHORITY["EPSG","6611"]], \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","4611"]], \r\n PROJECTION["Transverse_Mercator", AUTHORITY["EPSG","9807"]], \r\n PARAMETER["central_meridian", 114.17855555555556], \r\n PARAMETER["latitude_of_origin", 22.312133333333335], \r\n PARAMETER["scale_factor", 1.0], \r\n PARAMETER["false_easting", 836694.05], \r\n PARAMETER["false_northing", 819069.8], \r\n UNIT["m", 1.0], \r\n AXIS["Northing", NORTH], \r\n AXIS["Easting", EAST], \r\n AUTHORITY["EPSG","2326"]]',
1827+
center: { x: 113.90326937827093, y: 22.285836066567555 },
18271828
layers: [
18281829
{
18291830
...wmsLayer.layers[0],
@@ -2096,7 +2097,7 @@ describe('mapboxgl_WebMapV2', () => {
20962097
return Promise.resolve(new Response(JSON.stringify({})));
20972098
});
20982099
const iportalServiceProxyUrl = 'http://localhost:8195/portalproxy';
2099-
const tileCustomRequestHeaders = { 'Authorization': 'test token' };
2100+
const tileCustomRequestHeaders = { Authorization: 'test token' };
21002101
datavizWebmap = new WebMap(vectorLayer_line, {
21012102
...commonOption,
21022103
iportalServiceProxyUrlPrefix: iportalServiceProxyUrl,
@@ -2808,6 +2809,34 @@ describe('mapboxgl_WebMapV2', () => {
28082809
done();
28092810
});
28102811
});
2812+
it('initial_xyzLayer jingjin 2326', (done) => {
2813+
spyOn(FetchRequest, 'get').and.callFake((url) => {
2814+
if (url.indexOf('map.json') > -1) {
2815+
return Promise.resolve(new Response(JSON.stringify(xyzLayer2326)));
2816+
} else if (url.indexOf('portal.json') > -1) {
2817+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
2818+
}
2819+
return Promise.resolve(new Response(JSON.stringify({})));
2820+
});
2821+
const map = {
2822+
...commonMap,
2823+
getCRS: () => {
2824+
return null;
2825+
}
2826+
};
2827+
datavizWebmap = new WebMap(id, {
2828+
server: server,
2829+
map
2830+
});
2831+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
2832+
const layers = map.getStyle().layers;
2833+
expect(layers.length).toBe(1);
2834+
const xyzLayer = layers[0];
2835+
expect(xyzLayer.id).toBe('2326底图');
2836+
expect(xyzLayer.type).toBe('raster');
2837+
done();
2838+
});
2839+
});
28112840
it('initial_mapboxstyleLayer', (done) => {
28122841
spyOn(FetchRequest, 'get').and.callFake((url) => {
28132842
if (url.indexOf('map.json') > -1) {
@@ -3336,7 +3365,7 @@ describe('mapboxgl_WebMapV2', () => {
33363365
it('updateOverlayLayer featureProjection', (done) => {
33373366
spyOn(FetchRequest, 'get').and.callFake((url) => {
33383367
if (url.indexOf('map.json') > -1) {
3339-
webmap_rangeLayer.layers.map(item => {
3368+
webmap_rangeLayer.layers.map((item) => {
33403369
item.projection = 'EPSG:3857';
33413370
});
33423371
return Promise.resolve(new Response(JSON.stringify(webmap_rangeLayer)));
@@ -3394,7 +3423,8 @@ describe('mapboxgl_WebMapV2', () => {
33943423
it('when uncommon crs was defined, dont set repeat', (done) => {
33953424
const mapInfo = JSON.parse(raster4490);
33963425
const epsgCode = 'EPSG:4214';
3397-
const wkt_4214 = 'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4214"]]';
3426+
const wkt_4214 =
3427+
'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4214"]]';
33983428
mapInfo.projection = wkt_4214;
33993429
spyOn(FetchRequest, 'get').and.callFake((url) => {
34003430
if (url.indexOf('portal.json') > -1) {
@@ -3475,14 +3505,11 @@ describe('mapboxgl_WebMapV2', () => {
34753505
});
34763506
const originCrs = mapboxgl.CRS.get(epsgCode);
34773507
const crsSetSpy = spyOn(mapboxgl.CRS, 'set').and.callThrough();
3478-
datavizWebmap = new WebMap(
3479-
'123',
3480-
{
3481-
target: 'map',
3482-
serverUrl: 'http://fake/fakeiportal',
3483-
withCredentials: false
3484-
}
3485-
);
3508+
datavizWebmap = new WebMap('123', {
3509+
target: 'map',
3510+
serverUrl: 'http://fake/fakeiportal',
3511+
withCredentials: false
3512+
});
34863513
datavizWebmap.once('mapcreatesucceeded', ({ map: map1 }) => {
34873514
expect(originCrs).toBeFalsy();
34883515
expect(mapboxgl.CRS.get(epsgCode)).toBeTruthy();
@@ -3512,7 +3539,8 @@ describe('mapboxgl_WebMapV2', () => {
35123539
const mapInfo = JSON.parse(raster4490);
35133540
const epsgCode = 'EPSG:4215';
35143541
mapInfo.projection = epsgCode;
3515-
const wkt_4215 = 'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4215"]]';
3542+
const wkt_4215 =
3543+
'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4215"]]';
35163544
spyOn(FetchRequest, 'get').and.callFake((url) => {
35173545
if (url.indexOf('portal.json') > -1) {
35183546
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
@@ -3559,14 +3587,11 @@ describe('mapboxgl_WebMapV2', () => {
35593587
});
35603588
const originCrs = mapboxgl.CRS.get(epsgCode);
35613589
const crsSetSpy = spyOn(mapboxgl.CRS, 'set').and.callThrough();
3562-
datavizWebmap = new WebMap(
3563-
'123',
3564-
{
3565-
target: 'map',
3566-
serverUrl: 'http://fake/fakeiportal',
3567-
withCredentials: false
3568-
}
3569-
);
3590+
datavizWebmap = new WebMap('123', {
3591+
target: 'map',
3592+
serverUrl: 'http://fake/fakeiportal',
3593+
withCredentials: false
3594+
});
35703595
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
35713596
expect(originCrs).toBeFalsy();
35723597
expect(mapboxgl.CRS.get(epsgCode)).toBeTruthy();
@@ -3582,7 +3607,8 @@ describe('mapboxgl_WebMapV2', () => {
35823607

35833608
it('when uncommon crs was defined, baselayer is MAPBOXSTYLE', (done) => {
35843609
const epsgCode = 'EPSG:4216';
3585-
const wkt_4216 = 'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4216"]]';
3610+
const wkt_4216 =
3611+
'GEOGCS["Beijing 1954",DATUM["Beijing_1954",SPHEROID["Krassowsky 1940",6378245,298.3],TOWGS84[15.8,-154.4,-82.3,0,0,0,0]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4216"]]';
35863612
const mapInfo = {
35873613
...webmap_MAPBOXSTYLE_Tile,
35883614
layers: [],
@@ -3602,22 +3628,22 @@ describe('mapboxgl_WebMapV2', () => {
36023628
});
36033629
const originCrs = mapboxgl.CRS.get(epsgCode);
36043630
const crsSetSpy = spyOn(mapboxgl.CRS, 'set').and.callThrough();
3605-
datavizWebmap = new WebMap(
3606-
'123',
3607-
{
3608-
target: 'map',
3609-
serverUrl: 'http://fake/fakeiportal',
3610-
withCredentials: false
3611-
}
3612-
);
3631+
datavizWebmap = new WebMap('123', {
3632+
target: 'map',
3633+
serverUrl: 'http://fake/fakeiportal',
3634+
withCredentials: false
3635+
});
36133636
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
36143637
expect(originCrs).toBeFalsy();
36153638
expect(mapboxgl.CRS.get(epsgCode)).toBeTruthy();
36163639
expect(mapboxgl.CRS.get(epsgCode)).toEqual(map.getCRS());
36173640
expect(crsSetSpy).toHaveBeenCalledTimes(2);
36183641
expect(map.getCRS().getEpsgCode()).toBe(epsgCode);
36193642
expect(map.getCRS().getWKT()).toBe(wkt_4216);
3620-
expect(map.getCRS().getOrigin()).toEqual([vectorTile_style.metadata.indexbounds[0], vectorTile_style.metadata.indexbounds[3]]);
3643+
expect(map.getCRS().getOrigin()).toEqual([
3644+
vectorTile_style.metadata.indexbounds[0],
3645+
vectorTile_style.metadata.indexbounds[3]
3646+
]);
36213647
expect(map.getStyle().layers.length).toBe(vectorTile_style.layers.length - 1);
36223648
done();
36233649
});

0 commit comments

Comments
 (0)