Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/plots/mapbox/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,21 @@ function MapboxLayer(mapbox, index) {
this.source = null;
this.layerType = null;
this.below = null;

// is layer currently visible
this.visible = false;
}

var proto = MapboxLayer.prototype;

proto.update = function update(opts) {
if(this.needsNewSource(opts)) {
if(!this.visible) {

// IMPORTANT: must create source before layer to not cause errors
this.updateSource(opts);
this.updateLayer(opts);
}
else if(this.needsNewSource(opts)) {

// IMPORTANT: must delete layer before source to not cause errors
this.updateLayer(opts);
Expand All @@ -43,6 +52,8 @@ proto.update = function update(opts) {
}

this.updateStyle(opts);

this.visible = isVisible(opts);
};

proto.needsNewSource = function(opts) {
Expand Down Expand Up @@ -209,10 +220,7 @@ function convertSourceOpts(opts) {
module.exports = function createMapboxLayer(mapbox, index, opts) {
var mapboxLayer = new MapboxLayer(mapbox, index);

// IMPORTANT: must create source before layer to not cause errors
mapboxLayer.updateSource(opts);
mapboxLayer.updateLayer(opts);
mapboxLayer.updateStyle(opts);
mapboxLayer.update(opts);

return mapboxLayer;
};
14 changes: 12 additions & 2 deletions test/jasmine/tests/mapbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('mapbox defaults', function() {
describe('mapbox credentials', function() {
'use strict';

if(!hasWebGLSupport('scattermapbox hover')) return;
if(!hasWebGLSupport('mapbox credentials')) return;

var dummyToken = 'asfdsa124331wersdsa1321q3';
var gd;
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('mapbox credentials', function() {
describe('mapbox plots', function() {
'use strict';

if(!hasWebGLSupport('scattermapbox hover')) return;
if(!hasWebGLSupport('mapbox plots')) return;

var mock = require('@mocks/mapbox_0.json'),
gd;
Expand Down Expand Up @@ -461,6 +461,16 @@ describe('mapbox plots', function() {
}).then(function() {
expect(countVisibleLayers(gd)).toEqual(0);

return Plotly.relayout(gd, 'mapbox.layers[0]', {});
}).then(function() {
expect(countVisibleLayers(gd)).toEqual(0);

// layer with no source are not drawn

return Plotly.relayout(gd, 'mapbox.layers[0].source', layer0.source);
}).then(function() {
expect(countVisibleLayers(gd)).toEqual(1);

done();
});
});
Expand Down