Skip to content

Commit 43aba1d

Browse files
committed
Update computeBbox calls to handle null return value
1 parent b3c6fa8 commit 43aba1d

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

‎src/traces/choropleth/plot.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,25 @@ function calcGeoJSON(calcTrace, fullLayout) {
5454
calcPt._polygons = geoUtils.feature2polygons(feature);
5555

5656
var bboxFeature = geoUtils.computeBbox(feature);
57-
lonArray.push(bboxFeature[0], bboxFeature[2]);
58-
latArray.push(bboxFeature[1], bboxFeature[3]);
57+
if (bboxFeature) {
58+
const [west, south, east, north] = bboxFeature;
59+
lonArray.push(west, east);
60+
latArray.push(south, north);
61+
}
5962
} else {
6063
calcPt.geojson = null;
6164
}
6265
}
6366

6467
if (geoLayout.fitbounds === 'geojson' && locationmode === 'geojson-id') {
6568
var bboxGeojson = geoUtils.computeBbox(geoUtils.getTraceGeojson(trace));
66-
lonArray = [bboxGeojson[0], bboxGeojson[2]];
67-
latArray = [bboxGeojson[1], bboxGeojson[3]];
69+
// Falsy bbox (Sphere / malformed / empty geojson) falls through to the
70+
// per-feature bounds populated above, effectively the same as fitBounds === 'locations'.
71+
if (bboxGeojson) {
72+
const [west, south, east, north] = bboxGeojson;
73+
lonArray = [west, east];
74+
latArray = [south, north];
75+
}
6876
}
6977

7078
var opts = { padded: true };
@@ -73,6 +81,6 @@ function calcGeoJSON(calcTrace, fullLayout) {
7381
}
7482

7583
module.exports = {
76-
calcGeoJSON: calcGeoJSON,
77-
plot: plot
84+
calcGeoJSON,
85+
plot
7886
};

‎src/traces/scattergeo/plot.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,15 @@ function calcGeoJSON(calcTrace, fullLayout) {
101101
var lonArray;
102102
var latArray;
103103

104-
if (geoLayout.fitbounds === 'geojson' && trace.locationmode === 'geojson-id') {
105-
var bboxGeojson = geoUtils.computeBbox(geoUtils.getTraceGeojson(trace));
106-
lonArray = [bboxGeojson[0], bboxGeojson[2]];
107-
latArray = [bboxGeojson[1], bboxGeojson[3]];
104+
const bboxGeojson =
105+
geoLayout.fitbounds === 'geojson' && trace.locationmode === 'geojson-id'
106+
? geoUtils.computeBbox(geoUtils.getTraceGeojson(trace))
107+
: null;
108+
109+
if (bboxGeojson) {
110+
const [west, south, east, north] = bboxGeojson;
111+
lonArray = [west, east];
112+
latArray = [south, north];
108113
} else {
109114
lonArray = new Array(len);
110115
latArray = new Array(len);

0 commit comments

Comments
 (0)