Skip to content

Commit 70fbbee

Browse files
committed
【fix】ISVJ-11302; review by luox
1 parent 96f5fc0 commit 70fbbee

File tree

5 files changed

+208
-16
lines changed

5 files changed

+208
-16
lines changed

src/common/mapping/WebMapService.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ export class WebMapService {
803803
return this._getDatasetsInfo(serviceUrl, datasetName).then(info => {
804804
// 判断是否和底图坐标系一直
805805
if (info.epsgCode == baseProjection.split('EPSG:')[1]) {
806-
return FetchRequest.get(`${info.url}/tilefeature.mvt`)
806+
return FetchRequest.get(Util.urlPathAppend(info.url, '/tilefeature.mvt'))
807807
.then(function (response) {
808808
return response.json();
809809
})
@@ -881,7 +881,7 @@ export class WebMapService {
881881
_getDatasetsInfo(serviceUrl, datasetName) {
882882
return this._getDatasources(serviceUrl).then(datasourceName => {
883883
// 判断mvt服务是否可用
884-
let url = `${serviceUrl}/data/datasources/${datasourceName}/datasets/${datasetName}`;
884+
let url = Util.urlPathAppend(serviceUrl, `/data/datasources/${datasourceName}/datasets/${datasetName}`);
885885
const proxy = this.handleProxy();
886886
url = this.handleParentRes(url);
887887
return FetchRequest.get(url, null, {
@@ -905,7 +905,7 @@ export class WebMapService {
905905

906906
_getDatasources(url) {
907907
const proxy = this.handleProxy();
908-
let serviceUrl = `${url}/data/datasources.json`;
908+
let serviceUrl = Util.urlPathAppend(url, '/data/datasources.json');
909909
serviceUrl = this.handleParentRes(serviceUrl);
910910
return FetchRequest.get(serviceUrl, null, {
911911
withCredentials: this.handleWithCredentials(proxy, serviceUrl, false),
@@ -1154,7 +1154,7 @@ export class WebMapService {
11541154
_getTileLayerInfo(url, baseProjection) {
11551155
const proxy = this.handleProxy();
11561156
let epsgCode = baseProjection.split('EPSG:')[1];
1157-
let serviceUrl = `${url}/maps.json`;
1157+
let serviceUrl = Util.urlPathAppend(url, '/maps.json');
11581158
serviceUrl = this.handleParentRes(serviceUrl);
11591159
return FetchRequest.get(serviceUrl, null, {
11601160
withCredentials: this.handleWithCredentials(proxy, serviceUrl, this.withCredentials),
@@ -1168,7 +1168,7 @@ export class WebMapService {
11681168
if (mapInfo) {
11691169
mapInfo.forEach(info => {
11701170
let promise = FetchRequest.get(
1171-
`${info.path}.json?prjCoordSys=${JSON.stringify({ epsgCode: epsgCode })}`,
1171+
Util.urlAppend(Util.handleUrlSuffix(info.path, '.json'), `prjCoordSys=${JSON.stringify({ epsgCode: epsgCode })}`),
11721172
null,
11731173
{
11741174
withCredentials: this.withCredentials,

src/common/mapping/WebMapV2.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
137137
if (mapInfo.baseLayer && mapInfo.baseLayer.layerType === 'MAPBOXSTYLE') {
138138
let url = mapInfo.baseLayer.dataSource.url;
139139
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
140-
url += '/style.json';
140+
url = Util.urlPathAppend(url, '/style.json');
141141
}
142142
this.webMapService.getMapBoxStyle(url).then((res) => {
143143
if (res && res.metadata && res.metadata.indexbounds) {
@@ -156,14 +156,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
156156
});
157157
} else if (mapInfo.baseLayer && mapInfo.baseLayer.layerType === 'TILE') {
158158
// 获取地图的wkt
159-
this.getEpsgCodeWKT(`${mapInfo.baseLayer.url}/prjCoordSys.wkt`, {
159+
this.getEpsgCodeWKT(Util.urlPathAppend(mapInfo.baseLayer.url, '/prjCoordSys.wkt'), {
160160
withoutFormatSuffix: true,
161161
withCredentials: this.webMapService.handleWithCredentials('', mapInfo.baseLayer.url, false)
162162
}).then((res) => {
163163
if (!wkt) {
164164
wkt = res;
165165
}
166-
this.getBounds(`${mapInfo.baseLayer.url}.json`, {
166+
this.getBounds(Util.handleUrlSuffix(mapInfo.baseLayer.url, '.json'), {
167167
withoutFormatSuffix: true,
168168
withCredentials: this.webMapService.handleWithCredentials('', mapInfo.baseLayer.url, false)
169169
}).then((res) => {
@@ -347,7 +347,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
347347
_createMVTBaseLayer(layerInfo, addedCallback) {
348348
let url = layerInfo.dataSource.url;
349349
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
350-
url += '/style.json';
350+
url = Util.urlPathAppend(url, '/style.json');
351351
}
352352
const withoutFormatSuffix = url.indexOf('/restjsr/') === -1;
353353
this.webMapService
@@ -743,9 +743,15 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
743743
const url = layerInfo.url;
744744
const layerId = layerInfo.layerID || layerInfo.name;
745745
const { minzoom, maxzoom } = layerInfo;
746-
this.getBounds(`${url}.json`, {
746+
let requestUrl = url;
747+
if (layerInfo.credential && layerInfo.credential.token) {
748+
const token = layerInfo.credential.token;
749+
requestUrl = Util.urlAppend(requestUrl, `token=${token}`);
750+
}
751+
const boundsRequestUrl = Util.handleUrlSuffix(requestUrl, '.json');
752+
this.getBounds(boundsRequestUrl, {
747753
withoutFormatSuffix: true,
748-
withCredentials: this.webMapService.handleWithCredentials('', url, false)
754+
withCredentials: this.webMapService.handleWithCredentials('', requestUrl, false)
749755
}).then((res) => {
750756
let bounds = null;
751757
if (res && res.bounds) {
@@ -772,7 +778,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
772778
}
773779
}
774780
this._addBaselayer({
775-
url: [url],
781+
url: [requestUrl],
776782
layerID: layerId,
777783
visibility: layerInfo.visible,
778784
minzoom,
@@ -2779,7 +2785,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
27792785
height: 256
27802786
};
27812787

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

27842790
const tiandituUrl = url.replace('{layer}', layerType).replace('{proj}', tilematrixSet);
27852791
const tiandituUrlArr = [];
@@ -2793,7 +2799,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, DataF
27932799
if (isLabel) {
27942800
const labelLayer = layerLabelMap[layerType];
27952801
options.layer = labelLayer;
2796-
labelUrl += this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}';
2802+
labelUrl = Util.urlAppend(labelUrl, this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}');
27972803
labelUrl = labelUrl.replace('{layer}', labelLayer).replace('{proj}', tilematrixSet);
27982804
const labelUrlArr = [];
27992805
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: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,4 +3315,146 @@ describe('mapboxgl_WebMapV2', () => {
33153315
done();
33163316
});
33173317
});
3318+
3319+
it('overlay is TILE which carried credential token', (done) => {
3320+
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"]]`;
3321+
const nextMapInfo = {
3322+
...dynamicProjectionMapInfo,
3323+
layers: dynamicProjectionMapInfo.layers.map(item => {
3324+
return {
3325+
...item,
3326+
credential: {
3327+
"token": "pBRw08Vs3-vfgqDi76tpvOYKCnLYFZ35exKFMMFV5vQ-3CWn80_xIZ_rweYxOe9t3ot0ahD2Y5Uymh50-YeyzzQkel0Ong.."
3328+
}
3329+
}
3330+
})
3331+
};
3332+
spyOn(FetchRequest, 'get').and.callFake((url) => {
3333+
if (url.indexOf('portal.json') > -1) {
3334+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
3335+
}
3336+
if (url.indexOf('123/map.json') > -1) {
3337+
return Promise.resolve(new Response(JSON.stringify(nextMapInfo)));
3338+
}
3339+
if (url.indexOf(`prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`) > -1) {
3340+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3341+
return Promise.resolve(
3342+
new Response(
3343+
JSON.stringify({
3344+
prjCoordSys: { epsgCode: 4326 },
3345+
bounds: {
3346+
top: 2.3755571276430945,
3347+
left: 113.5091647206238,
3348+
bottom: 2.087888705520514,
3349+
leftBottom: {
3350+
x: 113.5091647206238,
3351+
y: 2.087888705520514
3352+
},
3353+
right: 113.84235808224173,
3354+
rightTop: {
3355+
x: 113.84235808224173,
3356+
y: 2.3755571276430945
3357+
}
3358+
}
3359+
})
3360+
)
3361+
);
3362+
}
3363+
if (url.indexOf(`test.json`) > -1) {
3364+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3365+
return Promise.resolve(
3366+
new Response(
3367+
JSON.stringify({
3368+
prjCoordSys: { epsgCode: 4496 },
3369+
bounds: {
3370+
top: 262679.13362826034,
3371+
left: 25493.744181281887,
3372+
bottom: 230878.98887457885,
3373+
leftBottom: {
3374+
x: 25493.744181281887,
3375+
y: 230878.98887457885
3376+
},
3377+
right: 62548.98751319852,
3378+
rightTop: {
3379+
x: 62548.98751319852,
3380+
y: 262679.13362826034
3381+
}
3382+
}
3383+
})
3384+
)
3385+
);
3386+
}
3387+
if (url.indexOf(`China_Dark.json`) > -1) {
3388+
return Promise.resolve(
3389+
new Response(
3390+
JSON.stringify({
3391+
prjCoordSys: { epsgCode: -1 },
3392+
bounds: {
3393+
top: 20037508.342789087,
3394+
left: -20037508.342789248,
3395+
bottom: -25819498.513543323,
3396+
leftBottom: {
3397+
x: -20037508.342789248,
3398+
y: -25819498.513543323
3399+
},
3400+
right: 20037508.342789244,
3401+
rightTop: {
3402+
x: 20037508.342789244,
3403+
y: 20037508.342789087
3404+
}
3405+
}
3406+
})
3407+
)
3408+
);
3409+
}
3410+
if (url.indexOf(`china.json`) > -1) {
3411+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3412+
return Promise.resolve(
3413+
new Response(
3414+
JSON.stringify({
3415+
prjCoordSys: { epsgCode: 3857 },
3416+
bounds: {
3417+
top: 5127400.782113583,
3418+
left: 10607760.850223977,
3419+
bottom: 2755785.4693220854,
3420+
leftBottom: {
3421+
x: 10607760.850223977,
3422+
y: 2755785.4693220854
3423+
},
3424+
right: 12979376.163015474,
3425+
rightTop: {
3426+
x: 12979376.163015474,
3427+
y: 5127400.782113583
3428+
}
3429+
}
3430+
})
3431+
)
3432+
);
3433+
}
3434+
if (url.indexOf('prjCoordSys.wkt')) {
3435+
return Promise.resolve(new Response(wkt4496));
3436+
}
3437+
});
3438+
datavizWebmap = new WebMap('123', {
3439+
target: 'map',
3440+
serverUrl: 'http://fake/fakeiportal',
3441+
withCredentials: false
3442+
});
3443+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
3444+
const style = map.getStyle();
3445+
expect(map.getStyle().layers.length).toBe(3);
3446+
const expectedBaselayerBounds = [-180.00000000000006, -88, 180.00000000000003, 85.05112877980648];
3447+
const actualBaselayerBounds = style.sources['中国暗色地图'].bounds;
3448+
expect(actualBaselayerBounds.length).toBe(expectedBaselayerBounds.length);
3449+
const expectedOverlayer1Bounds = [95.29113702040888, 24.019508369205386, 116.5957198557339, 41.77544139596302];
3450+
const actualOverlayer1Bounds = style.sources.china.bounds;
3451+
expect(actualOverlayer1Bounds.length).toBe(expectedOverlayer1Bounds.length);
3452+
expect(style.sources.china.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3453+
const expectedOverlayer2Bounds = [113.5091647206238, 2.087888705520514, 113.84235808224173, 2.3755571276430945];
3454+
const actualOverlayer2Bounds = style.sources.test.bounds;
3455+
expect(actualOverlayer2Bounds.length).toBe(expectedOverlayer2Bounds.length);
3456+
expect(style.sources.test.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3457+
done();
3458+
});
3459+
});
33183460
});

test/resources/WebMapV5.js

Lines changed: 45 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)