Skip to content

Commit ab0f876

Browse files
committed
Added orthographic projection
1 parent f745829 commit ab0f876

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

lib/projections.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ exports.default = function (width, height, config, projectionName) {
1212
var rotation = config.rotation || _projectionConfig2.default.rotation;
1313
var precision = config.precision || _projectionConfig2.default.precision;
1414

15-
return projectionName === "albersUsa" ? projectionReference[projectionName]().scale(scale).translate([xOffset + width / 2, yOffset + height / 2]).precision(precision) : projectionReference[projectionName]().scale(scale).translate([xOffset + width / 2, yOffset + height / 2]).rotate(rotation).precision(precision);
15+
var baseProjection = projectionReference[projectionName]().scale(scale).translate([xOffset + width / 2, yOffset + height / 2]).precision(precision);
16+
17+
return projectionName === "albersUsa" ? baseProjection : projectionName === "orthographic" ? baseProjection.rotate(rotation).clipAngle(90) : baseProjection.rotate(rotation);
1618
};
1719

1820
var _d3GeoProjection = require("d3-geo-projection");
@@ -32,5 +34,6 @@ var projectionReference = {
3234
robinson: _d3GeoProjection.geoRobinson,
3335
winkel3: _d3GeoProjection.geoWinkel3,
3436
eckert4: _d3GeoProjection.geoEckert4,
35-
albersUsa: _d3Geo.geoAlbersUsa
37+
albersUsa: _d3Geo.geoAlbersUsa,
38+
orthographic: _d3Geo.geoOrthographic
3639
};

src/projections.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import {
1010
geoMercator,
1111
geoAlbersUsa,
12+
geoOrthographic,
1213
} from "d3-geo"
1314

1415
import defaultProjectionConfig from "./projectionConfig"
@@ -21,6 +22,7 @@ const projectionReference = {
2122
winkel3: geoWinkel3,
2223
eckert4: geoEckert4,
2324
albersUsa: geoAlbersUsa,
25+
orthographic: geoOrthographic,
2426
}
2527

2628
export default function(width, height, config, projectionName) {
@@ -31,14 +33,14 @@ export default function(width, height, config, projectionName) {
3133
const rotation = config.rotation || defaultProjectionConfig.rotation
3234
const precision = config.precision || defaultProjectionConfig.precision
3335

36+
const baseProjection = projectionReference[projectionName]()
37+
.scale(scale)
38+
.translate([ xOffset + width / 2, yOffset + height / 2 ])
39+
.precision(precision)
40+
3441
return projectionName === "albersUsa"
35-
? projectionReference[projectionName]()
36-
.scale(scale)
37-
.translate([ xOffset + width / 2, yOffset + height / 2 ])
38-
.precision(precision)
39-
: projectionReference[projectionName]()
40-
.scale(scale)
41-
.translate([ xOffset + width / 2, yOffset + height / 2 ])
42-
.rotate(rotation)
43-
.precision(precision)
42+
? baseProjection
43+
: projectionName === "orthographic"
44+
? baseProjection.rotate(rotation).clipAngle(90)
45+
: baseProjection.rotate(rotation)
4446
}

0 commit comments

Comments
 (0)