Skip to content

Commit e26dfc3

Browse files
committed
do not attempt to remove non-existant source and layers
- this can happen when trying to remove a `visible:false` layer
1 parent c18fd75 commit e26dfc3

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/plots/mapbox/layers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ proto.removeLayer = function() {
145145

146146
proto.dispose = function() {
147147
var map = this.subplot.map;
148-
map.removeLayer(this.idLayer);
149-
map.removeSource(this.idSource);
148+
if(map.getLayer(this.idLayer)) map.removeLayer(this.idLayer);
149+
if(map.getSource(this.idSource)) map.removeSource(this.idSource);
150150
};
151151

152152
function isVisible(opts) {

test/jasmine/tests/mapbox_test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,28 @@ describe('@noCI, mapbox plots', function() {
976976
.then(done);
977977
}, LONG_TIMEOUT_INTERVAL);
978978

979+
it('@gl should not attempt to remove non-existing layer sources', function(done) {
980+
function _assert(msg, exp) {
981+
return function() {
982+
var layerList = gd._fullLayout.mapbox._subplot.layerList;
983+
expect(layerList.length).toBe(exp, msg);
984+
};
985+
}
986+
987+
Plotly.react(gd, [{type: 'scattermapbox'}], {
988+
mapbox: { layers: [{}] }
989+
})
990+
.then(_assert('1 visible:false layer', 1))
991+
.then(function() {
992+
return Plotly.react(gd, [{type: 'scattermapbox'}], {
993+
mapbox: { layers: [] }
994+
});
995+
})
996+
.then(_assert('no layers', 0))
997+
.catch(failTest)
998+
.then(done);
999+
}, LONG_TIMEOUT_INTERVAL);
1000+
9791001
it('@gl should be able to update the access token', function(done) {
9801002
Plotly.relayout(gd, 'mapbox.accesstoken', 'wont-work').catch(function(err) {
9811003
expect(gd._fullLayout.mapbox.accesstoken).toEqual('wont-work');

0 commit comments

Comments
 (0)