248
248
this . layersBySourceLayer = { } ;
249
249
this . _loadStyle ( style ) ;
250
250
}
251
+
251
252
_loadStyle ( style ) {
252
253
if ( Object . prototype . toString . call ( style ) == '[object Object]' ) {
253
254
this . _handleRelativeUrl ( style , this . baseUrl ) ;
397
398
return parts ? parts [ 1 ] + extension + ( parts . length > 2 ? parts [ 2 ] : '' ) : url + extension ;
398
399
}
399
400
400
- _handleRelativeUrl ( styles , baseUrl ) {
401
- if ( ! baseUrl ) {
402
- return styles ;
403
- }
404
- Object . keys ( styles ) . forEach ( ( fieldName ) => {
405
- if ( fieldName === 'sources' ) {
406
- Object . keys ( styles [ fieldName ] ) . forEach ( ( sourceName ) => {
407
- this . _handleRelativeUrl ( styles [ fieldName ] [ sourceName ] , baseUrl ) ;
408
- } )
409
- }
410
- if ( fieldName === 'sprite' || fieldName === 'glyphs' || fieldName === 'url' ) {
411
- if ( typeof styles [ fieldName ] === 'string' && ! CommonUtil . isAbsoluteURL ( styles [ fieldName ] ) ) {
412
- styles [ fieldName ] = CommonUtil . relative2absolute ( styles [ fieldName ] , baseUrl ) ;
413
- }
414
- }
415
- if ( fieldName === 'tiles' && Array . isArray ( styles [ fieldName ] ) ) {
416
- styles [ fieldName ] . forEach ( ( tile ) => {
417
- if ( ! CommonUtil . isAbsoluteURL ( tile ) ) {
418
- tile = CommonUtil . relative2absolute ( tile , baseUrl ) ;
419
- }
420
- } )
421
- }
422
- } )
423
- }
401
+ _handleRelativeUrl ( styles , url ) {
402
+ if ( ! url ) {
403
+ return styles ;
404
+ }
405
+ const baseUrl = url . split ( '?' ) [ 0 ] ;
406
+ const paramUrl = url . split ( '?' ) [ 1 ] || '' ;
407
+ Object . keys ( styles ) . forEach ( ( fieldName ) => {
408
+ if ( fieldName === 'sources' ) {
409
+ Object . keys ( styles [ fieldName ] ) . forEach ( ( sourceName ) => {
410
+ this . _handleRelativeUrl ( styles [ fieldName ] [ sourceName ] , url ) ;
411
+ } )
412
+ }
413
+ if ( fieldName === 'sprite' || fieldName === 'glyphs' || fieldName === 'url' ) {
414
+ if ( typeof styles [ fieldName ] === 'string' && ! CommonUtil . isAbsoluteURL ( styles [ fieldName ] ) ) {
415
+ styles [ fieldName ] = CommonUtil . relative2absolute ( styles [ fieldName ] , baseUrl ) ;
416
+ }
417
+ if ( paramUrl && ! styles [ fieldName ] . includes ( paramUrl ) ) {
418
+ styles [ fieldName ] = styles [ fieldName ] + ( paramUrl ? ( styles [ fieldName ] . includes ( '?' ) ? '&' + paramUrl : '?' + paramUrl ) : '' ) ;
419
+ }
420
+ }
421
+ if ( fieldName === 'tiles' && Array . isArray ( styles [ fieldName ] ) ) {
422
+ styles [ fieldName ] . forEach ( ( tile ) => {
423
+ if ( ! CommonUtil . isAbsoluteURL ( tile ) ) {
424
+ tile = CommonUtil . relative2absolute ( tile , baseUrl ) ;
425
+ }
426
+ if ( paramUrl && ! tile . includes ( paramUrl ) ) {
427
+ tile = tile + ( paramUrl ? ( styles [ fieldName ] . includes ( '?' ) ? '&' + paramUrl : '?' + paramUrl ) : '' ) ;
428
+ }
429
+ } )
430
+ }
431
+ } )
432
+ }
424
433
}
425
-
434
+
0 commit comments