Skip to content

fix(geo-layers): remap Web Mercator terrain tiles on GlobeView - #10350

Open
charlieforward9 wants to merge 20 commits into
masterfrom
cr/fix-globe-mercator-tiles
Open

charlieforward9 wants to merge 20 commits into
masterfrom
cr/fix-globe-mercator-tiles

Conversation

@charlieforward9

@charlieforward9 charlieforward9 commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Under GlobeView, tiled TerrainLayer meshes come from the loader with rows spaced linearly in latitude, but Web Mercator tile images are spaced in Mercator Y. Imagery and elevation slide north–south within each tile.

Change List

  • TerrainLayer: remap Web Mercator mesh rows to longitude/latitude on globes
    • Copies the loader output instead of mutating it
    • Detects globes by the viewport CRS's geocentric frame
  • Type the terrain mesh, replacing any casts
  • BitmapLayer: test rebuilding across GlobeView's zoom-12 switch
  • Unit tests
projection-warping.mov

Verified with the tileset-2d, tile-layer, terrain-layer and bitmap-layer headless tests and the terrain-layer, bitmap-layer and mvt-layer render tests.

@coveralls

coveralls commented Jun 6, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 84.158% (+0.001%) from 84.157% — cr/fix-globe-mercator-tiles into master

@chrisgervang chrisgervang 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.

The fix looks good. Let's consider how to make this generalized for other layers that may need the same correction

@chrisgervang chrisgervang mentioned this pull request Jun 11, 2026
13 of 59 tasks
@chrisgervang chrisgervang added this to the v9.4 milestone Jun 11, 2026
@charlieforward9 charlieforward9 self-assigned this Jun 13, 2026
@charlieforward9 charlieforward9 mentioned this pull request Jun 23, 2026
14 of 35 tasks
@charlieforward9

This comment has been minimized.

…or-tiles

# Conflicts:
#	modules/geo-layers/src/terrain-layer/terrain-layer.ts

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@copilot resolver los conflictos de combinación en esta rama.

Done — merged origin/master into this branch and resolved the one conflict in terrain-layer.ts. The only changes needed were:

  • Remove the duplicate _GlobeViewport bare import (master renamed it to _GlobeViewport as GlobeViewport)
  • Remove the duplicate COORDINATE_SYSTEM import our branch had added
  • Update import type {Mesh} → import type {MeshAttributes} and propagate that rename through all type aliases, state declarations, and function signatures to match master's loaders.gl upgrade

@charlieforward9

Copy link
Copy Markdown
Member Author

@copilot CI hurtin

Copilot AI commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

@copilot CI hurtin

Fixed in the latest commit. The CI failures were TypeScript errors introduced during the merge conflict resolution — I incorrectly replaced Mesh with MeshAttributes without accounting for the difference: MeshAttributes is an index type {[k: string]: MeshAttribute}, so TypeScript resolves mesh.attributes as MeshAttribute (the individual attribute value type, not the nested attributes dict). The terrain loader actually returns {attributes: {POSITION: ..., TEXCOORD_0: ...}, header: {...}} at runtime. Fixed by using (mesh as any).attributes casts in remapTerrainMeshToWebMercatorTile and // @ts-ignore + MeshWithBoundingBox cast in onViewportLoad, following the same pattern master already uses for the header.boundingBox access.

@greptile-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

The PR remaps Web Mercator terrain rows for globe views while preserving the loader’s original mesh.

  • Globe terrain tiles place their rows using Web Mercator spacing.
  • Bitmap tests cover switching from a map view to a globe and back.

Reviews (7) · Last reviewed commit: "fix(layers): rely on projectionChanged t..." · Reviewed by Greptile

@charlieforward9

Copy link
Copy Markdown
Member Author

@chrisgervang I revisited this and moved the bitmap fix out of TileLayer entirely.

The common quality is not "tile sublayer." It is a layer whose mesh sampling depends on the curved viewport's resolution, paired with an explicit source-coordinate contract. BitmapLayer already owns both: callers identify Web Mercator imagery with _imageCoordinateSystem: COORDINATE_SYSTEM.CARTESIAN, and BitmapLayer now rebuilds its mesh and coordinate uniforms when the viewport resolution changes. Subclasses inherit that behavior directly—there is no instanceof check, clone override, new TileLayer prop, or globe-specific cache path.

Terrain keeps its independent Web Mercator row remap in TerrainLayer, and it uses the same viewport capability instead of checking the GlobeViewport class.

I added a CustomBitmapLayer MapView -> GlobeView -> MapView regression. The live exact-head run moves from 6 vertices / conversion 0, to a tessellated mesh / conversion 1, and back to 6 / 0 with no console errors. Focused tests are 15/15; build, lint, and website checks pass on f6f9b2ea83.

@greptile-apps

greptile-apps Bot commented Aug 26, 2026

Copy link
Copy Markdown

Want your agent to iterate on Greptile's feedback? Try greploops.

Master now picks the BitmapLayer mesh by subdivision step and image
coordinates by viewport CRS (#10742, #10874), so this branch keeps that
logic and adds only the shouldUpdateState override: a viewport change
alone (GlobeView crossing zoom 12) does not flag props, so the mesh and
coordinate conversion were never rebuilt for tiles reused across it.

GlobeView's resolution now defaults to 0 (no subdivision), so
TerrainLayer detects a globe by the viewport CRS's geocentric frame, as
SolidPolygonLayer does, instead of by resolution. The BitmapLayer test
builds its GlobeViewport with resolution 10, as GlobeView({resolution})
would, and passes image coordinates as 'cartesian' now that
COORDINATE_SYSTEM is no longer exported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
charlieforward9 and others added 3 commits October 25, 2026 23:06
The onViewportLoad callback received each tile's [mesh, texture] pair as
`arr`. Rename it to `tileContent` so readers can tell what it holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #10874, switching between GlobeViewport and WebMercatorViewport sets
changeFlags.projectionChanged, which already triggers BitmapLayer's mesh rebuild.
The shouldUpdateState override only added an update on every pan and zoom.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
charlieforward9 added a commit that referenced this pull request Oct 26, 2026
Coverage LOD raised its minimum prefetch and placeholder zooms when
`viewport.resolution` was set, which used to mean GlobeViewport. Since
#10874, `resolution` is a subdivision setting on every View and defaults
to 0 in GlobeView, so globes lost the floors and flat views with
subdivision gained them. The tests' getter-only `resolution` override
also throws now that Viewport assigns the field.

Detect globes by the viewport's geocentric target CRS, as #10350 does,
and test against a real GlobeViewport.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@charlieforward9 charlieforward9 changed the title [geo-layers] Fix GlobeView Mercator tile warping fix(geo-layers): remap Web Mercator terrain tiles on GlobeView (1/2) Oct 26, 2026

@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.

Reviewed the current head. CI passes and there are no unresolved review threads. I found no blocker; this looks ready for approval. Keep the stated stack order with #10306, which also changes TerrainLayer.

@charlieforward9
charlieforward9 removed this pull request from stack #10929 November 18, 2026 00:23
@charlieforward9 charlieforward9 changed the title fix(geo-layers): remap Web Mercator terrain tiles on GlobeView (1/2) fix(geo-layers): remap Web Mercator terrain tiles on GlobeView Nov 18, 2026
@ibgreen ibgreen added the bug label Nov 21, 2026

This branch has not been deployed

No deployments
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.

6 participants