d3-geo-albers-usa-mapshaper
v1.0.0
Published
A D3.js composite projection that exactly replicates mapshaper's albersusa projection.
Maintainers
Readme
d3-geo-albers-usa-mapshaper
A d3-geo composite projection that roughly matches Mapshaper’s albersusa projection. This was mostly for fun, I wouldn't use it to line up geometries generated in Mapshaper.
The lower 48 use geoAlbers. Alaska and Hawaii use separate geoConicEqualArea definitions with Mapshaper’s standard parallels, rotations, and inset placement (Alaska is drawn at reduced scale relative to the contiguous states).
Installing
With npm:
npm install d3-geo-albers-usa-mapshaperUsage
import { geoAlbersUsaMapshaper } from "d3-geo-albers-usa-mapshaper";
const projection = geoAlbersUsaMapshaper();
// Typical D3 pattern: size to a viewport
const path = d3.geoPath().projection(
projection.fitSize([width, height], geojson)
);API Reference
# geoAlbersUsaMapshaper()
Constructs a new Mapshaper-compatible Albers USA projection. The returned object is a function (coordinates) => [x, y] plus the methods below.
# projection.scale([scale])
If scale is specified, sets the overall scale factor and updates component projections. If omitted, returns the current scale.
# projection.translate([point])
If point is specified, sets the translation [x, y] and recomputes clip extents and inset positions. If omitted, returns the current translation.
# projection.precision([precision])
If precision is specified, sets adaptive sampling precision on all component projections (see projection.precision). If omitted, returns the current precision.
# projection.stream(stream)
Returns a composite geo stream for rendering.
# projection.invert(point)
Given pixel coordinates [x, y], returns [longitude, latitude] by delegating to the lower 48, Alaska, or Hawaii projection based on inset bounds.
# projection.fitExtent(extent, object)
# projection.fitSize(size, object)
# projection.fitWidth(width, object)
# projection.fitHeight(height, object)
Convenience methods to set scale and translate so the given GeoJSON object fits the viewport; see fitExtent and related helpers in d3-geo.
Limitations
This projection fixes clip extents, centers, and rotations internally to mirror Mapshaper’s layout. It does not expose generic projection.center, projection.rotate, projection.clipAngle, or projection.clipExtent on the composite object the way a single-region d3 projection would.
Puerto Rico and other territories are not included as separate insets in this implementation.
License
ISC. See LICENSE.
