Skip to content

feat(core): add experimental CustomProjectionView - #10741

Merged
Pessimistress merged 19 commits into
masterfrom
x/alt-proj-custom-projection
Oct 6, 2026
Merged

Pessimistress merged 19 commits into
masterfrom
x/alt-proj-custom-projection

Conversation

@Pessimistress

@Pessimistress Pessimistress commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

For #10739 (PR 2 of 6)

Introduce a planar map view backed by application-supplied coordinate converters.

Changed list

  • Add experimental CustomProjectionView, viewport, and controller exports.
  • Support center, pitch, bearing, and map-style interaction.
  • Add CRS-based update detection and fromBounds/toBounds options.
  • Estimate meter scale from world-coordinate units and preserve meter altitude.
  • Document usage, coordinate behavior, and limitations.
  • Test camera alignment with WebMercatorViewport and controller behavior.

Note

Medium Risk
Touches core viewports, controllers, layer preprojection, and shader uniforms—wide rendering impact though gated behind experimental exports and documented layer limits.

Overview
Adds an experimental planar map stack (_CustomProjectionView, _CustomProjectionViewport, _CustomProjectionController) so apps can supply forward/inverse converters (e.g. proj4) and render with MapView-style center / zoom / pitch / bearing. Positions are CPU-preprojected to map meters, with optional fromBounds clamping, resolution for curved geometry, CRS metadata (fromCrs / toCrs) driving layer refresh via projectionSignature, and meter-size distortion handling through getDistanceScale or CRS heuristics.

CustomProjectionController anchors pan/zoom on the common ground plane, supports world-coordinate maxBounds, and is exported from @deck.gl/core and deck.gl only under _-prefixed names. Documentation, TOC, and What's New are updated; tests cover Web Mercator camera parity, controller gestures, layer preprojection/cartesian behavior, and shader altitude/precision.

Reviewed by Cursor Bugbot for commit bf605e1. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium risk] Adds experimental custom projection view and controller.

The PR appears safe to merge based on this review; no new findings remain.

Summary

Adds an experimental planar-map view with application-supplied coordinate converters, a viewport and a map-style controller.

  • Exports the new APIs from core and deck.gl.
  • Adds usage documentation and tests for camera alignment, interaction, coordinates and altitude.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[World coordinates] --> B[Projection converter]
  B --> C[CustomProjectionViewport]
  C --> D[Rendered positions and picking]
  E[Pointer gestures] --> F[CustomProjectionController]
  F --> C
Loading

Reviews (13) · Last reviewed commit: "fix tests"

@coveralls

coveralls commented Sep 24, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 82.941% (+0.2%) from 82.715% — x/alt-proj-custom-projection into master

@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from 1434d86 to 3a7069c Compare September 24, 2026 18:03
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from 3a7069c to 6b03ef2 Compare September 24, 2026 18:21
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch 2 times, most recently from 08fb03a to 81a94a1 Compare September 25, 2026 03:02
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from 81a94a1 to 57b81c9 Compare September 25, 2026 04:16
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch 2 times, most recently from fa8a169 to d5f7aca Compare September 29, 2026 00:34

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API and fundamental functionality review of the current revision. Two points to address below: source-unit handling in meter-size estimation, and explicit invalidation when the conversion configuration changes.

metersPerDegree,
1
]
: [1, 1, 1];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Recognized feet units are treated as meters here. isSphericalCrs classifies both +units=ft and +units=us-ft as linear, but this branch assigns one meter to each source unit. For an otherwise undistorted converter with forward([x, y, z]) => [0.3048 * x, 0.3048 * y, z], the estimator returns a scale of 0.3048 instead of 1, so meter-based sizes render at 30.48% of their intended size unless getDistanceScale is supplied. Could we use the actual source-unit-to-meter factor, or require an explicit scale callback for unsupported units? Please include a feet-to-meters regression case; the current recognized-linear-units test expects the same scale for feet and meters.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

units=ft is not a supported scenario. getDistanceScale is the wrong surface for that correction, because it does not apply to position projection, only size projections. The viewport currently documents preprojected value as "map coordinate in meters" and no unit conversion mechanism is exposed.

We can revisit when we integrate the new math.gl projection module.

