ProjectionEngine
math.gl's general projection interface is projection-engine agnostic. Applications depend on
ProjectionEngine and its prepared transform contract, not a particular projection catalogue or
backend. Native math.gl, proj4js, D3 and other engines can participate through adapters with explicit
coordinate, dimensional and execution semantics. See external projection engines.
Native engine constructors optionally accept resolver: CRSResolver from
@math.gl/geospatial/crs. createProjectionAsync() and getCRS() prepare
external identifiers; createProjection() remains synchronous and never looks them up.
See authority resolution
for precedence, caching and metadata rules.
ProjectionEngine is a reusable factory interface for a specific CRS pair. Native implementations
manage projection plugins, CRS readers, aliases and grids; external adapters need not use that
internal architecture. Prepared point and buffer transforms are synchronous, including transforms
returned by asynchronous initialization. An async-only backend uses the separate batch preparation
recipe rather than returning Promises from synchronous methods.
import type { ProjectionEngine } from "@math.gl/geospatial/projection-types";
import { projectionEngine } from "@math.gl/geospatial/projection";
const engine: ProjectionEngine = projectionEngine;
const mercator = engine.createProjection({ from: "WGS84", to: "EPSG:3857" });
const utm = engine.createProjection({ from: "WGS84", to: "EPSG:32631" });
mercator.project([12, 55]);
utm.project([12, 55]);
The /types entry exports only types. An import type adds no runtime code to a bundle.
The default projectionEngine includes the built-in projection catalogue, compatibility
readers and named datum catalogue. For selective imports, configure your own engine:
import { createProjectionEngine } from "@math.gl/geospatial/projection-core";
import { mercator } from "@math.gl/geospatial/projection-projections-merc";
const engine = createProjectionEngine({ projections: [mercator] });
const projection = engine.createProjection({ to: "EPSG:3857" });
| Engine | Capabilities | Import |
|---|---|---|
FullProjectionEngine | Built-in algorithms, WKT/PROJJSON compatibility readers and named datums | @math.gl/geospatial/projection |
ConfigurableProjectionEngine | Explicit plugins, readers, aliases and grids | @math.gl/geospatial/projection-core |
LazyProjectionEngine | Built-in algorithm descriptors; readers and datum catalogues remain explicit | @math.gl/geospatial/projection-projections-lazy |
WebMercatorProjectionEngine | Only WGS84 / EPSG:4326 and EPSG:3857; no readers or datum machinery | @math.gl/geospatial/projection-web-mercator |
All implement this interface. The eager catalogue is available as projectionEngine;
the lazy catalogue as lazyProjectionEngine. Both lazy exports are available
from @math.gl/geospatial/projection-projections-lazy.
Engine configurationโ
createProjectionEngine({projections, parsers, aliases, datumCatalogs, datumGrids, verticalGrids, enforceAxis, mode}) snapshots the registration arrays, alias definitions
and grid maps. Plugins and prepared grid data are shared. Engines have no source or target
CRS and no coordinate methods.
createProjection(options)โ
Accepts from, to, enforceAxis and mode. Source and target default to WGS84;
behavior defaults to the engine configuration. Eager engines return a
projection instance with scalar, flat-buffer and reusable-output
methods. Instances have independent compiled transforms and scratch storage.
The LazyProjectionEngine returns a deferred projection synchronously. Creation
loads no algorithms. Use await projection.preload() before calling projectSync()
or unprojectSync(), or let the async coordinate methods load on first use.
With eager plugins, coordinate methods are synchronous. With lazy descriptors, construction does not load algorithms; coordinate methods load them on first use and return promises. The descriptor cache shares loading across transforms created by the same engine.
createProjectionAsync(options)โ
Loads only the algorithms required by the CRS pair and returns a synchronous projection instance. Unrelated registered descriptors remain unloaded. Rejected loads can be retried.
Lazy creation and warm-upโ
import { LazyProjectionEngine } from "@math.gl/geospatial/projection-projections-lazy";
const engine = new LazyProjectionEngine();
const deferred = engine.createProjection({ to: "EPSG:3857" }); // synchronous; no loading
await deferred.preload();
const point = deferred.projectSync([12, 55]);
const ready = await engine.createProjectionAsync({ to: "EPSG:32631" });
const utm = ready.project([12, 55]); // synchronous
Minimal Web Mercator backendโ
import { WebMercatorProjectionEngine } from "@math.gl/geospatial/projection-web-mercator";
const engine = new WebMercatorProjectionEngine();
const projection = engine.createProjection({ to: "EPSG:3857" });
const meters = projection.projectSync([12, 55]);
This subpath includes only spherical Web Mercator arithmetic and buffer validation.
It accepts WGS84, EPSG:4326 and EPSG:3857 strings. Geographic aliases use
longitude/latitude order, matching the full engine's built-in aliases. Other definitions,
datums, grid shifts and projections require a configurable or full engine. Heights
and trailing ordinates pass through unchanged. Latitudes at or beyond the poles are rejected.
Engine configurationโ
Create a full engine with new FullProjectionEngine({aliases, datumGrids, verticalGrids})
when multiple CRS pairs share registrations. There is no global alias or grid registry.
The default projectionEngine is ready to use; it does not inherit registrations from
other engines. Use a factory to create a transform or construct
new ProjectionTransform(options) for per-instance configuration.