A thin wrapper around proj4 that accepts multiple CRS input formats and automatically resolves authority codes via spatialreference.org.
| Format | Example | Handling |
|---|---|---|
| Proj4 string | +proj=stere +lat_0=-90 ... |
Native proj4js |
| WKT1 | PROJCS["Antarctic",...] |
Native proj4js |
| Authority code | EPSG:3031, ESRI:2181 |
Fetch from spatialreference.org |
When input matches pattern <AUTH>:<CODE> (case-insensitive):
- Check if already registered via
proj4.defs - If not, fetch:
https://spatialreference.org/ref/{auth}/{code}/ogcwkt/ - Register with
proj4.defs('{AUTH}:{CODE}', fetchedWKT) - Return transformer
// Example resolution
"EPSG:3031" → fetch https://spatialreference.org/ref/epsg/3031/ogcwkt/
"ESRI:2181" → fetch https://spatialreference.org/ref/esri/2181/ogcwkt/
"SR-ORG:7483" → fetch https://spatialreference.org/ref/sr-org/7483/ogcwkt/
// Returns WKT1 like:
// PROJCS["WGS 84 / Antarctic Polar Stereographic",...]// Async wrapper - handles all formats
const proj = await resolveProj('EPSG:3031');
proj.forward([lon, lat]); // → [x, y]
// Or transform directly
const [x, y] = await transform('EPSG:4326', 'EPSG:3031', [0, -71]);- Cache fetched definitions in
proj4.defsfor reuse - Return meaningful errors on fetch failure (404, network)
- Timeout after ~5 seconds
- Authority names are lowercased for URL:
EPSG→epsg