Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit 9c9264f

Browse files
committed
add albersUsa-only logic for geo.center
- as albersUsa projection does not expose `center()` method
1 parent 67d3b72 commit 9c9264f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/plots/geo/geo2.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,17 @@ proto.updateProjection = function(fullLayout, geoLayout) {
215215
.translate([t[0] + (midPt[0] - t[0]), t[1] + (midPt[1] - t[1])])
216216
.clipExtent(b);
217217

218-
// TODO we'll need to special algo for albersUsa projection
219-
// as this particular projection does not support `.center`
218+
// the 'albers usa' projection does not expose a 'center' method
219+
// so here's this hack to make it respond to 'geoLayout.center'
220+
if(geoLayout._isAlbersUsa) {
221+
var centerPx = projection([center.lon, center.lat]);
222+
var tt = projection.translate();
223+
224+
projection.translate([
225+
tt[0] - (centerPx[0] - tt[0]),
226+
tt[1] - (centerPx[1] - tt[1])
227+
]);
228+
}
220229
};
221230

222231
proto.updateBaseLayers = function(fullLayout, geoLayout) {

src/plots/geo/layout/defaults.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,22 @@ function handleGeoDefaults(geoLayoutIn, geoLayoutOut, coerce) {
9898
if(show) coerce('oceancolor');
9999
}
100100

101-
coerce('center.lon', isScoped ? centerLon : projLon);
102-
coerce('center.lat', latRange[0] + (latRange[1] - latRange[0]) / 2);
101+
var centerLonDflt;
102+
var centerLatDflt;
103+
104+
if(isAlbersUsa) {
105+
// 'albers usa' does not have a 'center',
106+
// these values were found using via:
107+
// projection.invert([geoLayout.center.lon, geoLayoutIn.center.lat])
108+
centerLonDflt = -96.6;
109+
centerLatDflt = 38.7;
110+
} else {
111+
centerLonDflt = isScoped ? centerLon : projLon;
112+
centerLatDflt = latRange[0] + (latRange[1] - latRange[0]) / 2;
113+
}
114+
115+
coerce('center.lon', centerLonDflt);
116+
coerce('center.lat', centerLatDflt);
103117

104118
if(isConic) {
105119
var dfltProjParallels = scopeParams.projParallels || [0, 60];

0 commit comments

Comments
 (0)