Skip to content

Commit 6e748ef

Browse files
committed
mapbox: handle non-visible to visible in update method
- so that a layer object created with an invalid source can be relayouted with a valid one.
1 parent b6fc59d commit 6e748ef

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/plots/mapbox/layers.js

+13-5
Original file line numberDiff line numberDiff 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

3235
var proto = MapboxLayer.prototype;
3336

3437
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)) {
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

4859
proto.needsNewSource = function(opts) {
@@ -209,10 +220,7 @@ function convertSourceOpts(opts) {
209220
module.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
};

test/jasmine/tests/mapbox_test.js

+10
Original file line numberDiff line numberDiff line change
@@ -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
});

0 commit comments

Comments
 (0)