Skip to content

refactor(examples): move the custom projection example to deck.gl v10's crs-based API - #882

Merged
kylebarron merged 6 commits into
mainfrom
kyle/custom-projection-v10-api
Nov 13, 2026
Merged

kylebarron merged 6 commits into
mainfrom
kyle/custom-projection-v10-api

Conversation

@kylebarron

Copy link
Copy Markdown
Member

Note

This PR was written by Claude (Claude Code), not by @kylebarron.

deck.gl published 10.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.

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

kylebarron and others added 6 commits November 12, 2026 17:19
…example

deck.gl 10.0.0-alpha.1 changed the experimental custom projection API that
the example's deck.gl 9.4 stand-in copied in October: views now take a
`crs` that math.gl resolves into a descriptor, and `fromBounds`,
`projection`, `fromCrs` and `toCrs` are gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…h.gl 5, as in deck.gl v10

deck.gl 10.0.0-alpha.1's `_CustomProjectionView` takes a `crs` (an EPSG
code, PROJ string, WKT or PROJJSON) and resolves it asynchronously with
math.gl's projection engine; the `projection`, `fromCrs`, `toCrs` and
`fromBounds` props are gone. The example's deck.gl 9.4 stand-in now does
the same with `@math.gl/geospatial` 5.0.0-beta.8, the version alpha.1
pins, and `ProjectedCOGLayer` converts through `viewport.crs.converter`.
Presets still pass their `fromBounds`, so the maps look as before.

`examples/_shared` now declares the `@math.gl/web-mercator` peer of
`@deck.gl/mapbox` itself: otherwise pnpm resolved that peer to the new
5.0 beta for every example with a MapLibre overlay.

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

deck.gl 10.0.0-alpha.1 drops `fromBounds`: a math.gl CRS descriptor's
`normalize` clamps positions into the projection's rendering extent
instead. `ProjectedCOGLayer` now derives its lng/lat domain from that
clamp, so it no longer takes a `fromBounds` prop, and the presets no
longer carry one.

The polar presets now reach math.gl's extent, 60° past the equator,
instead of the example's 20°.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
….0.0-alpha.1

Explains how the stand-in follows v10's API, how to move the example to
deck.gl v10, and what the domain is now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Beside the Equal Earth and Web Mercator maps, math.gl's inverse returns a
wrapped longitude instead of throwing, so the cursor readout showed a
wrong coordinate where it used to show "—". The stand-in's inverse now
projects the result back and rejects it unless it lands where it came
from, as the October stand-in did. This also covers the camera's world
center, and a new test pins the same check in `ProjectedCOGLayer`.

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

The README's steps for moving to deck.gl v10 keep `pixelToWorld`, which
the app imports from the stand-in. The spec now records the meters-only
scale, the app's wait on `resolveCRS`, and the round-trip check.

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

@kylebarron kylebarron left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There will still be a lot of changes and review before this gets merged into primary project code when v10 is released, but this looks like a good update to align with upstream v10 alphas.

@kylebarron
kylebarron merged commit d22b88d into main Nov 13, 2026
4 checks passed
@kylebarron
kylebarron deleted the kyle/custom-projection-v10-api branch November 13, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant