@@ -41,7 +41,7 @@ function Mapbox(opts) {
41
41
// state variables used to infer how and what to update
42
42
this . map = null ;
43
43
this . accessToken = null ;
44
- this . styleUrl = null ;
44
+ this . styleObj = null ;
45
45
this . traceHash = { } ;
46
46
this . layerList = [ ] ;
47
47
}
@@ -64,7 +64,7 @@ proto.plot = function(calcData, fullLayout, promises) {
64
64
if ( self . map && ( opts . accesstoken !== self . accessToken ) ) {
65
65
self . map . remove ( ) ;
66
66
self . map = null ;
67
- self . styleUrl = null ;
67
+ self . styleObj = null ;
68
68
self . traceHash = [ ] ;
69
69
self . layerList = { } ;
70
70
}
@@ -90,16 +90,17 @@ proto.createMap = function(calcData, fullLayout, resolve, reject) {
90
90
gd = self . gd ,
91
91
opts = self . opts ;
92
92
93
- // mapbox doesn't have a way to get the current style URL; do it ourselves
94
- var styleUrl = self . styleUrl = convertStyleUrl ( opts . style ) ;
93
+ // store style id and URL or object
94
+ var styleObj = self . styleObj = getStyleObj ( opts . style ) ;
95
95
96
96
// store access token associated with this map
97
97
self . accessToken = opts . accesstoken ;
98
98
99
+ // create the map!
99
100
var map = self . map = new mapboxgl . Map ( {
100
101
container : self . div ,
101
102
102
- style : styleUrl ,
103
+ style : styleObj . style ,
103
104
center : convertCenter ( opts . center ) ,
104
105
zoom : opts . zoom ,
105
106
bearing : opts . bearing ,
@@ -172,11 +173,11 @@ proto.updateMap = function(calcData, fullLayout, resolve, reject) {
172
173
173
174
self . rejectOnError ( reject ) ;
174
175
175
- var styleUrl = convertStyleUrl ( self . opts . style ) ;
176
+ var styleObj = getStyleObj ( self . opts . style ) ;
176
177
177
- if ( self . styleUrl !== styleUrl ) {
178
- self . styleUrl = styleUrl ;
179
- map . setStyle ( styleUrl ) ;
178
+ if ( self . styleObj . id !== styleObj . id ) {
179
+ self . styleObj = styleObj ;
180
+ map . setStyle ( styleObj . style ) ;
180
181
181
182
map . style . once ( 'load' , function ( ) {
182
183
@@ -402,16 +403,32 @@ proto.getView = function() {
402
403
} ;
403
404
} ;
404
405
405
- function convertStyleUrl ( style ) {
406
- var styleValues = layoutAttributes . style . values ;
406
+ function getStyleObj ( val ) {
407
+ var styleValues = layoutAttributes . style . values ,
408
+ styleDflt = layoutAttributes . style . dflt ,
409
+ styleObj = { } ;
407
410
408
- // if style is part of the 'official' mapbox values,
409
- // add URL prefix and suffix
410
- if ( styleValues . indexOf ( style ) !== - 1 ) {
411
- return constants . styleUrlPrefix + style + '-' + constants . styleUrlSuffix ;
411
+ if ( Lib . isPlainObject ( val ) ) {
412
+ styleObj . id = val . id ;
413
+ styleObj . style = val ;
412
414
}
415
+ else if ( typeof val === 'string' ) {
416
+ styleObj . id = val ;
417
+ styleObj . style = ( styleValues . indexOf ( val ) !== - 1 ) ?
418
+ convertStyleVal ( val ) :
419
+ val ;
420
+ }
421
+ else {
422
+ styleObj . id = styleDflt ;
423
+ styleObj . style = convertStyleVal ( styleDflt ) ;
424
+ }
425
+
426
+ return styleObj ;
427
+ }
413
428
414
- return style ;
429
+ // if style is part of the 'official' mapbox values, add URL prefix and suffix
430
+ function convertStyleVal ( val ) {
431
+ return constants . styleUrlPrefix + val + '-' + constants . styleUrlSuffix ;
415
432
}
416
433
417
434
function convertCenter ( center ) {
0 commit comments