Skip to content

Commit 70878b7

Browse files
committed
add PlotlyGeoAssets to window during Plotly.register
for geo AND mapbox base plot modules ... that way we do this only once when geo and mapbox modules are registered
1 parent 8fc1dbe commit 70878b7

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/plots/geo/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ function plotGeo(gd) {
3737
var calcData = gd.calcdata;
3838
var geoIds = fullLayout._subplots[GEO];
3939

40-
/**
41-
* If 'plotly-geo-assets.js' is not included,
42-
* initialize object to keep reference to every loaded topojson
43-
*/
44-
if(window.PlotlyGeoAssets === undefined) {
45-
window.PlotlyGeoAssets = {topojson: {}};
46-
}
47-
4840
for(var i = 0; i < geoIds.length; i++) {
4941
var geoId = geoIds[i];
5042
var geoCalcData = getSubplotCalcData(calcData, GEO, geoId);

src/registry.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,25 @@ function registerTraceModule(_module) {
269269
extendFlat(exports.traceLayoutAttributes, _module.layoutAttributes);
270270
}
271271

272-
// add mapbox-gl CSS here to avoid console warning on instantiation
273272
var basePlotModule = _module.basePlotModule;
274-
if(basePlotModule.name === 'mapbox') {
273+
var bpmName = basePlotModule.name;
274+
275+
// add mapbox-gl CSS here to avoid console warning on instantiation
276+
if(bpmName === 'mapbox') {
275277
var styleRules = basePlotModule.constants.styleRules;
276278
for(var k in styleRules) {
277279
addStyleRule('.mapboxgl-' + k, styleRules[k]);
278280
}
279281
}
282+
283+
// if `plotly-geo-assets.js` is not included,
284+
// add `PlotlyGeoAssets` global to stash references to all fetched
285+
// topojson / geojson data
286+
if((bpmName === 'geo' || bpmName === 'mapbox') &&
287+
(typeof window !== undefined && window.PlotlyGeoAssets === undefined)
288+
) {
289+
window.PlotlyGeoAssets = {topojson: {}};
290+
}
280291
}
281292

282293
function registerSubplot(_module) {

0 commit comments

Comments
 (0)