Skip to content

Commit e6ecdf4

Browse files
committed
【fix】ISVJ-11302; review by luox
1 parent 32ec9dd commit e6ecdf4

File tree

4 files changed

+172
-16
lines changed

4 files changed

+172
-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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
});
@@ -425,7 +425,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
425425
_createMVTBaseLayer(layerInfo, addedCallback) {
426426
let url = layerInfo.dataSource.url;
427427
if (url.indexOf('/restjsr/') > -1 && !/\/style\.json$/.test(url)) {
428-
url += '/style.json';
428+
url = Util.urlPathAppend(url, '/style.json');
429429
}
430430
const withoutFormatSuffix = url.indexOf('/restjsr/') === -1;
431431
this.webMapService
@@ -880,11 +880,17 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
880880
const url = layerInfo.url;
881881
const layerId = layerInfo.layerID || layerInfo.name;
882882
const { minzoom, maxzoom } = layerInfo;
883+
let requestUrl = url;
884+
if (layerInfo.credential && layerInfo.credential.token) {
885+
const token = layerInfo.credential.token;
886+
requestUrl = Util.urlAppend(requestUrl, `token=${token}`);
887+
}
883888
const reqOptions = {
884889
withoutFormatSuffix: true,
885-
withCredentials: this.webMapService.handleWithCredentials('', url, false)
890+
withCredentials: this.webMapService.handleWithCredentials('', requestUrl, false)
886891
};
887-
let res = await this.getBounds(`${url}.json`, reqOptions)
892+
const boundsRequestUrl = Util.handleUrlSuffix(requestUrl, '.json');
893+
let res = await this.getBounds(boundsRequestUrl, reqOptions)
888894
let bounds = null;
889895
if (res && res.bounds) {
890896
bounds = this._getBoundList(res);
@@ -904,13 +910,14 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
904910
top
905911
];
906912
} else {
907-
res = await this.getBounds(`${url}.json?prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`, reqOptions)
913+
const nextBoundsRequestUrl = Util.urlAppend(boundsRequestUrl, `prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`)
914+
res = await this.getBounds(nextBoundsRequestUrl, reqOptions)
908915
bounds = this._getBoundList(res);
909916
}
910917
}
911918
}
912919
this._addBaselayer({
913-
url: [url],
920+
url: [requestUrl],
914921
layerID: layerId,
915922
visibility: layerInfo.visible,
916923
minzoom,
@@ -2917,7 +2924,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
29172924
height: 256
29182925
};
29192926

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

29222929
const tiandituUrl = url.replace('{layer}', layerType).replace('{proj}', tilematrixSet);
29232930
const tiandituUrlArr = [];
@@ -2931,7 +2938,7 @@ export function createWebMapV2Extending(SuperClass, { MapManager, mapRepo, crsMa
29312938
if (isLabel) {
29322939
const labelLayer = layerLabelMap[layerType];
29332940
options.layer = labelLayer;
2934-
labelUrl += this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}';
2941+
labelUrl = Util.urlAppend(labelUrl, this._getParamString(options, labelUrl) + '&tilematrix={z}&tilerow={y}&tilecol={x}');
29352942
labelUrl = labelUrl.replace('{layer}', labelLayer).replace('{proj}', tilematrixSet);
29362943
const labelUrlArr = [];
29372944
for (let i = 0; i < 8; i++) {

test/mapboxgl/mapping/WebMapV22Spec.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,10 @@ describe('mapboxgl_WebMapV2_2', () => {
595595
datavizWebmap.on('mapcreatesucceeded', (data) => {
596596
try {
597597
expect(datavizWebmap.map.getStyle().layers.length).toBe(2);
598-
debugger;
599598
const originLayerInfo = datavizWebmap._handler._mapInfo.layers.find((layer) => {
600599
return layer.layerID === 'China';
601600
});
602601
originLayerInfo.layerType = 'mvt';
603-
debugger;
604602
datavizWebmap.updateOverlayLayer(
605603
{ id: 'China' },
606604
{

test/mapboxgl/mapping/WebMapV2Spec.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3874,6 +3874,157 @@ it('add rangeLayer last end === fieldValue', (done) => {
38743874
});
38753875
});
38763876

3877+
it('overlay is TILE which carried credential token', (done) => {
3878+
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"]]`;
3879+
const nextMapInfo = {
3880+
...dynamicProjectionMapInfo,
3881+
layers: dynamicProjectionMapInfo.layers.map(item => {
3882+
return {
3883+
...item,
3884+
credential: {
3885+
"token": "pBRw08Vs3-vfgqDi76tpvOYKCnLYFZ35exKFMMFV5vQ-3CWn80_xIZ_rweYxOe9t3ot0ahD2Y5Uymh50-YeyzzQkel0Ong.."
3886+
}
3887+
}
3888+
})
3889+
};
3890+
spyOn(FetchRequest, 'get').and.callFake((url) => {
3891+
if (url.indexOf('portal.json') > -1) {
3892+
return Promise.resolve(new Response(JSON.stringify(iportal_serviceProxy)));
3893+
}
3894+
if (url.indexOf('123/map.json') > -1) {
3895+
return Promise.resolve(new Response(JSON.stringify(nextMapInfo)));
3896+
}
3897+
if (url.indexOf(`prjCoordSys=${JSON.stringify({ epsgCode: 4326 })}`) > -1) {
3898+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3899+
return Promise.resolve(
3900+
new Response(
3901+
JSON.stringify({
3902+
prjCoordSys: { epsgCode: 4326 },
3903+
bounds: {
3904+
top: 2.3755571276430945,
3905+
left: 113.5091647206238,
3906+
bottom: 2.087888705520514,
3907+
leftBottom: {
3908+
x: 113.5091647206238,
3909+
y: 2.087888705520514
3910+
},
3911+
right: 113.84235808224173,
3912+
rightTop: {
3913+
x: 113.84235808224173,
3914+
y: 2.3755571276430945
3915+
}
3916+
}
3917+
})
3918+
)
3919+
);
3920+
}
3921+
if (url.indexOf(`test.json`) > -1) {
3922+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3923+
return Promise.resolve(
3924+
new Response(
3925+
JSON.stringify({
3926+
prjCoordSys: { epsgCode: 4496 },
3927+
bounds: {
3928+
top: 262679.13362826034,
3929+
left: 25493.744181281887,
3930+
bottom: 230878.98887457885,
3931+
leftBottom: {
3932+
x: 25493.744181281887,
3933+
y: 230878.98887457885
3934+
},
3935+
right: 62548.98751319852,
3936+
rightTop: {
3937+
x: 62548.98751319852,
3938+
y: 262679.13362826034
3939+
}
3940+
}
3941+
})
3942+
)
3943+
);
3944+
}
3945+
if (url.indexOf(`China_Dark.json`) > -1) {
3946+
return Promise.resolve(
3947+
new Response(
3948+
JSON.stringify({
3949+
prjCoordSys: { epsgCode: -1 },
3950+
bounds: {
3951+
top: 20037508.342789087,
3952+
left: -20037508.342789248,
3953+
bottom: -25819498.513543323,
3954+
leftBottom: {
3955+
x: -20037508.342789248,
3956+
y: -25819498.513543323
3957+
},
3958+
right: 20037508.342789244,
3959+
rightTop: {
3960+
x: 20037508.342789244,
3961+
y: 20037508.342789087
3962+
}
3963+
}
3964+
})
3965+
)
3966+
);
3967+
}
3968+
if (url.indexOf(`china.json`) > -1) {
3969+
expect(url).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
3970+
return Promise.resolve(
3971+
new Response(
3972+
JSON.stringify({
3973+
prjCoordSys: { epsgCode: 3857 },
3974+
bounds: {
3975+
top: 5127400.782113583,
3976+
left: 10607760.850223977,
3977+
bottom: 2755785.4693220854,
3978+
leftBottom: {
3979+
x: 10607760.850223977,
3980+
y: 2755785.4693220854
3981+
},
3982+
right: 12979376.163015474,
3983+
rightTop: {
3984+
x: 12979376.163015474,
3985+
y: 5127400.782113583
3986+
}
3987+
}
3988+
})
3989+
)
3990+
);
3991+
}
3992+
if (url.indexOf('prjCoordSys.wkt')) {
3993+
return Promise.resolve(new Response(wkt4496));
3994+
}
3995+
});
3996+
datavizWebmap = new WebMap('123', {
3997+
target: 'map',
3998+
serverUrl: 'http://fake/fakeiportal',
3999+
withCredentials: false
4000+
});
4001+
datavizWebmap.on('mapcreatesucceeded', ({ map }) => {
4002+
const style = map.getStyle();
4003+
expect(map.getStyle().layers.length).toBe(3);
4004+
const expectedBaselayerBounds = [-180.00000000000006, -88, 180.00000000000003, 85.05112877980648];
4005+
const actualBaselayerBounds = style.sources['中国暗色地图'].bounds;
4006+
expect(actualBaselayerBounds.length).toBe(expectedBaselayerBounds.length);
4007+
actualBaselayerBounds.forEach((val, i) => {
4008+
expect(val).toBeCloseTo(expectedBaselayerBounds[i], 6);
4009+
});
4010+
const expectedOverlayer1Bounds = [95.29113702040888, 24.019508369205386, 116.5957198557339, 41.77544139596302];
4011+
const actualOverlayer1Bounds = style.sources.china.bounds;
4012+
expect(actualOverlayer1Bounds.length).toBe(expectedOverlayer1Bounds.length);
4013+
actualOverlayer1Bounds.forEach((val, i) => {
4014+
expect(val).toBeCloseTo(expectedOverlayer1Bounds[i], 6);
4015+
});
4016+
expect(style.sources.china.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
4017+
const expectedOverlayer2Bounds = [113.5091647206238, 2.087888705520514, 113.84235808224173, 2.3755571276430945];
4018+
const actualOverlayer2Bounds = style.sources.test.bounds;
4019+
expect(actualOverlayer2Bounds.length).toBe(expectedOverlayer2Bounds.length);
4020+
actualOverlayer2Bounds.forEach((val, i) => {
4021+
expect(val).toBeCloseTo(expectedOverlayer2Bounds[i], 6);
4022+
});
4023+
expect(style.sources.test.tiles[0]).toContain(`token=${nextMapInfo.layers[0].credential.token}`);
4024+
done();
4025+
});
4026+
});
4027+
38774028
it('baselayer is ZXY_TILE, calc zoomBase with resolutions, minScale 0', (done) => {
38784029
spyOn(FetchRequest, 'get').and.callFake((url) => {
38794030
if (url.indexOf('portal.json') > -1) {

0 commit comments

Comments
 (0)