@@ -765,8 +765,8 @@ export class WebMap extends Observable {
765
765
this . getScales ( baseLayer ) ;
766
766
}
767
767
}
768
-
769
-
768
+
769
+
770
770
if ( options . visibleExtent ) {
771
771
const view = this . map . getView ( ) ;
772
772
const resolution = view . getResolutionForExtent ( options . visibleExtent , this . map . getSize ( ) ) ;
@@ -4259,7 +4259,18 @@ export class WebMap extends Observable {
4259
4259
if ( this . isRestMapMapboxStyle ( layerInfo ) ) {
4260
4260
url = url . replace ( restMapMVTStr , '' )
4261
4261
}
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 , {
4263
4274
withCredentials : this . withCredentials ,
4264
4275
withoutFormatSuffix : true ,
4265
4276
headers : {
@@ -4295,7 +4306,17 @@ export class WebMap extends Observable {
4295
4306
if ( styleUrl . indexOf ( '/restjsr/' ) > - 1 ) {
4296
4307
styleUrl = `${ styleUrl } /style.json` ;
4297
4308
}
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 , {
4299
4320
withCredentials : this . withCredentials ,
4300
4321
withoutFormatSuffix : true ,
4301
4322
headers : {
@@ -4306,6 +4327,18 @@ export class WebMap extends Observable {
4306
4327
} ) . then ( styles => {
4307
4328
_this . _matchStyleObject ( styles ) ;
4308
4329
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
+
4309
4342
let newLayerInfo = {
4310
4343
url : url ,
4311
4344
sourceType : 'VECTOR_TILE' ,
0 commit comments