Skip to content

Commit 3249ccf

Browse files
committed
[feature] ol webmap 支持 rest-vectortile图层携带令牌
review by zhaoq
1 parent 563c2ec commit 3249ccf

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/openlayers/mapping/WebMap.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,8 +765,8 @@ export class WebMap extends Observable {
765765
this.getScales(baseLayer);
766766
}
767767
}
768-
769-
768+
769+
770770
if (options.visibleExtent) {
771771
const view = this.map.getView();
772772
const resolution = view.getResolutionForExtent(options.visibleExtent, this.map.getSize());
@@ -4259,7 +4259,18 @@ export class WebMap extends Observable {
42594259
if (this.isRestMapMapboxStyle(layerInfo)) {
42604260
url = url.replace(restMapMVTStr, '')
42614261
}
4262-
return FetchRequest.get(this.getRequestUrl(url + '.json'), null, {
4262+
url = this.getRequestUrl(url + '.json')
4263+
4264+
let credential = layerInfo.credential;
4265+
let credentialValue,keyfix;
4266+
//携带令牌(restmap用的首字母大写,但是这里要用小写)
4267+
if (credential) {
4268+
keyfix = Object.keys(credential)[0]
4269+
credentialValue = credential[keyfix];
4270+
url = `${url}?${keyfix}=${credentialValue}`;
4271+
}
4272+
4273+
return FetchRequest.get(url, null, {
42634274
withCredentials: this.withCredentials,
42644275
withoutFormatSuffix: true,
42654276
headers: {
@@ -4295,7 +4306,17 @@ export class WebMap extends Observable {
42954306
if (styleUrl.indexOf('/restjsr/') > -1) {
42964307
styleUrl = `${styleUrl}/style.json`;
42974308
}
4298-
return FetchRequest.get(this.getRequestUrl(styleUrl), null, {
4309+
styleUrl = this.getRequestUrl(styleUrl)
4310+
let credential = layerInfo.credential;
4311+
//携带令牌(restmap用的首字母大写,但是这里要用小写)
4312+
let credentialValue, keyfix;
4313+
if (credential) {
4314+
keyfix = Object.keys(credential)[0]
4315+
credentialValue = credential[keyfix];
4316+
styleUrl = `${styleUrl}?${keyfix}=${credentialValue}`;
4317+
}
4318+
4319+
return FetchRequest.get(styleUrl, null, {
42994320
withCredentials: this.withCredentials,
43004321
withoutFormatSuffix: true,
43014322
headers: {
@@ -4306,6 +4327,18 @@ export class WebMap extends Observable {
43064327
}).then(styles => {
43074328
_this._matchStyleObject(styles);
43084329
let bounds = layerInfo.bounds;
4330+
// 处理携带令牌的情况
4331+
if (credentialValue) {
4332+
styles.sprite = `${styles.sprite}?${keyfix}=${credentialValue}`;
4333+
let sources = styles.sources;
4334+
let sourcesNames = Object.keys(sources);
4335+
sourcesNames.forEach(function (sourceName) {
4336+
styles.sources[sourceName].tiles.forEach(function (tiles, i) {
4337+
styles.sources[sourceName].tiles[i] = `${tiles}?${keyfix}=${credentialValue}`
4338+
})
4339+
})
4340+
}
4341+
43094342
let newLayerInfo = {
43104343
url: url,
43114344
sourceType: 'VECTOR_TILE',

0 commit comments

Comments
 (0)