-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[geo-layers] Fix GlobeView Mercator tile warping #10350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
charlieforward9
wants to merge
5
commits into
master
Choose a base branch
from
cr/fix-globe-mercator-tiles
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e18ee8d
Fix terrain globe Mercator tile warping
charlieforward9 8c3cac8
Fix bitmap tile warping in GlobeView
charlieforward9 dd962f8
Address terrain globe Mercator review comments
charlieforward9 e1d2fc5
Address GlobeView review feedback
charlieforward9 ec2e1a5
Clarify GlobeView terrain remap scope
charlieforward9 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,13 @@ import { | |
| } from '@deck.gl/core'; | ||
| import {SimpleMeshLayer} from '@deck.gl/mesh-layers'; | ||
| import {COORDINATE_SYSTEM} from '@deck.gl/core'; | ||
| import type {MeshAttributes} from '@loaders.gl/schema'; | ||
| import type {Mesh} from '@loaders.gl/schema'; | ||
| import {TerrainWorkerLoader} from '@loaders.gl/terrain'; | ||
| import { | ||
| MAX_LATITUDE as MAX_WEB_MERCATOR_LATITUDE, | ||
| lngLatToWorld, | ||
| worldToLngLat | ||
| } from '@math.gl/web-mercator'; | ||
| import TileLayer, {TileLayerProps} from '../tile-layer/tile-layer'; | ||
| import type { | ||
| Bounds, | ||
|
|
@@ -108,12 +113,13 @@ type TerrainLoadProps = { | |
| elevationData: string | null; | ||
| elevationDecoder: ElevationDecoder; | ||
| meshMaxError: number; | ||
| remapToWebMercatorTile?: boolean; | ||
| signal?: AbortSignal; | ||
| }; | ||
|
|
||
| type MeshAndTexture = [MeshAttributes | null, TextureSource | null]; | ||
| type MeshAndTexture = [Mesh | null, TextureSource | null]; | ||
| type MeshBoundingBox = [min: number[], max: number[]]; | ||
| type MeshWithBoundingBox = MeshAttributes & { | ||
| type MeshWithBoundingBox = Mesh & { | ||
| header?: { | ||
| boundingBox?: MeshBoundingBox; | ||
| }; | ||
|
|
@@ -165,7 +171,7 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
|
|
||
| state!: { | ||
| isTiled?: boolean; | ||
| terrain?: MeshAttributes; | ||
| terrain?: Mesh; | ||
| zRange?: ZRange | null; | ||
| }; | ||
|
|
||
|
|
@@ -203,8 +209,9 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
| bounds, | ||
| elevationDecoder, | ||
| meshMaxError, | ||
| remapToWebMercatorTile, | ||
| signal | ||
| }: TerrainLoadProps): Promise<MeshAttributes> | null { | ||
| }: TerrainLoadProps): Promise<Mesh> | null { | ||
| if (!elevationData) { | ||
| return null; | ||
| } | ||
|
|
@@ -221,7 +228,16 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
| } | ||
| }; | ||
| const {fetch} = this.props; | ||
| return fetch(elevationData, {propName: 'elevationData', layer: this, loadOptions, signal}); | ||
| const terrain = fetch(elevationData, { | ||
| propName: 'elevationData', | ||
| layer: this, | ||
| loadOptions, | ||
| signal | ||
| }); | ||
|
|
||
| return remapToWebMercatorTile | ||
| ? terrain.then(mesh => (mesh ? remapMeshToWebMercatorTile(mesh, bounds) : mesh)) | ||
| : terrain; | ||
| } | ||
|
|
||
| getTiledTerrainData(tile: TileLoadProps): Promise<MeshAndTexture> { | ||
|
|
@@ -243,19 +259,18 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
| topRight = [bbox.right, bbox.top]; | ||
| } | ||
| const bounds: Bounds = [bottomLeft[0], bottomLeft[1], topRight[0], topRight[1]]; | ||
| const overlappedBounds = getOverlappedBounds( | ||
| bounds, | ||
| this.props.tileSize, | ||
| Boolean(viewport.resolution && viewport.resolution > 0) | ||
| ); | ||
|
|
||
| const terrain = this.loadTerrain({ | ||
| elevationData: dataUrl, | ||
| bounds: overlappedBounds, | ||
| elevationDecoder, | ||
| meshMaxError, | ||
| signal | ||
| }); | ||
| const isGlobe = Boolean(viewport.resolution && viewport.resolution > 0); | ||
| const overlappedBounds = getOverlappedBounds(bounds, this.props.tileSize, isGlobe); | ||
|
|
||
| const terrain = | ||
| this.loadTerrain({ | ||
| elevationData: dataUrl, | ||
| bounds: overlappedBounds, | ||
| elevationDecoder, | ||
| meshMaxError, | ||
| remapToWebMercatorTile: isGlobe, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All tile sublayers rendered on a globe trigger the remap. Is it true that only the built-in bitmap layer gets modified by this, or would other sublayers get remapped too? |
||
| signal | ||
| }) ?? Promise.resolve(null); | ||
| const surface = textureUrl | ||
| ? // If surface image fails to load, the tile should still be displayed | ||
| fetch(textureUrl, {propName: 'texture', layer: this, loaders: [], signal}).catch(_ => null) | ||
|
|
@@ -319,11 +334,9 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
| const {zRange} = this.state; | ||
| const ranges = tiles | ||
| .map(tile => tile.content) | ||
| .filter(Boolean) | ||
| .map(arr => { | ||
| // @ts-ignore | ||
| const bounds = arr[0].header.boundingBox; | ||
| return bounds.map(bound => bound[2]); | ||
| .flatMap(arr => { | ||
| const bounds = arr?.[0]?.header?.boundingBox; | ||
| return bounds ? [bounds.map(bound => bound[2])] : []; | ||
| }); | ||
| if (ranges.length === 0) { | ||
| return; | ||
|
|
@@ -417,3 +430,43 @@ export default class TerrainLayer<ExtraPropsT extends {} = {}> extends Composite | |
|
|
||
| const isTileSetURL = (url: string): boolean => | ||
| url.includes('{x}') && (url.includes('{y}') || url.includes('{-y}')); | ||
|
|
||
| function remapMeshToWebMercatorTile(mesh: Mesh, bounds: Bounds): Mesh { | ||
| const positionAttribute = mesh.attributes.POSITION; | ||
| const texCoordAttribute = mesh.attributes.TEXCOORD_0; | ||
| const positions = positionAttribute?.value; | ||
| const texCoords = texCoordAttribute?.value; | ||
| if (!positions || !texCoords) { | ||
| return mesh; | ||
| } | ||
|
|
||
| const [, south, , north] = bounds; | ||
| const northY = lngLatToMercatorWorldY(north); | ||
| const southY = lngLatToMercatorWorldY(south); | ||
| const remappedPositions = new Float32Array(positions); | ||
|
|
||
| for (let i = 0; i < texCoords.length / 2; i++) { | ||
| const v = texCoords[i * 2 + 1]; | ||
| const mercatorY = northY + (southY - northY) * v; | ||
| remappedPositions[i * 3 + 1] = worldToLngLat([0, mercatorY])[1]; | ||
| } | ||
|
|
||
| return { | ||
| ...mesh, | ||
| attributes: { | ||
| ...mesh.attributes, | ||
| POSITION: { | ||
| ...positionAttribute, | ||
| value: remappedPositions | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| function lngLatToMercatorWorldY(latitude: number): number { | ||
| const clampedLatitude = Math.max( | ||
| -MAX_WEB_MERCATOR_LATITUDE, | ||
| Math.min(MAX_WEB_MERCATOR_LATITUDE, latitude) | ||
| ); | ||
| return lngLatToWorld([0, clampedLatitude])[1]; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.