this.isGeospatial = true;
this.bearing = bearing;
this.resolution = resolution;
this.signature = JSON.stringify([fromCrs, toCrs, resolution]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Could we give applications an explicit way to invalidate preprojected geometry when conversion semantics change? I agree with keeping converter object identity out of this signature because React can recreate equivalent converters. However, changing fromBounds changes preproject output while this signature remains unchanged, allowing prepared layer positions to retain the old bounds while viewport projection/picking uses the new bounds. A converter can also change behavior with the same CRS identifiers. Including the bounds values and adding a projectionRevision (or equivalent explicit trigger) would cover both cases without unnecessary updates on callback recreation. Applications should be able to refresh geometry while keeping accurate CRS identifiers and the same subdivision resolution.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fromBounds is intended to be an inherited property of the fromCrs and/or projection method (e.g. the latitude range of [-85.051129, 85.051129] of Web Mercator projection), not the bounding box of a layer's data. It is used to inform the viewport that the project function cannot produce a valid output if the input is outside of the bounds. Therefore it should never change on its own without the identity of the projection changing.

ibgreen commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Thanks Xiaoji — this is a useful step toward making deck.gl work with a broader range of coordinate datasets and map projections. The application-supplied converter and a separate planar view give us a practical foundation while keeping the projection engine outside core. Supporting a non-Mercator rendering plane is especially valuable.

A few directional ideas as we shape the API:

  • Connect to math.gl and loaders.gl CRS support. Source CRS, display CRS, axis/unit metadata, and local projection scale should have a consistent contract. CRS interpretation, unit conversion, and reusable distance/scale calculations are good candidates for math.gl; deck.gl should own camera behavior, interaction, picking, and layer lifecycle. A small adapter/example using the existing ecosystem would help establish that boundary.
  • Leave room for a source CRS per layer. The current view-wide fromCrs is a reasonable experimental starting point. Longer term, independently loaded datasets should be able to retain their own source CRSs while sharing one display projection, with loaders.gl metadata feeding that configuration.
  • Use reusable subdivision primitives. Projection-aware edge subdivision and polygon triangulation are separate operations. Edges need densification through the nonlinear transform; filled polygons and bitmaps can also need interior mesh refinement, with interpolated attributes such as UVs. I opened math.gl proposals for polyline subdivision and triangle-mesh subdivision that could support this. An eventual error tolerance measured after projection would complement the current source-unit resolution. deck.gl would decide when to apply refinement and retain responsibility for layer geometry integration.
  • Keep the scope clear. This is a planar projection foundation. Seam/domain clipping, spatially varying distortion, and more general computations near the poles still need deliberate handling as the stack evolves.

These are direction-setting ideas, not a request to implement all of them in this PR. I would like us to address the two inline points on source-unit scaling and conversion invalidation, and keep this experimental API moving forward.

@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from d5f7aca to 6f2fd7e Compare October 5, 2026 22:20
Base automatically changed from x/alt-proj-core-plumbing to master October 6, 2026 16:26
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from bdbbce5 to adcb376 Compare October 6, 2026 16:26
@Pessimistress
Pessimistress force-pushed the x/alt-proj-custom-projection branch from adcb376 to bf605e1 Compare October 6, 2026 17:51
@Pessimistress
Pessimistress merged commit c762d6b into master Oct 6, 2026
8 checks passed
@Pessimistress
Pessimistress deleted the x/alt-proj-custom-projection branch October 6, 2026 18:02
@chrisgervang chrisgervang mentioned this pull request Oct 7, 2026
53 of 66 tasks
kylebarron added a commit to developmentseed/deck.gl-raster that referenced this pull request Oct 7, 2026
…reographic COGs (#694)

* ci: build examples under examples/experimental

Add `examples/experimental/*` to the pnpm workspace and to the docs
workflow's example build loop. The loop skips directories without a
package.json: `examples/experimental/` itself matches `examples/*/`, and a
failed `node -p` would abort the step under `bash -e`.

Both hunks are byte-identical to the ones in #647, so the two branches
merge cleanly in either order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(examples): add experimental custom projection example

Render COGs in arbitrary planar map projections (Arctic and Antarctic
polar stereographic, Equal Earth, Web Mercator), with no basemap. Polar
data can't be shown in Web Mercator at all, and choosing a projection is
routine in GIS workflows.

deck.gl merged experimental support for this as `_CustomProjectionView`
(visgl/deck.gl#10741), but it ships with deck.gl v10. The example uses a
stand-in on deck.gl 9.4's `OrthographicView` with the same options and
`{center, zoom}` view state, so moving to the official view is an import
swap in the example plus a globe-detection fix in deck.gl-raster (see the
README).

- `src/custom-projection/`: the view, viewport and controller stand-in.
  Common space and zoom match upstream, and so do `preproject`,
  `postUnproject`, `projectFlat` and `projectionSignature`.
- `src/projected-cog-layer/`: `ProjectedCOGLayer`, a `COGLayer` that selects
  tiles in the map CRS and has `RasterLayer` mesh each tile in map meters
  (`coordinateSystem: "cartesian"`). Domain-aware culling and trimming,
  pole and antimeridian handling, and LOD measured on screen.
- Vector context (coastlines, graticule, domain outline) is projected on
  the CPU.
- Data: GEBCO 2026, the NASA Explorer Base Map (native EPSG:3031),
  EOxCloudless, and ITS_LIVE ice velocity (EPSG:3031 and EPSG:3413).

No library code changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* add app experimental box

* clean up app wording

* cleaner labels

* perf(examples): cut pole mesh cost in custom projection example

Zooming in over a pole was slow: a view at zoom 8 meshed 1.15M
triangles and spent ~26 s in proj4. The reprojector measures error in
source pixels as if they were square, but lng/lat pixels near a pole are
only cos(lat) as wide as they are tall on a polar map, so it kept
splitting triangles to fix sub-screen-pixel column errors.

- Stretch each geographic tile's pixel grid horizontally by the pixels'
  aspect ratio on the map before meshing (columnErrorScale). RasterLayer
  only uses `width` to size the mesh grid, so passing width * scale with
  matching transforms reweighs column error without changing UVs. The
  ratio is measured in the output map, so it also holds for Equal Earth.
- Stop meshing geographic tiles at 89.5° instead of one row from the
  pole, which halves the remaining pole triangles.

Over the pole at zoom 8: 1.15M -> 31k triangles, ~26 s -> 0.7 s of
meshing. Visible map-space error is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* cleaner label

* update README

* add experimental section to docs

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
kylebarron added a commit to developmentseed/deck.gl-raster that referenced this pull request Nov 13, 2026
…'s crs-based API (#882)

> [!NOTE]
> This PR was written by Claude (Claude Code), not by @kylebarron.

deck.gl published
[`10.0.0-alpha.1`](https://github.com/visgl/deck.gl/releases/tag/v10.0.0-alpha.1).
Its experimental `_CustomProjectionView` API has changed since the
custom projection example copied it in October (#694). This moves the
example's deck.gl 9.4 stand-in to the alpha.1 API, so the example shows
how upstream works now. The example stays on deck.gl 9.4, and nothing
under `packages/` changes.

Ref #695

### What changed upstream

| | October (visgl/deck.gl#10741) | `10.0.0-alpha.1` |
| --- | --- | --- |
| Projection input | `projection: {forward, inverse}`, `fromCrs`,
`toCrs` | **`crs`**: an EPSG code, PROJ string, WKT or PROJJSON,
resolved by math.gl's `projectionEngine.getCRS` |
| Resolution | synchronous | **asynchronous**: `view.initialize()`,
which `Deck` awaits |
| World coordinates | `fromCrs` | **always WGS84** |
| Domain | `fromBounds` | **set by the projection**:
`crs.converter.WGS84.normalize` |
| Conversions | `viewport.preproject` / `postUnproject` |
`viewport.crs.converter.WGS84.from` / `to` |

### What changes in the example

- **The stand-in** (`src/custom-projection/`) takes a `crs` and resolves
it with `@math.gl/geospatial` `5.0.0-beta.8`, the version alpha.1 pins,
through a cached `resolveCRS`. The viewport exposes `crs`, and
`projectionSignature` is `[crs.signature, resolution]`. It still differs
from upstream in three ways:
  - top-down camera only;
- meter-based CRSs only, because deck.gl 9.4's `Viewport` constructor
calls `projectFlat` before a subclass can store a per-CRS scale;
  - `project` and `unproject` stay in map meters.
- **`ProjectedCOGLayer`** converts through
`viewport.crs.converter.WGS84`, and takes its lng/lat domain from the
CRS's `normalize` clamp. It no longer has a `fromBounds` prop, and the
presets no longer carry one.
- **The app** resolves the selected preset's CRS before handing the view
to `DeckGL`, because deck.gl 9.4 doesn't await `initialize()`. Until the
new CRS resolves, the previous projection stays on screen, so `DeckGL`
never remounts.
- **The README** says how to move the example to deck.gl v10.
- **`examples/_shared`** now declares `@math.gl/web-mercator: ^4.1.0`.
Without it, pnpm resolved `@deck.gl/mapbox`'s `@math.gl/web-mercator`
peer (range `^4.1.0`) to the new 5.0 beta for every example with a
MapLibre overlay.

### Visible change

The polar maps now reach math.gl's extent, 60° past the equator, instead
of the example's 20°. The default views look the same.

<!-- before/after screenshots -->

### Checks

math.gl's conversions match proj4's to within a micrometer at sample
points inside each preset's extent, for all four presets.

COG range requests per view, in headed Chrome:

| View | `main` | This PR |
| --- | --- | --- |
| Arctic, default | 10 | 10 |
| Antarctic, default | 10 | 10 |
| Equal Earth, default | 4 | 4 |
| Web Mercator, default | 8 | 8 |
| Antarctic, NASA basemap and ITS_LIVE | 13 | 13 |
| Arctic, zoom 0.6 | 3 | **13** |
| Antarctic, zoom 0.6 | 4 | **14** |

Every view finished loading in under 8 seconds, with no new console
messages.

- **Switching projections:** switching five times, 40 ms apart, kept one
`Deck` instance and only custom projection viewports.
- **Cursor:** off the map (above, below or beside it) it reads "—".
Beside the Equal Earth and Web Mercator maps, math.gl's inverse returns
a wrapped longitude instead of throwing, so the stand-in keeps the
October stand-in's round-trip check.

The example's main bundle chunk grows from 1,592 KB to 1,801 KB, **+67
KB gzipped**, all of it math.gl's projection engine. Apache Arrow isn't
bundled.

The example's 56 tests pass, and so do `pnpm -r --filter=!docs
typecheck` and `pnpm check`.

🤖 Written by [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants