Skip to content

Render in custom MapLibre projections (addProjection) - #105

Merged
Shane98c merged 8 commits into
mainfrom
feat/custom-projections
Nov 6, 2026
Merged

Shane98c merged 8 commits into
mainfrom
feat/custom-projections

Conversation

@Shane98c

@Shane98c Shane98c commented Nov 4, 2026

Copy link
Copy Markdown
Member

Renders in map projections registered with MapLibre's experimental addProjection (maplibre-gl ≥ 6.15), such as EPSG:3031. Apps pass the layer the same projection objects in a new mapProjections option:

const antarctic: CRS = {
  name: 'EPSG:3031',
  projection: proj4('EPSG:4326', EPSG_3031_PROJ4),
  tileMatrixSet: { origin: [-4194304, 4194304], extentAtZoom0: 8388608 },
}
addProjection(antarctic)
map.setProjection({ type: 'EPSG:3031' })
map.addLayer(new ZarrLayer({ ...options, mapProjections: [antarctic] }))

How it works

  • World mapping (src/[world-mapping.ts](https://github.com/tmp/cproj/src/world-mapping.ts)): computes positions in the projection's world square from its definition.
  • Meshes (createWorldMesh): built directly in the world square and refined where the projection bends. Triangles that cross a seam or that the projection can't place are dropped.
  • Region and level selection: works from each tile's footprint in the world square, including 0–360° data and far poles.
  • Projection switches rebuild region geometry without refetching data.
  • The layer hides and warns once if the map is in a registered projection it wasn't given.

Also in this PR

  • Fixes a 1px gap where a tile edge lies exactly on a region edge, in all projections.
  • Demo: Antarctic and Arctic polar stereographic, plate carrée, Equal Earth and CONUS Albers, over Natural Earth GeoJSON. Demo moves to maplibre-gl 6.16 and adds proj4.
  • README: new "custom map projections" section.

Limitations

  • MapLibre only. Mapbox doesn't draw custom layers outside mercator and globe.
  • Basemap and terrain tiles must be in the same CRS as the map. The demo's DEM is Web Mercator, so terrain stays off in custom projections.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
zarr-layer Ready Ready Preview Nov 4, 2026 4:06am UTC

Request Review

@Shane98c
Shane98c merged commit aa98d51 into main Nov 6, 2026
10 checks passed
@Shane98c
Shane98c deleted the feat/custom-projections branch November 6, 2026 02:47

This branch was successfully deployed

1 active deployment
Preview — a7bcd575 Deployed Nov 4, 2026 by vercel[bot]
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.

1 participant