diff --git a/src/plots/mapbox/mapbox.js b/src/plots/mapbox/mapbox.js index bc798ca3ae2..c8ab4b1e650 100644 --- a/src/plots/mapbox/mapbox.js +++ b/src/plots/mapbox/mapbox.js @@ -315,9 +315,16 @@ proto.updateData = function(calcData) { trace = calcTrace[0].trace; traceObj = traceHash[trace.uid]; + var didUpdate = false; if(traceObj) { - traceObj.update(calcTrace); - } else if(trace._module) { + if(traceObj.type === trace.type) { + traceObj.update(calcTrace); + didUpdate = true; + } else { + traceObj.dispose(); + } + } + if(!didUpdate && trace._module) { traceHash[trace.uid] = trace._module.plot(this, calcTrace); } } diff --git a/src/traces/choroplethmapbox/plot.js b/src/traces/choroplethmapbox/plot.js index f6e236e2027..3fbb9026cce 100644 --- a/src/traces/choroplethmapbox/plot.js +++ b/src/traces/choroplethmapbox/plot.js @@ -13,6 +13,7 @@ var convertOnSelect = require('./convert').convertOnSelect; var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; function ChoroplethMapbox(subplot, uid) { + this.type = 'choroplethmapbox'; this.subplot = subplot; this.uid = uid; diff --git a/src/traces/densitymapbox/plot.js b/src/traces/densitymapbox/plot.js index 9a6a5a55403..c4b26c8af7b 100644 --- a/src/traces/densitymapbox/plot.js +++ b/src/traces/densitymapbox/plot.js @@ -12,6 +12,7 @@ var convert = require('./convert'); var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; function DensityMapbox(subplot, uid) { + this.type = 'densitymapbox'; this.subplot = subplot; this.uid = uid; diff --git a/src/traces/scattermapbox/plot.js b/src/traces/scattermapbox/plot.js index 55c2e910dcb..2fa66fc0ca7 100644 --- a/src/traces/scattermapbox/plot.js +++ b/src/traces/scattermapbox/plot.js @@ -13,6 +13,7 @@ var LAYER_PREFIX = require('../../plots/mapbox/constants').traceLayerPrefix; var ORDER = ['fill', 'line', 'circle', 'symbol']; function ScatterMapbox(subplot, uid) { + this.type = 'scattermapbox'; this.subplot = subplot; this.uid = uid; diff --git a/test/jasmine/tests/densitymapbox_test.js b/test/jasmine/tests/densitymapbox_test.js index 9503d3ab506..3fb5f67e61f 100644 --- a/test/jasmine/tests/densitymapbox_test.js +++ b/test/jasmine/tests/densitymapbox_test.js @@ -497,4 +497,30 @@ describe('@noCI Test densitymapbox interactions:', function() { .catch(failTest) .then(done); }, 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL); + + it('@gl should be able to restyle from and to *scattermapbox*', function(done) { + function _assert(msg, exp) { + var traceHash = gd._fullLayout.mapbox._subplot.traceHash; + expect(Object.keys(traceHash).length).toBe(1, 'one visible trace| ' + msg); + for(var k in traceHash) { + expect(traceHash[k].type).toBe(exp, 'trace type| ' + msg); + } + } + + Plotly.plot(gd, [{ + type: 'densitymapbox', + lon: [10, 20, 30], + lat: [15, 25, 35], + z: [1, 20, 5] + }], {}, { + mapboxAccessToken: MAPBOX_ACCESS_TOKEN + }) + .then(function() { _assert('after first', 'densitymapbox'); }) + .then(function() { return Plotly.restyle(gd, 'type', 'scattermapbox'); }) + .then(function() { _assert('after restyle to scattermapbox', 'scattermapbox'); }) + .then(function() { return Plotly.restyle(gd, 'type', 'densitymapbox'); }) + .then(function() { _assert('back to densitymapbox', 'densitymapbox'); }) + .catch(failTest) + .then(done); + }, 5 * jasmine.DEFAULT_TIMEOUT_INTERVAL); });