Skip to content

Commit 671fdff

Browse files
committed
fix(geo): preserve D3 projection default rotation when user does not set rotation
Geo.updateProjection unconditionally called projection.rotate() which overwrites the D3 projection's built-in default rotation. For projections that ship with a non-identity default (e.g. peirce quincuncial [-90,-90,45], wiechel [0,-90,45]), the map rendered in a different orientation. Only call projection.rotate() when the user explicitly set rotation values or when fitbounds has derived a rotation from the data. Otherwise preserve the D3 projection's default rotation so maps render in their canonical orientation. Fixes #7949
1 parent 21da158 commit 671fdff

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

src/plots/geo/geo.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,22 @@ proto.updateProjection = function(geoCalcData, fullLayout) {
303303

304304
// set 'pre-fit' projection
305305
projection
306-
.center([center.lon - rotation.lon, center.lat - rotation.lat])
307-
.rotate([-rotation.lon, -rotation.lat, rotation.roll])
308-
.parallels(projLayout.parallels);
306+
.center([center.lon - rotation.lon, center.lat - rotation.lat]);
307+
308+
// Only override the projection's built-in rotation when the user
309+
// explicitly set it (or when fitbounds derived one). Otherwise
310+
// preserve the D3 projection's default rotation so that projections
311+
// with a non-identity default (e.g. peirce quincuncial, wiechel)
312+
// render in their canonical orientation.
313+
if (fullLayout._input && fullLayout._input[this.id] &&
314+
fullLayout._input[this.id].projection &&
315+
fullLayout._input[this.id].projection.rotation) {
316+
projection.rotate([-rotation.lon, -rotation.lat, rotation.roll]);
317+
} else if (geoLayout.fitbounds) {
318+
projection.rotate([-rotation.lon, -rotation.lat, rotation.roll]);
319+
}
320+
321+
projection.parallels(projLayout.parallels);
309322

310323
// fit projection 'scale' and 'translate' to set lon/lat ranges
311324
var rangeBox = makeRangeBox(lonaxisRange, lataxisRange);

0 commit comments

Comments
 (0)