Skip to content

Commit d052f82

Browse files
authored
Merge pull request #693 from plotly/mapbox-layer-relayout
Make invalid mapbox layers work with relayout
2 parents f69f6fc + c839b4c commit d052f82

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
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

+12-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('mapbox defaults', function() {
146146
describe('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() {
195195
describe('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
});

0 commit comments

Comments
 (0)