File tree 2 files changed +25
-7
lines changed
2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,21 @@ function MapboxLayer(mapbox, index) {
27
27
this . source = null ;
28
28
this . layerType = null ;
29
29
this . below = null ;
30
+
31
+ // is layer currently visible
32
+ this . visible = false ;
30
33
}
31
34
32
35
var proto = MapboxLayer . prototype ;
33
36
34
37
proto . update = function update ( opts ) {
35
- if ( this . needsNewSource ( opts ) ) {
38
+ if ( ! this . visible ) {
39
+
40
+ // IMPORTANT: must create source before layer to not cause errors
41
+ this . updateSource ( opts ) ;
42
+ this . updateLayer ( opts ) ;
43
+ }
44
+ else if ( this . needsNewSource ( opts ) ) {
36
45
37
46
// IMPORTANT: must delete layer before source to not cause errors
38
47
this . updateLayer ( opts ) ;
@@ -43,6 +52,8 @@ proto.update = function update(opts) {
43
52
}
44
53
45
54
this . updateStyle ( opts ) ;
55
+
56
+ this . visible = isVisible ( opts ) ;
46
57
} ;
47
58
48
59
proto . needsNewSource = function ( opts ) {
@@ -209,10 +220,7 @@ function convertSourceOpts(opts) {
209
220
module . exports = function createMapboxLayer ( mapbox , index , opts ) {
210
221
var mapboxLayer = new MapboxLayer ( mapbox , index ) ;
211
222
212
- // IMPORTANT: must create source before layer to not cause errors
213
- mapboxLayer . updateSource ( opts ) ;
214
- mapboxLayer . updateLayer ( opts ) ;
215
- mapboxLayer . updateStyle ( opts ) ;
223
+ mapboxLayer . update ( opts ) ;
216
224
217
225
return mapboxLayer ;
218
226
} ;
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ describe('mapbox defaults', function() {
146
146
describe ( 'mapbox credentials' , function ( ) {
147
147
'use strict' ;
148
148
149
- if ( ! hasWebGLSupport ( 'scattermapbox hover ' ) ) return ;
149
+ if ( ! hasWebGLSupport ( 'mapbox credentials ' ) ) return ;
150
150
151
151
var dummyToken = 'asfdsa124331wersdsa1321q3' ;
152
152
var gd ;
@@ -195,7 +195,7 @@ describe('mapbox credentials', function() {
195
195
describe ( 'mapbox plots' , function ( ) {
196
196
'use strict' ;
197
197
198
- if ( ! hasWebGLSupport ( 'scattermapbox hover ' ) ) return ;
198
+ if ( ! hasWebGLSupport ( 'mapbox plots ' ) ) return ;
199
199
200
200
var mock = require ( '@mocks/mapbox_0.json' ) ,
201
201
gd ;
@@ -461,6 +461,16 @@ describe('mapbox plots', function() {
461
461
} ) . then ( function ( ) {
462
462
expect ( countVisibleLayers ( gd ) ) . toEqual ( 0 ) ;
463
463
464
+ return Plotly . relayout ( gd , 'mapbox.layers[0]' , { } ) ;
465
+ } ) . then ( function ( ) {
466
+ expect ( countVisibleLayers ( gd ) ) . toEqual ( 0 ) ;
467
+
468
+ // layer with no source are not drawn
469
+
470
+ return Plotly . relayout ( gd , 'mapbox.layers[0].source' , layer0 . source ) ;
471
+ } ) . then ( function ( ) {
472
+ expect ( countVisibleLayers ( gd ) ) . toEqual ( 1 ) ;
473
+
464
474
done ( ) ;
465
475
} ) ;
466
476
} ) ;
You can’t perform that action at this time.
0 commit comments