Custom projections
Custom projections let a planar deck.gl view display data in an application-defined coordinate reference system (CRS). A view resolves the target CRS and a viewport carries its forward and inverse conversion through camera work, layer positioning, geometry tessellation, picking, and rendered output.
This page extends the core rendering engine overview. Read it with deck instance and render loop, layer lifecycle and state, and interaction and picking.
Projection model
Coordinate spaces
The projection model keeps three coordinate spaces distinct. Application data starts in fromCrs world coordinates. The supplied conversion maps those values to planar toCrs coordinates. The viewport then applies a fixed scale to common space, where the camera and rendering system operate.
The inverse conversion follows the same path in reverse. It supports screen unprojection and picking when the map-coordinate position is inside the converter's valid domain. The viewport uses CRS distance scales to turn converted altitude into common-space height, so a CRS with non-meter vertical units still produces the expected elevation and layer-size behavior.
| Space | Role | Typical owner |
|---|---|---|
fromCrs | Input positions and view centers | Application and layer data |
toCrs | Planar coordinates after the custom conversion | Projection converter and map-oriented aggregation |
| Common space | Camera-relative positions used by the renderer | Viewport and projection system |
fromBounds defines the valid input domain. The system clamps positions to this domain rather than clipping them. A converter still needs to handle projection seams and other discontinuities before geometry reaches the view.
References: modules/…/custom-projection-viewport.ts• L42-60 modules/…/custom-projection-viewport.ts• L213-260 modules/…/viewport.ts• L409-451
View and viewport
CustomProjectionView is the user-facing view. It resolves the configured target CRS before it creates a CustomProjectionViewport, and it rejects a CRS that is not projected. The viewport requires finite linear units for all CRS axes. It then owns the conversion pair, camera matrices, common-space scale, projection mode, and distance scales.
The view state uses a map-style center, zoom, pitch, and bearing. Zoom doubles the scale for each increment. The optional controller keeps navigation anchors on the common-space ground plane, applies pitch and zoom limits, and can constrain the camera to world-coordinate bounds. The view waits for an asynchronously resolved CRS before it can build a viewport, so camera motion stays in the input CRS while screen motion stays aligned with projected map space. A loaded descriptor can initialize synchronously, while an initial use can wait for shared CRS resolution.
Custom projection is a planar mode. It is separate from GlobeView, whose viewport maps geographic positions onto a globe, and from WebMercatorViewport, whose target CRS describes 512-unit tile coordinates. All modes use the shared projection contract, but they have different coordinate spaces and navigation rules. OrthographicViewport remains the flat, CRS-free path for local coordinates.
The diagram shows how a view turns application coordinates into rendered positions and back into world coordinates for interaction.
flowchart LR
A[View props and view state] --> B[Custom projection view]
B --> C[Custom projection viewport]
C --> D[Forward conversion to map coordinates]
C --> E[Common-space camera matrices]
D --> F[Layer positions and geometry]
E --> G[Screen pixels]
G --> H[Inverse conversion for unprojection and picking]
References: modules/…/custom-projection-view.ts• L33-97 modules/…/custom-projection-viewport.ts• L42-116 modules/…/viewport.ts• L153-240 modules/…/web-mercator-viewport.ts• L92-125 modules/…/globe-viewport.ts• L95-199
Distance scale
Projection distortion means that one map-coordinate unit may not represent one ground meter. The viewport derives local meter scales from the target CRS at an anchor, then supplies those scales for width, radius, elevation, and other meter-based layer sizes.
The horizontal scales can differ by axis. The vertical size scale uses a value derived from them so that objects keep a stable aspect ratio. These local scales describe ground size. The map-coordinate-to-common-space scale remains fixed for the projection.
For custom projection rendering, the viewport samples local conversion scale across finite CRS rendering bounds. The shared scale data carries horizontal scale, local change across the sample field, and vertical-unit scale. The WebGL path reads this data as a texture and the WebGPU path reads it as storage data. Both projection helpers map a position into the field, reconstruct a local scale, and fall back to the global scale when the position is outside the field or the sample is invalid. The viewport also fills isolated invalid sample cells so preprojected positions can still receive local size data.
References: modules/…/custom-projection-viewport.ts• L118-210 modules/…/custom-projection-viewport.ts• L263-276 modules/…/project.ts• L19-33 modules/…/viewport-uniforms.ts• L262-275 modules/…/project.glsl.ts• L86-149 modules/…/project.wgsl.ts• L109-168 modules/…/viewport.ts• L474-493
Layer positioning
CPU preprojection
Custom projections are applied before normal layer drawing when a layer's source CRS cannot be consumed directly by the active projection shader. The coordinate-system helpers compare the source CRS with the viewport target and mark incompatible positions as preprojected. The GPU then receives target-coordinate values instead of interpreting an application-specific CRS. A source CRS that matches the viewport target can remain in the shader path.
The layer coordinate system controls this path. Default geospatial positions use the source CRS. Cartesian positions are already target-coordinate values, so model matrices and coordinate origins can act on them without another CRS conversion. Meter offsets use a local meter frame around an anchor. This distinction lets ordinary layers and generated layer geometry share one projection mode.
The projection mode is part of the rendering contract. Shared projection helpers use it to select custom-geospatial behavior and to establish a stable common-space origin for precision. In custom-geospatial mode, the CPU conversion remains the source of truth. The helpers also keep the rounded shader origin paired with its common-space origin, which preserves small offsets near a large map-coordinate center.
References: modules/…/coordinate-systems.ts• L11-89 modules/…/project-functions.ts• L47-135 modules/…/viewport-uniforms.ts• L81-191 modules/…/project.ts• L38-67
Position invalidation
A layer must keep the same preprojection capability during its lifetime. When the projection signature changes, the layer invalidates projection-aware attributes and rebuilds positions. Camera movement alone does not require source positions to be converted again because the camera matrices change while the conversion stays the same.
The signature tracks the CRS identities and tessellation resolution. Changing only the converter object does not provide a change signal. Applications that replace a converter must also change a signature input such as fromCrs, toCrs, or resolution so that existing layers refresh their positions.
References: modules/…/custom-projection-viewport.ts• L95-115 modules/…/viewport.ts• L196-230 docs/…/custom-projection-view.md• L86-92
Geometry tessellation
Curved paths and polygons
A non-linear projection can curve an edge that is straight in fromCrs. A positive resolution adds intermediate points in the source coordinate space before conversion. Each generated point is converted once, so the rendered path or polygon follows the projected shape instead of joining only projected endpoints.
Path and polygon tessellators use the same rule for normal data and binary data. They preserve the source geometry and rebuild affected rows when the projection, model transform, coordinate system, or tessellation resolution changes. Polygon winding and cut-edge information are corrected after projection so triangulation remains valid when the conversion changes orientation.
References: modules/…/path-layer.ts• L359-410 modules/…/path-tesselator.ts• L84-97 modules/…/polygon-tesselator.ts• L86-120 test/…/preprojection-tesselator.spec.ts• L15-123
Images and generated geometry
BitmapLayer uses a mesh when a custom view requests subdivision. The mesh gives the image more vertices so its surface can follow projected bounds. Texture coordinates remain linear inside each triangle, so subdivision cannot repair an image whose pixel coordinate system does not match fromCrs.
Aggregation layers use projected map space for their bins and generated shapes. For example, custom projection tests render contour, hexagon, and heatmap results in the same projected view as ordinary paths and state polygons. A generated layer must therefore state whether its size is in source coordinates, map coordinates, or common space before it builds geometry.
References: modules/…/bitmap-layer.ts• L255-273 modules/…/contour-layer.ts• L360-394 modules/…/hexagon-layer.ts• L78-92 modules/…/grid-layer.ts• L77-88 docs/…/custom-projection-view.md• L94-102
Unsupported geometry assumptions
Preprojection removes the geographic assumptions that some layer features need. Longitude wrapping is disabled for preprojected paths, lines, arcs, and polygons. Great-circle options do not preserve a great-circle curve. Applications must sample the curve in geographic space and render the samples as a path.
Geometry must also be split at projection discontinuities. The custom view does not clip those seams for the application. Tiled layer families are not supported because their tile coordinates and loading rules depend on a fixed geographic projection.
References: modules/…/path-layer.ts• L386-404 modules/…/line-layer.ts• L188-195 modules/…/arc-layer.ts• L255-267 docs/…/custom-projection-view.md• L94-103
Validation coverage
Conversion and navigation tests
Viewport tests check the forward and inverse contract, altitude scaling, bounds behavior, distance scales, projection signatures, screen round trips, and panning anchors. Shader tests also check that converted altitude units become the expected common-space height, including non-meter vertical units and large map-coordinate origins. Controller tests cover map-style navigation while keeping the center in the source CRS and constraining pitch, zoom, and bounds.
These tests protect the boundary between application coordinates and common space. They also check that invalid inverse results do not become plausible picked positions.
References: test/…/custom-projection-viewport.spec.ts• L26-119 test/…/custom-projection-viewport.spec.ts• L181-267 test/…/custom-projection-controller.spec.ts• L1-200 test/…/custom-projection-altitude.spec.ts• L22-95 test/…/custom-projection-altitude.spec.ts• L124-175 test/…/custom-projection-altitude.spec.ts• L177-295
View lifecycle tests
View-level tests protect the contracts around CRS resolution and failure reporting, layout and state propagation, controller selection, source and inverse coordinates, and experimental export boundaries. They also cover shared pending resolution and manager behavior when a view is removed before its CRS finishes loading.
References: test/…/custom-projection-view.spec.ts• L19-87 test/…/custom-projection-view.spec.ts• L90-150 test/…/custom-projection-view.spec.ts• L152-212
Core layer tests
Layer tests verify that points, lines, arcs, paths, and polygons receive converted positions. They also verify that projection changes rebuild every geometry row, that model transforms combine with preprojection, and that WebGL and WebGPU paths handle generated vertices without mutating source data.
The same tests confirm that longitude wrapping is not applied after preprojection. This matters because applying geographic wrapping after a custom conversion can create a false edge or move geometry across the wrong seam. Core shader tests add a lower-level check that cartesian and default inputs produce the same common position after conversion, model transforms, coordinate origins, and altitude scaling.
References: test/…/custom-projection.spec.ts• L31-145 test/…/custom-projection.spec.ts• L147-222 test/…/custom-projection.spec.ts• L224-464 test/…/custom-projection-altitude.spec.ts• L97-122 test/…/custom-projection-altitude.spec.ts• L177-295
Render and aggregation tests
Render tests use a real projected state map and a projected aggregation grid. They compare flat and pitched views across WebGL and WebGPU. They also check that screen probes land inside the canvas and that picking returns the source-CRS feature for supported backends.
The custom projection app provides a direct validation path for four projection families. It shows how the same layers use Equal Earth, equirectangular, stereographic, and Web Mercator converters while local meter scales and input bounds vary by projection. The app also switches the view and initial camera state together, so each projection receives a matching frame. Its private package defines local Vite start scripts and the core, layer, widget, and geospatial runtime dependencies needed to run this validation path.
The coverage shows the intended product boundary: custom projections work with core layer types and selected generated aggregation layers, but they do not turn every projection-dependent feature into a supported feature.
References: test/…/custom-projection.spec.ts• L23-128 test/…/custom-projection.spec.ts• L130-255 test/…/custom-projection.spec.ts• L257-273 test/…/app.ts• L51-142 test/…/package.json• L1-16
Change checklist
When these files or sections are changed, remember to consider these:
- Change a converter and its CRS identity or resolution together so layer position attributes see a new projection signature.
- Change
resolutionwith path, polygon, or bitmap geometry rules because it changes vertex counts and projected edge shape. - Change coordinate-system handling with both CPU attribute transforms and shader projection-origin rules.
- Change meter-scale rules with layer size behavior and aggregation cell or radius units.
- Change the sampled local scale field with both the WebGL texture path and the WebGPU storage-data path. Keep their map-to-sample transform and fallback rules aligned.
- Change inverse validation with picking and controller pan or zoom anchors.
- Change projection seams or wrapping rules with every layer that creates or cuts line and polygon geometry.
- Change vertical CRS units with viewport distance scales and shader altitude conversion. Keep the source altitude contract and rendered meter size aligned.
- Change precision-origin handling with both the rounded shader origin and the common-space origin used by CPU and GPU projection paths.
- Change a built-in viewport CRS or coordinate frame with source-CRS matching, packed shader frames, and its flat project/unproject behavior.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Converter returns non-meter X/Y or inconsistent altitude units | Camera scale, layer sizes, and elevation do not match the map | Keep forward and inverse in the documented map-coordinate contract |
| Converter uses a non-meter vertical unit without a matching CRS scale | Converted height is too high or too low in the rendered scene | Define the CRS vertical unit so viewport distance scales can convert it to common-space height |
| Converter changes without a signature input change | Existing layer attributes keep old projected positions | Change fromCrs, toCrs, or resolution with the converter |
| Inverse conversion returns a finite but invalid position | Picking or navigation can use a false world coordinate | Use the viewport round-trip check and return null for invalid domains |
A curved edge uses resolution: 0 | The renderer joins projected endpoints and the shape can visibly miss the projection curve | Set a positive source-space resolution for curved geometry |
| Geographic wrapping is used after preprojection | A line or polygon can cross the wrong boundary | Split geometry in source space and let preprojection handle the conversion |
| Geometry crosses a projection discontinuity | The rendered shape can span an invalid map region | Split the geometry before passing it to the layer |
| WebGL and WebGPU use different local scale data or transforms | Meter-sized objects change size or aspect ratio when the backend changes | Keep the external scale field contract shared across the projection shader paths |
| Shader origin is rounded without deriving the matching common origin | Small offsets disappear near a large map-coordinate center | Treat the shader origin and common origin as one precision contract |
| A source CRS is treated as shader-compatible because its units look similar | The shader reads coordinates in the wrong frame or direction | Match source and target CRS signatures and preproject incompatible sources |
Key files
| File | Why to read it |
|---|---|
| modules/…/custom-projection-view.ts | Defines the view contract, resolves the target projected CRS, and connects view state, viewport, and controller. |
| modules/…/custom-projection-viewport.ts | Defines coordinate conversion, common-space scale, inverse validation, local size scale data, and meter-size behavior. |
| modules/…/viewport.ts | Defines the shared CRS conversion, distance-scale, resolution, and project/unproject contract used by all viewports. |
| modules/…/web-mercator-viewport.ts | Shows how the standard map viewport uses its tile CRS and keeps geographic navigation separate from custom planar conversion. |
| modules/…/globe-viewport.ts | Shows the separate globe coordinate transform and navigation model. |
| modules/…/orthographic-viewport.ts | Shows the flat local-coordinate viewport without a geospatial CRS. |
| modules/…/web-mercator-util.ts | Defines the standard 512-unit tile CRS used by the Web Mercator viewport. |
| modules/…/globe-util.ts | Defines the globe CRS and the geographic-to-sphere conversion used by globe rendering. |
| modules/…/coordinate-systems.ts | Explains when a source CRS can pass to the shader and when the system must preproject it. |
| modules/…/viewport-uniforms.ts | Defines projection mode, coordinate origin, precision, and local scale uniforms. |
| modules/…/project-functions.ts | Connects layer coordinate systems and origins to common-space positions. |
| modules/…/project.ts | Connects viewport projection data and local scale fields to the shared shader module. |
| modules/…/project.glsl.ts | Defines the WebGL projection helpers and local scale sampling contract. |
| modules/…/project.wgsl.ts | Defines the WebGPU projection helpers and the matching local scale contract. |
| modules/…/path-layer.ts | Shows the layer lifecycle for projected path tessellation. |
| modules/…/polygon-tesselator.ts | Shows how projected polygon cuts, winding, and triangulation stay valid. |
| modules/…/bitmap-layer.ts | Shows how raster bounds become a subdivided projected mesh. |
| modules/…/contour-layer.ts | Shows how generated aggregation geometry is placed in a custom view. |
| test/…/custom-projection-view.spec.ts | Verifies CRS loading, view and viewport state, inverse handling, controller setup, and manager lifecycle behavior. |
| test/…/custom-projection-altitude.spec.ts | Verifies common-space altitude, coordinate origins, model transforms, and size scales across WebGL and WebGPU paths. |
| test/…/custom-projection.spec.ts | Demonstrates end-to-end rendering and picking across core and aggregation layers. |
| test/…/app.ts | Provides a working view that switches between several projection families and displays local scale probes. |
| test/…/package.json | Defines the private Vite app, its local start scripts, and the runtime dependencies for the validation path. |
| test/…/projection-config.ts | Defines the shared contract for converter, bounds, CRS, and local scale settings. |