File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Expand file tree Collapse file tree 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) {
2727 this . source = null ;
2828 this . layerType = null ;
2929 this . below = null ;
30+
31+ // is layer currently visible
32+ this . visible = false ;
3033}
3134
3235var proto = MapboxLayer . prototype ;
3336
3437proto . 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 ) ) {
3645
3746 // IMPORTANT: must delete layer before source to not cause errors
3847 this . updateLayer ( opts ) ;
@@ -43,6 +52,8 @@ proto.update = function update(opts) {
4352 }
4453
4554 this . updateStyle ( opts ) ;
55+
56+ this . visible = isVisible ( opts ) ;
4657} ;
4758
4859proto . needsNewSource = function ( opts ) {
@@ -209,10 +220,7 @@ function convertSourceOpts(opts) {
209220module . exports = function createMapboxLayer ( mapbox , index , opts ) {
210221 var mapboxLayer = new MapboxLayer ( mapbox , index ) ;
211222
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 ) ;
216224
217225 return mapboxLayer ;
218226} ;
Original file line number Diff line number Diff line change @@ -146,7 +146,7 @@ describe('mapbox defaults', function() {
146146describe ( 'mapbox credentials' , function ( ) {
147147 'use strict' ;
148148
149- if ( ! hasWebGLSupport ( 'scattermapbox hover ' ) ) return ;
149+ if ( ! hasWebGLSupport ( 'mapbox credentials ' ) ) return ;
150150
151151 var dummyToken = 'asfdsa124331wersdsa1321q3' ;
152152 var gd ;
@@ -195,7 +195,7 @@ describe('mapbox credentials', function() {
195195describe ( 'mapbox plots' , function ( ) {
196196 'use strict' ;
197197
198- if ( ! hasWebGLSupport ( 'scattermapbox hover ' ) ) return ;
198+ if ( ! hasWebGLSupport ( 'mapbox plots ' ) ) return ;
199199
200200 var mock = require ( '@mocks/mapbox_0.json' ) ,
201201 gd ;
@@ -461,6 +461,16 @@ describe('mapbox plots', function() {
461461 } ) . then ( function ( ) {
462462 expect ( countVisibleLayers ( gd ) ) . toEqual ( 0 ) ;
463463
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+
464474 done ( ) ;
465475 } ) ;
466476 } ) ;
You can’t perform that action at this time.
0 commit comments