Skip to content

Commit

Permalink
【fix】ISVJ-7398 修复带有token的restmap和叠加的数据401问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Dec 28, 2023
1 parent 0f3790f commit 460bd4b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/openlayers/mapping/WebMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1394,12 +1394,12 @@ export class WebMap extends Observable {
withCredentials: this.withCredentials,
withoutFormatSuffix: true
};
let tempUrl = layerInfo.url;
if (layerInfo.url.indexOf("?token=") > -1) {
that.credentialKey = 'token';
that.credentialValue = layerInfo.credential = layerInfo.url.split("?token=")[1];
layerInfo.credential = { token: layerInfo.url.split("?token=")[1] };
layerInfo.url = layerInfo.url.split("?token=")[0];
}
let url = this.handleJSONSuffix(layerInfo.url);
let url = this.handleJSONSuffix(tempUrl);
return FetchRequest.get(that.getRequestUrl(url), null, options).then(function (response) {
return response.json();
}).then(async function (result) {
Expand Down
23 changes: 23 additions & 0 deletions test/openlayers/mapping/WebMapSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,27 @@ describe('openlayers_WebMap', () => {
done();
}
});

it('createBaseLayer-SUPERMAP_REST-token', (done) => {
spyOn(FetchRequest, 'get').and.callFake((url, params, options) => {
if (url.indexOf('map.json') > -1) {
var mapJson = datavizWebMap_RestMap_token;
return Promise.resolve(new Response(mapJson));
} else if (url.indexOf('content.json') > -1) {
expect(url.indexOf('testtoken')).toBe(-1);
return Promise.resolve(new Response(geojsonData));
} else {
expect(url.indexOf('testtoken')).not.toBe(-1);
return Promise.resolve()
}
});
var datavizWebmap = new WebMap(id, {successCallback, errorCallback, server: defaultServer });
function successCallback(map, mapInfo, layers, baseLayer){
expect(baseLayer.credential).toEqual({token: 'testtoken'});
done();
}
function errorCallback(error) {
console.log(error);
}
});
});
2 changes: 2 additions & 0 deletions test/resources/WebMapV5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 460bd4b

Please sign in to comment.