Skip to content

Commit 4536216

Browse files
committed
【fix】ISVJ-11302; review by luox
1 parent e675585 commit 4536216

File tree

4 files changed

+217
-16
lines changed

4 files changed

+217
-16
lines changed

src/common/mapping/WebMapService.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ export class WebMapService {
809809
return this._getDatasetsInfo(serviceUrl, datasetName).then(info => {
810810
// 判断是否和底图坐标系一直
811811
if (info.epsgCode == baseProjection.split('EPSG:')[1]) {
812-
return FetchRequest.get(`${info.url}/tilefeature.mvt`)
812+
return FetchRequest.get(Util.urlPathAppend(info.url, '/tilefeature.mvt'))
813813
.then(function (response) {
814814
return response.json();
815815
})
@@ -887,7 +887,7 @@ export class WebMapService {
887887
_getDatasetsInfo(serviceUrl, datasetName) {
888888
return this._getDatasources(serviceUrl).then(datasourceName => {
889889
// 判断mvt服务是否可用
890-
let url = `${serviceUrl}/data/datasources/${datasourceName}/datasets/${datasetName}`;
890+
let url = Util.urlPathAppend(serviceUrl, `/data/datasources/${datasourceName}/datasets/${datasetName}`);
891891
const proxy = this.handleProxy();
892892
url = this.handleParentRes(url);
893893
return FetchRequest.get(url, null, {
@@ -911,7 +911,7 @@ export class WebMapService {
911911

912912
_getDatasources(url) {
913913
const proxy = this.handleProxy();
914-
let serviceUrl = `${url}/data/datasources.json`;
914+
let serviceUrl = Util.urlPathAppend(url, '/data/datasources.json');
915915
serviceUrl = this.handleParentRes(serviceUrl);
916916
return FetchRequest.get(serviceUrl, null, {
917917
withCredentials: this.handleWithCredentials(proxy, serviceUrl, false),
@@ -1160,7 +1160,7 @@ export class WebMapService {
11601160
_getTileLayerInfo(url, baseProjection) {
11611161
const proxy = this.handleProxy();
11621162
let epsgCode = baseProjection.split('EPSG:')[1];
1163-
let serviceUrl = `${url}/maps.json`;
1163+
let serviceUrl = Util.urlPathAppend(url, '/maps.json');
11641164
serviceUrl = this.handleParentRes(serviceUrl);
11651165
return FetchRequest.get(serviceUrl, null, {
11661166
withCredentials: this.handleWithCredentials(proxy, serviceUrl, this.withCredentials),
@@ -1174,7 +1174,7 @@ export class WebMapService {
11741174
if (mapInfo) {
11751175
mapInfo.forEach(info => {
11761176
let promise = FetchRequest.get(
1177-
`${info.path}.json?prjCoordSys=${JSON.stringify({ epsgCode: epsgCode })}`,
1177+
Util.urlAppend(Util.handleUrlSuffix(info.path, '.json'), `prjCoordSys=${JSON.stringify({ epsgCode: epsgCode })}`),
11781178
null,
11791179
{
11801180
withCredentials: this.withCredentials,

src/common/mapping/WebMapV2.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
124124
}
125125

126126
async _registerMapCRS(mapInfo) {
127-
const { projection, extent, baseLayer = {} } = mapInfo;
127+
const { projection, extent = { leftBottom: {}, rightTop: {} }, baseLayer = {} } = mapInfo;
128128
const epsgCode = toEpsgCode(projection);
129129
let crs = {
130130
name: epsgCode,
@@ -136,7 +136,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
136136
case 'MAPBOXSTYLE': {
137137
let url = baseLayer.dataSource.url;
138138
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
139-
url += '/style.json';
139+
url = Util.urlPathAppend(url, '/style.json');
140140
}
141141
const res = await this.webMapService.getMapBoxStyle(url);
142142
if (res && res.metadata && res.metadata.indexbounds) {
@@ -147,7 +147,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
147147
case 'TILE': {
148148
// 获取地图的wkt
149149
if (!crs.wkt) {
150-
crs.wkt = await this.getEpsgCodeWKT(`${baseLayer.url}/prjCoordSys.wkt`, {
150+
crs.wkt = await this.getEpsgCodeWKT(Util.urlPathAppend(baseLayer.url, '/prjCoordSys.wkt'), {
151151
withoutFormatSuffix: true,
152152
withCredentials: this.webMapService.handleWithCredentials('', baseLayer.url, false)
153153
});
@@ -398,7 +398,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
398398
_createMVTBaseLayer(layerInfo, addedCallback) {
399399
let url = layerInfo.dataSource.url;
400400
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
401-
url += '/style.json';
401+
url = Util.urlPathAppend(url, '/style.json');
402402
}
403403
const withoutFormatSuffix = url.indexOf('/restjsr/') === -1;
404404
this.webMapService
@@ -853,11 +853,17 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
853853
const url = layerInfo.url;
854854
const layerId = layerInfo.layerID || layerInfo.name;
855855
const { minzoom, maxzoom } = layerInfo;
856+
let requestUrl = url;
857+
if (layerInfo.credential && layerInfo.credential.token) {
858+
const token = layerInfo.credential.token;
859+
requestUrl = Util.urlAppend(requestUrl, `token=${token}`);
860+
}
856861
const reqOptions = {
857862
withoutFormatSuffix: true,
858-
withCredentials: this.webMapService.handleWithCredentials('', url, false)
863+
withCredentials: this.webMapService.handleWithCredentials('', requestUrl, false)
859864
};
860-
let res = await this.getBounds(`${url}.json`, reqOptions)
865+
const boundsRequestUrl = Util.handleUrlSuffix(requestUrl, '.json');
866+
let res = await this.getBounds(boundsRequestUrl, reqOptions)
861867
let bounds = null;
862868
if (res && res.bounds) {
863869
bounds = this._getBoundList(res);
@@ -877,13 +883,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
877883
top
878884
];
879885
} else {
880-
res = await this.getBounds(`${url}.json?prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`, reqOptions)
886+
const nextBoundsRequestUrl = Util.urlAppend(boundsRequestUrl, `prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`)
887+
res = await this.getBounds(nextBoundsRequestUrl, reqOptions)
881888
bounds = this._getBoundList(res);
882889
}
883890
}
884891
}
885892
this._addBaselayer({
886-
url: [url],
893+
url: [requestUrl],
887894
layerID: layerId,
888895
visibility: layerInfo.visible,
889896
minzoom,
@@ -2890,7 +2897,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
28902897
height: 256
28912898
};
28922899

2893-
url += this._getParamString(options, url) + '&tilematrix={z}&tilerow={y}&tilecol={x}';
2900+
url = Util.urlAppend(url, this._getParamString(options, url) + '&tilematrix={z}&tilerow={y}&tilecol={x}')
28942901

28952902
const tiandituUrl = url.replace('{layer}', layerType).replace('{proj}', tilematrixSet);
28962903
const tiandituUrlArr = [];
@@ -2904,7 +2911,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
29042911
if (isLabel) {
29052912
const labelLayer = layerLabelMap[layerType];
29062913
options.layer = labelLayer;
2907-
labelUrl += this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}';
2914+
labelUrl = Util.urlAppend(labelUrl, this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}');
29082915
labelUrl = labelUrl.replace('{layer}', labelLayer).replace('{proj}', tilematrixSet);
29092916
const labelUrlArr = [];
29102917
for (let i = 0; i < 8; i++) {

test/common/mapping/WebMapServiceSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe('WebMapServiceSpec.js', () => {
434434
if (url.includes('/web/datas/123')) {
435435
return Promise.resolve(new Response(JSON.stringify(result1)));
436436
}
437-
if (url.includes('/data/datasources/captial/datasets/test?parentResType=MAP&parentResId=123/tilefeature.mvt')) {
437+
if (url.includes('/data/datasources/captial/datasets/test/tilefeature.mvt?parentResType=MAP&parentResId=123')) {
438438
return Promise.resolve(new Response(JSON.stringify(result2)));
439439
}
440440
if (url.includes('/data/datasources/captial/datasets/test?parentResType=MAP&parentResId=123')) {

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,6 +3880,157 @@ describe('mapboxgl_WebMapV2', () => {
38803880
});
38813881
});
38823882

3883+
it('overlay is TILE which carried credential token', (done) => {
3884+
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"]]`;
3885+
const nextMapInfo = {
3886+
...dynamicProjectionMapInfo,
3887+
layers: dynamicProjectionMapInfo.layers.map(item => {
3888+
return {
3889+
...item,
3890+
credential: {
3891+
"token": "pBRw08Vs3-vfgqDi76tpvOYKCnLYFZ35exKFMMFV5vQ-3CWn80_xIZ_rweYxOe9t3ot0ahD2Y5Uymh50-YeyzzQkel0Ong.."
3892+
}
3893+
}
3894+
})
3895+
};
3896+
spyOn(FetchRequest, 'get').and.callFake((url) => {
3897+
if (url.indexOf('portal.json') > -1) {
3898+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
3899+
}
3900+
if (url.indexOf('123/map.json') > -1) {
3901+
return Promise.resolve(new Response(JSON.stringify(nextMapInfo)));
3902+
}
3903+
if (url.indexOf(`prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`) > -1) {
3904+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3905+
return Promise.resolve(
3906+
new Response(
3907+
JSON.stringify({
3908+
prjCoordSys: { epsgCode: 4326 },
3909+
bounds: {
3910+
top: 2.3755571276430945,
3911+
left: 113.5091647206238,
3912+
bottom: 2.087888705520514,
3913+
leftBottom: {
3914+
x: 113.5091647206238,
3915+
y: 2.087888705520514
3916+
},
3917+
right: 113.84235808224173,
3918+
rightTop: {
3919+
x: 113.84235808224173,
3920+
y: 2.3755571276430945
3921+
}
3922+
}
3923+
})
3924+
)
3925+
);
3926+
}
3927+
if (url.indexOf(`test.json`) > -1) {
3928+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3929+
return Promise.resolve(
3930+
new Response(
3931+
JSON.stringify({
3932+
prjCoordSys: { epsgCode: 4496 },
3933+
bounds: {
3934+
top: 262679.13362826034,
3935+
left: 25493.744181281887,
3936+
bottom: 230878.98887457885,
3937+
leftBottom: {
3938+
x: 25493.744181281887,
3939+
y: 230878.98887457885
3940+
},
3941+
right: 62548.98751319852,
3942+
rightTop: {
3943+
x: 62548.98751319852,
3944+
y: 262679.13362826034
3945+
}
3946+
}
3947+
})
3948+
)
3949+
);
3950+
}
3951+
if (url.indexOf(`China_Dark.json`) > -1) {
3952+
return Promise.resolve(
3953+
new Response(
3954+
JSON.stringify({
3955+
prjCoordSys: { epsgCode: -1 },
3956+
bounds: {
3957+
top: 20037508.342789087,
3958+
left: -20037508.342789248,
3959+
bottom: -25819498.513543323,
3960+
leftBottom: {
3961+
x: -20037508.342789248,
3962+
y: -25819498.513543323
3963+
},
3964+
right: 20037508.342789244,
3965+
rightTop: {
3966+
x: 20037508.342789244,
3967+
y: 20037508.342789087
3968+
}
3969+
}
3970+
})
3971+
)
3972+
);
3973+
}
3974+
if (url.indexOf(`china.json`) > -1) {
3975+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3976+
return Promise.resolve(
3977+
new Response(
3978+
JSON.stringify({
3979+
prjCoordSys: { epsgCode: 3857 },
3980+
bounds: {
3981+
top: 5127400.782113583,
3982+
left: 10607760.850223977,
3983+
bottom: 2755785.4693220854,
3984+
leftBottom: {
3985+
x: 10607760.850223977,
3986+
y: 2755785.4693220854
3987+
},
3988+
right: 12979376.163015474,
3989+
rightTop: {
3990+
x: 12979376.163015474,
3991+
y: 5127400.782113583
3992+
}
3993+
}
3994+
})
3995+
)
3996+
);
3997+
}
3998+
if (url.indexOf('prjCoordSys.wkt')) {
3999+
return Promise.resolve(new Response(wkt4496));
4000+
}
4001+
});
4002+
datavizWebmap = new WebMap('123', {
4003+
target: 'map',
4004+
serverUrl: 'http://fake/fakeiportal',
4005+
withCredentials: false
4006+
});
4007+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
4008+
const style = map.getStyle();
4009+
expect(map.getStyle().layers.length).toBe(3);
4010+
const expectedBaselayerBounds = [-180.00000000000006, -88, 180.00000000000003, 85.05112877980648];
4011+
const actualBaselayerBounds = style.sources['中国暗色地图'].bounds;
4012+
expect(actualBaselayerBounds.length).toBe(expectedBaselayerBounds.length);
4013+
actualBaselayerBounds.forEach((val, i) => {
4014+
expect(val).toBeCloseTo(expectedBaselayerBounds[i], 6);
4015+
});
4016+
const expectedOverlayer1Bounds = [95.29113702040888, 24.019508369205386, 116.5957198557339, 41.77544139596302];
4017+
const actualOverlayer1Bounds = style.sources.china.bounds;
4018+
expect(actualOverlayer1Bounds.length).toBe(expectedOverlayer1Bounds.length);
4019+
actualOverlayer1Bounds.forEach((val, i) => {
4020+
expect(val).toBeCloseTo(expectedOverlayer1Bounds[i], 6);
4021+
});
4022+
expect(style.sources.china.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
4023+
const expectedOverlayer2Bounds = [113.5091647206238, 2.087888705520514, 113.84235808224173, 2.3755571276430945];
4024+
const actualOverlayer2Bounds = style.sources.test.bounds;
4025+
expect(actualOverlayer2Bounds.length).toBe(expectedOverlayer2Bounds.length);
4026+
actualOverlayer2Bounds.forEach((val, i) => {
4027+
expect(val).toBeCloseTo(expectedOverlayer2Bounds[i], 6);
4028+
});
4029+
expect(style.sources.test.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
4030+
done();
4031+
});
4032+
});
4033+
38834034
it('baselayer is ZXY_TILE, calc zoomBase with resolutions, minScale 0', (done) => {
38844035
spyOn(FetchRequest, 'get').and.callFake((url) => {
38854036
if (url.indexOf('portal.json') > -1) {
@@ -4127,4 +4278,47 @@ describe('mapboxgl_WebMapV2', () => {
41274278
done();
41284279
});
41294280
});
4281+
4282+
it('baselayer is MAPBOXSTYLE when mapInfo has no extent', (done) => {
4283+
const mapInfo = {
4284+
"maxScale": "1:144447.92746805",
4285+
"baseLayer": {
4286+
"layerType": "MAPBOXSTYLE",
4287+
"name": "Capital@World33font",
4288+
"dataSource": {
4289+
"type": "EXTERNAL",
4290+
"url": "http://localhost:8195/portalproxy/ad4c697aec15c20c/iserver/services/map-mvt-CapitalWorld33font/restjsr/v1/vectortile/maps/Capital%40World33font"
4291+
}
4292+
},
4293+
"projection": "EPSG:4326",
4294+
"minScale": "1:591658710.909131",
4295+
"title": "Capital@World33font",
4296+
"version": "2.3.0",
4297+
}
4298+
spyOn(FetchRequest, 'get').and.callFake((url) => {
4299+
if (url.indexOf('portal.json') > -1) {
4300+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
4301+
}
4302+
if (url.indexOf('123/map.json') > -1) {
4303+
return Promise.resolve(
4304+
new Response(
4305+
JSON.stringify(mapInfo)
4306+
)
4307+
);
4308+
}
4309+
if (url.indexOf('/style.json')) {
4310+
return Promise.resolve(new Response(JSON.stringify(vectorTile_style)));
4311+
}
4312+
return Promise.resolve(new Response(JSON.stringify({})));
4313+
});
4314+
datavizWebmap = new WebMap('123', {
4315+
target: 'map',
4316+
serverUrl: 'http://fake/fakeiportal',
4317+
withCredentials: false
4318+
});
4319+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
4320+
expect(map).not.toBeUndefined();
4321+
done();
4322+
});
4323+
});
41304324
});

0 commit comments

Comments
 (0)