Skip to content

Commit

Permalink
【fix】wms130 bounds顺序跟投影轴顺序关联
Browse files Browse the repository at this point in the history
  • Loading branch information
songyumeng committed Dec 13, 2024
1 parent 1c99bb5 commit c722836
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/common/mapping/WebMapV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html. */
import cloneDeep from 'lodash.clonedeep';
import { getProjection, registerProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define';
import { ColorsPickerUtil } from '../util/ColorsPickerUtil';
import { Util } from '../commontypes/Util';
import { ArrayStatistic } from '../util/ArrayStatistic';
import { ColorsPickerUtil } from '../util/ColorsPickerUtil';
import { FetchRequest } from '../util/FetchRequest';
import { getProjection, registerProjection, toEpsgCode, transformCoodinates } from './utils/epsg-define';
import { SourceListModelV2 } from './utils/SourceListModelV2';
import { isSameRasterLayer, mergeFeatures } from './utils/util';

Expand Down Expand Up @@ -124,12 +124,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
this._mapInfo = mapInfo;
const { projection } = mapInfo;
let bounds, wkt;
this.baseProjection = toEpsgCode(projection);
let defaultWktValue = getProjection(this.baseProjection, this.specifiedProj4);

if (defaultWktValue) {
wkt = defaultWktValue;
if (projection.indexOf('EPSG') === 0) {
this.baseProjection = projection;
wkt = getProjection(projection, this.specifiedProj4);
} else {
this.baseProjection = toEpsgCode(projection);
wkt = projection;
}

if (!mapRepo.CRS.get(this.baseProjection)) {
if (mapInfo.baseLayer && mapInfo.baseLayer.layerType === 'MAPBOXSTYLE') {
let url = mapInfo.baseLayer.dataSource.url;
Expand Down Expand Up @@ -865,12 +867,17 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
width: 256,
height: 256
};
options.bbox = '{bbox}';
options.crs = this.baseProjection;
if (version === '1.3.0') {
options.bbox = this.baseProjection === 'EPSG:4326' ? '{bbox-wms-1.3.0}' : '{bbox-epsg-3857}';
options.crs = this.baseProjection;
} else {
options.bbox = '{bbox-epsg-3857}';
options.srs = this.baseProjection;
if (this.baseProjection === 'EPSG:4326') {
options.bbox = '{bbox-wms-1.3.0}';
} else {
const proj = getProjection(this.baseProjection, this.specifiedProj4);
if (proj.axis && proj.axis.indexOf('ne') === 0) {
options.bbox = '{bbox-wms-1.3.0}';
}
}
}
return Util.urlAppend(url, this._getParamString(options, url));
}
Expand Down
26 changes: 26 additions & 0 deletions test/mapboxgl/mapping/WebMapV2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,32 @@ describe('mapboxgl_WebMapV2', () => {
datavizWebmap.on('mapcreatesucceeded', callback);
});

it('add wmsLayer with 2326WKT and version is 1.3.0', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map-world/wms130') > -1) {
return Promise.resolve(new Response(wmsCapabilitiesTextWith130));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
const callback = function (data) {
expect(data).not.toBeUndefined();
expect(data.map.getSource('世界地图_Day').tiles[0].indexOf('{bbox-wms-1.3.0}')).toBeGreaterThan(-1);
done();
};
datavizWebmap = new WebMap({
...wmsLayer,
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\"]]',
center: { x: 113.90326937827093,y: 22.285836066567555 },
layers: [
{
...wmsLayer.layers[0],
url: 'http://fack/iserver/services/map-world/wms130/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day?'
}
]
});
datavizWebmap.on('mapcreatesucceeded', callback);
});

it('add wmtsLayer with correct url', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map-china400/wmts100') > -1) {
Expand Down
26 changes: 26 additions & 0 deletions test/maplibregl/mapping/WebMapV2Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,32 @@ describe('maplibregl_WebMapV2', () => {
datavizWebmap.on('mapcreatesucceeded', callback);
});

it('add wmsLayer with 2326WKT and version is 1.3.0', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map-world/wms130') > -1) {
return Promise.resolve(new Response(wmsCapabilitiesTextWith130));
}
return Promise.resolve(new Response(JSON.stringify({})));
});
const callback = function (data) {
expect(data).not.toBeUndefined();
expect(data.map.getSource('世界地图_Day').tiles[0].indexOf('{bbox-wms-1.3.0}')).toBeGreaterThan(-1);
done();
};
datavizWebmap = new WebMap({
...wmsLayer,
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\"]]',
center: { x: 113.90326937827093,y: 22.285836066567555 },
layers: [
{
...wmsLayer.layers[0],
url: 'http://fack/iserver/services/map-world/wms130/%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE_Day?'
}
]
});
datavizWebmap.on('mapcreatesucceeded', callback);
});

it('add wmtsLayer with correct url', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url) => {
if (url.indexOf('map-china400/wmts100') > -1) {
Expand Down

0 comments on commit c722836

Please sign in to comment.