Skip to content

Commit 59746ba

Browse files
committed
【fix】ISVJ-7398 修复带有token的restmap和叠加的数据401问题
1 parent 4e6add6 commit 59746ba

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,12 +1392,13 @@ export class WebMap extends Observable {
13921392
withCredentials: this.withCredentials,
13931393
withoutFormatSuffix: true
13941394
};
1395+
let tempUrl = layerInfo.url;
13951396
if (layerInfo.url.indexOf("?token=") > -1) {
1396-
that.credentialKey = 'token';
1397-
that.credentialValue = layerInfo.credential = layerInfo.url.split("?token=")[1];
1397+
layerInfo.credential = { token: layerInfo.url.split("?token=")[1] };
13981398
layerInfo.url = layerInfo.url.split("?token=")[0];
13991399
}
1400-
return FetchRequest.get(that.getRequestUrl(`${layerInfo.url}.json`), null, options).then(function (response) {
1400+
let url = this.handleJSONSuffix(tempUrl);
1401+
return FetchRequest.get(that.getRequestUrl(url), null, options).then(function (response) {
14011402
return response.json();
14021403
}).then(async function (result) {
14031404
// layerInfo.projection = mapInfo.projection;
@@ -5163,4 +5164,16 @@ export class WebMap extends Observable {
51635164
}
51645165
return ['EPSG:-1000','EPSG:-1'].includes(projection);
51655166
}
5167+
handleJSONSuffix(url) {
5168+
if(!url.includes('.json')) {
5169+
if (url.includes('?')) {
5170+
let urlArr = url.split('?');
5171+
urlArr[0] = urlArr[0] + ".json";
5172+
url = urlArr.join('?');
5173+
} else {
5174+
url = url + ".json"
5175+
}
5176+
}
5177+
return url;
5178+
}
51665179
}

test/openlayers/mapping/WebMapSpec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,4 +1299,28 @@ describe('openlayers_WebMap', () => {
12991299
done();
13001300
}
13011301
});
1302+
1303+
it('createBaseLayer-SUPERMAP_REST-token', (done) => {
1304+
spyOn(FetchRequest, 'get').and.callFake((url, params, options) => {
1305+
if (url.indexOf('map.json') > -1) {
1306+
var mapJson = datavizWebMap_RestMap_token;
1307+
return Promise.resolve(new Response(mapJson));
1308+
} else if (url.indexOf('content.json') > -1) {
1309+
expect(url.indexOf('testtoken')).toBe(-1);
1310+
return Promise.resolve(new Response(geojsonData));
1311+
} else {
1312+
console.log(url)
1313+
expect(url.indexOf('testtoken')).not.toBe(-1);
1314+
return Promise.resolve()
1315+
}
1316+
});
1317+
var datavizWebmap = new WebMap(id, {successCallback, errorCallback, server: defaultServer });
1318+
function successCallback(map, mapInfo, layers, baseLayer){
1319+
expect(baseLayer.credential).toEqual({token: 'testtoken'});
1320+
done();
1321+
}
1322+
function errorCallback(error) {
1323+
console.log(error);
1324+
}
1325+
});
13021326
});

test/resources/WebMapV5.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy