@@ -27,7 +27,8 @@ exports.idRegex = exports.attrRegex = Lib.counterRegex(MAPBOX);
27
27
28
28
var deprecationWarning = [
29
29
'mapbox subplots and traces are deprecated!' ,
30
- 'Please consider switching to `map` subplots and traces.'
30
+ 'Please consider switching to `map` subplots and traces.' ,
31
+ 'Learn more at: https://plotly.com/javascript/maplibre-migration/'
31
32
] . join ( ' ' ) ;
32
33
33
34
exports . attributes = {
@@ -52,7 +53,7 @@ exports.supplyLayoutDefaults = require('./layout_defaults');
52
53
var firstPlot = true ;
53
54
54
55
exports . plot = function plot ( gd ) {
55
- if ( firstPlot ) {
56
+ if ( firstPlot ) {
56
57
firstPlot = false ;
57
58
Lib . warn ( deprecationWarning ) ;
58
59
}
@@ -61,25 +62,25 @@ exports.plot = function plot(gd) {
61
62
var calcData = gd . calcdata ;
62
63
var mapboxIds = fullLayout . _subplots [ MAPBOX ] ;
63
64
64
- if ( mapboxgl . version !== constants . requiredVersion ) {
65
+ if ( mapboxgl . version !== constants . requiredVersion ) {
65
66
throw new Error ( constants . wrongVersionErrorMsg ) ;
66
67
}
67
68
68
69
var accessToken = findAccessToken ( gd , mapboxIds ) ;
69
70
mapboxgl . accessToken = accessToken ;
70
71
71
- for ( var i = 0 ; i < mapboxIds . length ; i ++ ) {
72
+ for ( var i = 0 ; i < mapboxIds . length ; i ++ ) {
72
73
var id = mapboxIds [ i ] ;
73
74
var subplotCalcData = getSubplotCalcData ( calcData , MAPBOX , id ) ;
74
75
var opts = fullLayout [ id ] ;
75
76
var mapbox = opts . _subplot ;
76
77
77
- if ( ! mapbox ) {
78
+ if ( ! mapbox ) {
78
79
mapbox = new Mapbox ( gd , id ) ;
79
80
fullLayout [ id ] . _subplot = mapbox ;
80
81
}
81
82
82
- if ( ! mapbox . viewInitial ) {
83
+ if ( ! mapbox . viewInitial ) {
83
84
mapbox . viewInitial = {
84
85
center : Lib . extendFlat ( { } , opts . center ) ,
85
86
zoom : opts . zoom ,
@@ -92,24 +93,24 @@ exports.plot = function plot(gd) {
92
93
}
93
94
} ;
94
95
95
- exports . clean = function ( newFullData , newFullLayout , oldFullData , oldFullLayout ) {
96
+ exports . clean = function ( newFullData , newFullLayout , oldFullData , oldFullLayout ) {
96
97
var oldMapboxKeys = oldFullLayout . _subplots [ MAPBOX ] || [ ] ;
97
98
98
- for ( var i = 0 ; i < oldMapboxKeys . length ; i ++ ) {
99
+ for ( var i = 0 ; i < oldMapboxKeys . length ; i ++ ) {
99
100
var oldMapboxKey = oldMapboxKeys [ i ] ;
100
101
101
- if ( ! newFullLayout [ oldMapboxKey ] && ! ! oldFullLayout [ oldMapboxKey ] . _subplot ) {
102
+ if ( ! newFullLayout [ oldMapboxKey ] && ! ! oldFullLayout [ oldMapboxKey ] . _subplot ) {
102
103
oldFullLayout [ oldMapboxKey ] . _subplot . destroy ( ) ;
103
104
}
104
105
}
105
106
} ;
106
107
107
- exports . toSVG = function ( gd ) {
108
+ exports . toSVG = function ( gd ) {
108
109
var fullLayout = gd . _fullLayout ;
109
110
var subplotIds = fullLayout . _subplots [ MAPBOX ] ;
110
111
var size = fullLayout . _size ;
111
112
112
- for ( var i = 0 ; i < subplotIds . length ; i ++ ) {
113
+ for ( var i = 0 ; i < subplotIds . length ; i ++ ) {
113
114
var opts = fullLayout [ subplotIds [ i ] ] ;
114
115
var domain = opts . domain ;
115
116
var mapbox = opts . _subplot ;
@@ -131,84 +132,84 @@ exports.toSVG = function(gd) {
131
132
132
133
// Append logo if visible
133
134
var hidden = subplotDiv . select ( '.mapboxgl-ctrl-logo' ) . node ( ) . offsetParent === null ;
134
- if ( ! hidden ) {
135
+ if ( ! hidden ) {
135
136
var logo = fullLayout . _glimages . append ( 'g' ) ;
136
137
logo . attr ( 'transform' , strTranslate ( size . l + size . w * domain . x [ 0 ] + 10 , size . t + size . h * ( 1 - domain . y [ 0 ] ) - 31 ) ) ;
137
138
logo . append ( 'path' )
138
- . attr ( 'd' , constants . mapboxLogo . path0 )
139
- . style ( {
140
- opacity : 0.9 ,
141
- fill : '#ffffff' ,
142
- 'enable-background' : 'new'
143
- } ) ;
139
+ . attr ( 'd' , constants . mapboxLogo . path0 )
140
+ . style ( {
141
+ opacity : 0.9 ,
142
+ fill : '#ffffff' ,
143
+ 'enable-background' : 'new'
144
+ } ) ;
144
145
145
146
logo . append ( 'path' )
146
- . attr ( 'd' , constants . mapboxLogo . path1 )
147
- . style ( 'opacity' , 0.35 )
148
- . style ( 'enable-background' , 'new' ) ;
147
+ . attr ( 'd' , constants . mapboxLogo . path1 )
148
+ . style ( 'opacity' , 0.35 )
149
+ . style ( 'enable-background' , 'new' ) ;
149
150
150
151
logo . append ( 'path' )
151
- . attr ( 'd' , constants . mapboxLogo . path2 )
152
- . style ( 'opacity' , 0.35 )
153
- . style ( 'enable-background' , 'new' ) ;
152
+ . attr ( 'd' , constants . mapboxLogo . path2 )
153
+ . style ( 'opacity' , 0.35 )
154
+ . style ( 'enable-background' , 'new' ) ;
154
155
155
156
logo . append ( 'polygon' )
156
- . attr ( 'points' , constants . mapboxLogo . polygon )
157
- . style ( {
158
- opacity : 0.9 ,
159
- fill : '#ffffff' ,
160
- 'enable-background' : 'new'
161
- } ) ;
157
+ . attr ( 'points' , constants . mapboxLogo . polygon )
158
+ . style ( {
159
+ opacity : 0.9 ,
160
+ fill : '#ffffff' ,
161
+ 'enable-background' : 'new'
162
+ } ) ;
162
163
}
163
164
164
165
// Add attributions
165
166
var attributions = subplotDiv
166
- . select ( '.mapboxgl-ctrl-attrib' ) . text ( )
167
- . replace ( 'Improve this map' , '' ) ;
167
+ . select ( '.mapboxgl-ctrl-attrib' ) . text ( )
168
+ . replace ( 'Improve this map' , '' ) ;
168
169
169
170
var attributionGroup = fullLayout . _glimages . append ( 'g' ) ;
170
171
171
172
var attributionText = attributionGroup . append ( 'text' ) ;
172
173
attributionText
173
- . text ( attributions )
174
- . classed ( 'static-attribution' , true )
175
- . attr ( {
176
- 'font-size' : 12 ,
177
- 'font-family' : 'Arial' ,
178
- color : 'rgba(0, 0, 0, 0.75)' ,
179
- 'text-anchor' : 'end' ,
180
- 'data-unformatted' : attributions
181
- } ) ;
174
+ . text ( attributions )
175
+ . classed ( 'static-attribution' , true )
176
+ . attr ( {
177
+ 'font-size' : 12 ,
178
+ 'font-family' : 'Arial' ,
179
+ color : 'rgba(0, 0, 0, 0.75)' ,
180
+ 'text-anchor' : 'end' ,
181
+ 'data-unformatted' : attributions
182
+ } ) ;
182
183
183
184
var bBox = Drawing . bBox ( attributionText . node ( ) ) ;
184
185
185
186
// Break into multiple lines twice larger than domain
186
187
var maxWidth = size . w * ( domain . x [ 1 ] - domain . x [ 0 ] ) ;
187
- if ( ( bBox . width > maxWidth / 2 ) ) {
188
+ if ( ( bBox . width > maxWidth / 2 ) ) {
188
189
var multilineAttributions = attributions . split ( '|' ) . join ( '<br>' ) ;
189
190
attributionText
190
- . text ( multilineAttributions )
191
- . attr ( 'data-unformatted' , multilineAttributions )
192
- . call ( svgTextUtils . convertToTspans , gd ) ;
191
+ . text ( multilineAttributions )
192
+ . attr ( 'data-unformatted' , multilineAttributions )
193
+ . call ( svgTextUtils . convertToTspans , gd ) ;
193
194
194
195
bBox = Drawing . bBox ( attributionText . node ( ) ) ;
195
196
}
196
197
attributionText . attr ( 'transform' , strTranslate ( - 3 , - bBox . height + 8 ) ) ;
197
198
198
199
// Draw white rectangle behind text
199
200
attributionGroup
200
- . insert ( 'rect' , '.static-attribution' )
201
- . attr ( {
202
- x : - bBox . width - 6 ,
203
- y : - bBox . height - 3 ,
204
- width : bBox . width + 6 ,
205
- height : bBox . height + 3 ,
206
- fill : 'rgba(255, 255, 255, 0.75)'
207
- } ) ;
201
+ . insert ( 'rect' , '.static-attribution' )
202
+ . attr ( {
203
+ x : - bBox . width - 6 ,
204
+ y : - bBox . height - 3 ,
205
+ width : bBox . width + 6 ,
206
+ height : bBox . height + 3 ,
207
+ fill : 'rgba(255, 255, 255, 0.75)'
208
+ } ) ;
208
209
209
210
// Scale down if larger than domain
210
211
var scaleRatio = 1 ;
211
- if ( ( bBox . width + 6 ) > maxWidth ) scaleRatio = maxWidth / ( bBox . width + 6 ) ;
212
+ if ( ( bBox . width + 6 ) > maxWidth ) scaleRatio = maxWidth / ( bBox . width + 6 ) ;
212
213
213
214
var offset = [ ( size . l + size . w * domain . x [ 1 ] ) , ( size . t + size . h * ( 1 - domain . y [ 0 ] ) ) ] ;
214
215
attributionGroup . attr ( 'transform' , strTranslate ( offset [ 0 ] , offset [ 1 ] ) + strScale ( scaleRatio ) ) ;
@@ -222,7 +223,7 @@ function findAccessToken(gd, mapboxIds) {
222
223
var context = gd . _context ;
223
224
224
225
// special case for Mapbox Atlas users
225
- if ( context . mapboxAccessToken === '' ) return '' ;
226
+ if ( context . mapboxAccessToken === '' ) return '' ;
226
227
227
228
var tokensUseful = [ ] ;
228
229
var tokensListed = [ ] ;
@@ -231,42 +232,42 @@ function findAccessToken(gd, mapboxIds) {
231
232
232
233
// Take the first token we find in a mapbox subplot.
233
234
// These default to the context value but may be overridden.
234
- for ( var i = 0 ; i < mapboxIds . length ; i ++ ) {
235
+ for ( var i = 0 ; i < mapboxIds . length ; i ++ ) {
235
236
var opts = fullLayout [ mapboxIds [ i ] ] ;
236
237
var token = opts . accesstoken ;
237
238
238
- if ( isStyleRequireAccessToken ( opts . style ) ) {
239
- if ( token ) {
239
+ if ( isStyleRequireAccessToken ( opts . style ) ) {
240
+ if ( token ) {
240
241
Lib . pushUnique ( tokensUseful , token ) ;
241
242
} else {
242
- if ( isStyleRequireAccessToken ( opts . _input . style ) ) {
243
+ if ( isStyleRequireAccessToken ( opts . _input . style ) ) {
243
244
Lib . error ( 'Uses Mapbox map style, but did not set an access token.' ) ;
244
245
hasOneSetMapboxStyle = true ;
245
246
}
246
247
wontWork = true ;
247
248
}
248
249
}
249
250
250
- if ( token ) {
251
+ if ( token ) {
251
252
Lib . pushUnique ( tokensListed , token ) ;
252
253
}
253
254
}
254
255
255
- if ( wontWork ) {
256
+ if ( wontWork ) {
256
257
var msg = hasOneSetMapboxStyle ?
257
258
constants . noAccessTokenErrorMsg :
258
259
constants . missingStyleErrorMsg ;
259
260
Lib . error ( msg ) ;
260
261
throw new Error ( msg ) ;
261
262
}
262
263
263
- if ( tokensUseful . length ) {
264
- if ( tokensUseful . length > 1 ) {
264
+ if ( tokensUseful . length ) {
265
+ if ( tokensUseful . length > 1 ) {
265
266
Lib . warn ( constants . multipleTokensErrorMsg ) ;
266
267
}
267
268
return tokensUseful [ 0 ] ;
268
269
} else {
269
- if ( tokensListed . length ) {
270
+ if ( tokensListed . length ) {
270
271
Lib . log ( [
271
272
'Listed mapbox access token(s)' , tokensListed . join ( ',' ) ,
272
273
'but did not use a Mapbox map style, ignoring token(s).'
@@ -284,11 +285,11 @@ function isStyleRequireAccessToken(s) {
284
285
) ;
285
286
}
286
287
287
- exports . updateFx = function ( gd ) {
288
+ exports . updateFx = function ( gd ) {
288
289
var fullLayout = gd . _fullLayout ;
289
290
var subplotIds = fullLayout . _subplots [ MAPBOX ] ;
290
291
291
- for ( var i = 0 ; i < subplotIds . length ; i ++ ) {
292
+ for ( var i = 0 ; i < subplotIds . length ; i ++ ) {
292
293
var subplotObj = fullLayout [ subplotIds [ i ] ] . _subplot ;
293
294
subplotObj . updateFx ( fullLayout ) ;
294
295
}
0 commit comments