Skip to content

Commit f04bc14

Browse files
committed
Add special handling for Albers USA
1 parent 195345c commit f04bc14

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/plots/geo/geo.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ proto.updateProjection = function (geoCalcData, fullLayout) {
353353
// so here's this hack to make it respond to 'geoLayout.center'
354354
if (geoLayout._isAlbersUsa) {
355355
var centerPx = projection([center.lon, center.lat]);
356-
var tt = projection.translate();
357-
358-
projection.translate([tt[0] - (centerPx[0] - tt[0]), tt[1] - (centerPx[1] - tt[1])]);
356+
// If center isn't within the Albers USA bounds (clipped to the USA),
357+
// `projection(...)` returns null so skip the recentering
358+
if (centerPx) {
359+
var tt = projection.translate();
360+
projection.translate([tt[0] - (centerPx[0] - tt[0]), tt[1] - (centerPx[1] - tt[1])]);
361+
}
359362
}
360363
};
361364

src/plots/geo/layout_defaults.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
201201

202202
// Only use fitbounds if user hasn't set any view attributes. This prevents
203203
// user-specified view info from being ignored.
204-
const fitbounds = coerce('fitbounds');
205-
if (fitbounds) {
204+
coerce('fitbounds');
205+
if (geoLayoutOut.fitbounds) {
206206
const centerIn = geoLayoutIn.center || {};
207207
const projectionIn = geoLayoutIn.projection || {};
208208
const rotationIn = projectionIn.rotation || {};
@@ -217,7 +217,8 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce, opts) {
217217
lonaxisIn.range,
218218
lataxisIn.range
219219
].some((d) => d !== undefined);
220-
if (hasUserView) geoLayoutOut.fitbounds = false;
220+
// The Albers projection doesn't need a fit, so skip here
221+
if (hasUserView || isAlbersUsa) geoLayoutOut.fitbounds = false;
221222
}
222223

223224
// Set auto-filled view attributes to null so updateProjection can

0 commit comments

Comments
 (0)