-
-
Notifications
You must be signed in to change notification settings - Fork 707
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
Fix level of detail at high pitch #4779
Draft
NathanMOlson
wants to merge
170
commits into
maplibre:main
Choose a base branch
from
NathanMOlson:lodfix_globe
base: main
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.
+740
−595
Draft
Changes from all commits
Commits
Show all changes
170 commits
Select commit
Hold shift + click to select a range
6132078
Globe - basic infrastructure, raster layer adaptation for globe (#3783)
kubapelc c1886e8
Globe - fill layer (#3882)
kubapelc b9675ca
Merge branch 'main' into globe
HarelM 1754899
Fix build due to bad merge.
HarelM db7eb72
Merge branch 'main' into globe
HarelM cceaebc
Globe - line layer (#3961)
kubapelc 1d1b34e
Merge branch 'main' into globe
HarelM b5d7bba
Merge branch 'main' into globe
HarelM bf4a5b5
Globe - fill extrusion layer (#3968)
kubapelc 66b2262
Kubapelc/globe pr hillshade (#3979)
kubapelc 3e9f933
Merge branch 'main' into globe
HarelM 016d5cf
Merge branch 'main' into globe
HarelM 9fc1183
Merge branch 'main' into globe
HarelM 1ccdb02
Globe - circle and heatmap layers (#4015)
kubapelc c613b60
Merge branch 'main' into globe
HarelM d2d8f75
Improve readibility of build test and fix it.
HarelM 759606a
Globe - symbols & symbol bugfixes (#4067)
kubapelc 9636080
Merge branch 'main' into globe
HarelM a304459
Globe - example images (#4140)
kubapelc ee6ef0d
Globe - clipping fix (#4146)
kubapelc 518041f
Merge branch 'main' into globe
HarelM bd9ac45
Merge branch 'main' into globe
HarelM c7c789a
Fix bad merge
HarelM b503911
Fix lint
HarelM cb2a046
Fix location of old vertex count
HarelM a25074d
replace expected file for terrain changes
HarelM dbf6173
Merge branch 'main' into globe
HarelM 881efb6
Fix rename in main merge branch
HarelM aa2b288
Fix build test
HarelM ba95d93
Merge branch 'main' into globe
HarelM c343c43
Move projection to style class (#4267)
HarelM 3c5e958
Add an Atmosphere layer for Globe (#3888) (#4020)
Pheonor bcd4cfd
Merge branch 'main' into globe
HarelM 91a3043
missing fix from merge
HarelM ec7eb68
Fix lint
HarelM 376b213
Terrain fix (#4343)
kubapelc 09aaf3e
Fix missing image for globe example
HarelM 66d4402
Update atmosphere (#4345)
Pheonor 4b35099
Merge branch 'main' into globe
HarelM 7f23795
Merge branch 'main' into globe
HarelM 9e72755
Globe - transform+projection changes (#4341)
kubapelc 90d8727
Merge branch 'main' into globe
HarelM b83bee8
Fix painter test
HarelM 5fea74a
Merge branch 'main' into globe
HarelM d5709cd
Merge branch 'main' into globe
HarelM 6973a03
Fix lint
HarelM 3e67533
Merge branch 'main' into globe
HarelM f4d7926
Update test/build/min.test.ts
HarelM d3e6374
Merge branch 'main' into globe
HarelM c181cb4
Update changelog
HarelM cc24dd8
Merge branch 'main' into globe
HarelM 2f81dd7
Globe - camera controls (#4408)
kubapelc 06c19e0
Merge branch 'main' into globe
HarelM 7f3220f
Globe: bugfixes: raster layer & projection change (#4546)
kubapelc 8c45af4
Merge branch 'main' into globe
HarelM 359da6c
Merge branch 'main' into globe
kubapelc 0ffbbba
Adapt new heatmap code for globe, update build size
kubapelc b2a98b7
Fix render tests
kubapelc ed1437e
Merge branch 'main' into globe
HarelM b859df9
Globe - custom layers API and examples, globe dev guide (#4577)
kubapelc decd85c
Merge branch 'main' into globe
HarelM 86b9fc3
Globe - Covering tiles (#4615)
kubapelc 38cf5a8
Merge branch 'main' into globe
HarelM 798b7e8
Merge branch 'main' into globe
HarelM f3b7d32
Merge branch 'main' into globe
HarelM 5a6d815
fix typo
HarelM 97dcd88
Merge branch 'main' into globe
HarelM 471c996
Remove sky disabling in examples as this is no longer needed.
HarelM 99d58a8
Merge branch 'main' into globe
HarelM 555ce7b
Fix spelling
HarelM aba2735
Fix spelling - unencode
HarelM ebd791f
Fix more spelling
HarelM 3a1be48
Merge branch 'main' into globe
HarelM d0981a0
Fix lint
HarelM af682a7
add failing unit tests to demonstrate issue #
NathanMOlson e04efc4
fix failing unit tests
NathanMOlson 396464e
formatting
NathanMOlson bbfa12a
better calculation of distanceZ
NathanMOlson ed09a92
update globe transform to calculate zoom level for each individual ti…
NathanMOlson f13b4ef
match behavior from globe to mercator
NathanMOlson 3aa725d
update changelog
NathanMOlson 0ee1c32
fix distance units
NathanMOlson 8a1c9ed
code hygiene
NathanMOlson e3b54e7
fix source_cache unit tests (fix "overscaled" behavior)
NathanMOlson 24ecd8c
fix degrees vs radians
NathanMOlson 53f42b6
load lower resolution tiles for terrain, based on parameter deltaZoom
NathanMOlson 5aa3595
fix failing unit test (caused by radians vs degrees fix)
NathanMOlson 3efe1b2
update terrain shading results
NathanMOlson 8173270
update test results for failing render tests
NathanMOlson 21ae70e
update terrain/default render test
NathanMOlson 6f9bad8
upadte terrain heatmap render test
NathanMOlson 22305b6
fix globe raster-pole e render test by re-incorporating tileSize into…
NathanMOlson d125e59
fix checkerboard render test, which was failing due to a very slight …
NathanMOlson dfcbf2a
aded failing unit test for overscaled tiles
NathanMOlson 04f52e2
fix unit test with z < 0
NathanMOlson b00ad1d
fix render test "projection/globe/collision-text-variable-anchor/pit…
NathanMOlson 49a9c41
code hygiene
NathanMOlson 756b26b
add test that shows zoom levels at high pitch in terrain
NathanMOlson 8730631
actual ptich was limited to 60 degrees, so set it to 60 for clarity
NathanMOlson 7ec03f4
code hygiene
NathanMOlson 5830405
remove osm tiles in terrain render tests and replace with number tiles
NathanMOlson 9e6c0be
fix hardcoded terrain tileSize
NathanMOlson 8b01384
fix unit test
NathanMOlson 4f58b3b
Add parameter to change tile selection behavior at high pitch
NathanMOlson efbaa5c
Merge branch 'main' into lodfix_globe
NathanMOlson ff0be21
remove console.log
NathanMOlson 6ad7a4b
fix bad merge
NathanMOlson 18b5973
code hygiene
NathanMOlson 71a55e9
reduce formatting differences
NathanMOlson 6eaa30e
rearrange mercatorCoveringTiles to be more like globe
NathanMOlson a1d35b0
make globe covering tiles more like mercator
NathanMOlson 9477a2a
make globe more like mercator
NathanMOlson 9ce7d6a
more rearranging
NathanMOlson a083dfb
rearranging
NathanMOlson 8ebb6a3
rearranging
NathanMOlson bdaaac0
rearranging
NathanMOlson 3473302
rearranging
NathanMOlson 033ea68
rearranging
NathanMOlson c37bfc5
rearranging
NathanMOlson 92226e8
more rearranging
NathanMOlson ba08e74
change globeTransform to always return for renderWorldCopies
NathanMOlson b79338b
rearranging
NathanMOlson 9ce373c
fix tile ordering for globe
NathanMOlson b13861c
code hygiene
NathanMOlson 56e26ab
combine globe and mercator coveringTiles() implementations
NathanMOlson c58f1a7
add types
NathanMOlson cb082da
comments
NathanMOlson 87f747d
fix optinal param
NathanMOlson 5495e2c
documentation update
NathanMOlson 8cfe7a9
move coveringTiles helper functions into interface
NathanMOlson a35f112
add return type
NathanMOlson a7ceaf6
always construct TerrainSourceCache with a sourceCache containing _so…
NathanMOlson 301c25d
update render tests
NathanMOlson 433a532
update render test
NathanMOlson a1ecfac
update render test
NathanMOlson 455cb75
update render tests
NathanMOlson 1f243b5
Merge branch 'main' into lodfix_globe
NathanMOlson 261a4a2
Merge branch 'main' into lodfix_globe
NathanMOlson 0d6605e
improve name of pitchBehavior -> pitchTileLoadingBehavior
NathanMOlson ccae1df
add tileZoomDeadband property
NathanMOlson a58651d
lint
NathanMOlson 9acb2f7
default tileZooomDeadband to 0
NathanMOlson 07d309f
Merge branch 'main' into lodfix_globe and resolve conflicts
NathanMOlson b9e491b
update build size
NathanMOlson aa95dd7
Merge branch 'main' into lodfix_globe
NathanMOlson a231a28
fix merge errors
NathanMOlson 7c626cf
adjust build size
NathanMOlson 591773a
Merge branch 'main' into lodfix_globe
NathanMOlson 9dc9797
fix CHANGELOG
NathanMOlson 8b77d4b
Merge branch 'main' into lodfix_globe
NathanMOlson c0679f7
Merge branch 'main' into lodfix_globe
NathanMOlson 94a0a57
move calculateTileZoom() out to its own function, remove top-level pa…
NathanMOlson 386b968
allow overriding definition of calculateTileZoom
NathanMOlson 1a2ed77
Update CHANGELOG.md
NathanMOlson 4bb8544
Update src/geo/projection/covering_tiles.ts
NathanMOlson a6842b0
cameraVFOV -> cameraVerticalFOV
NathanMOlson 8e47b41
move coveringZoomLevel() and CoveringZoomOptions to covering_tiles
NathanMOlson 4b69155
remove unneeded export
NathanMOlson f5fa8aa
move coveringTilesDetails to re-used objects
NathanMOlson d16e54b
Merge branch 'main' into lodfix_globe
NathanMOlson 4925c25
Merge branch 'main' into lodfix_globe
NathanMOlson 4835605
Merge branch 'main' into lodfix_globe
NathanMOlson 1e61f82
Merge branch 'main' into lodfix_globe
NathanMOlson 2fa31f5
Merge branch 'main' into lodfix_globe
NathanMOlson 1855951
fix coveringZoomLevel call
NathanMOlson d23cc33
remove coveringTiles() interface from ITransform
NathanMOlson a2c1e58
Don't allow constant zoom level when the field of view extends near t…
NathanMOlson 8ea60fe
restore missing /2 in calculateTileZoom() FOV adjustment
NathanMOlson 72e365b
fix unit test
NathanMOlson 810855f
limit zoom change with FOV to a factor of 2. (only affects VFOV > 120…
NathanMOlson 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
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,290 @@ | ||
import {OverscaledTileID} from '../../source/tile_id'; | ||
import {Aabb, Frustum, IntersectionResult} from '../../util/primitives'; | ||
import {vec2, vec4} from 'gl-matrix'; | ||
import {IReadonlyTransform} from '../transform_interface'; | ||
import {MercatorCoordinate} from '../mercator_coordinate'; | ||
import {scaleZoom} from '../transform_helper'; | ||
import {clamp, degreesToRadians} from '../../util/util'; | ||
import {Terrain} from '../../render/terrain'; | ||
|
||
type CoveringTilesResult = { | ||
tileID: OverscaledTileID; | ||
distanceSq: number; | ||
tileDistanceToCamera: number; | ||
}; | ||
|
||
type CoveringTilesStackEntry = { | ||
zoom: number; | ||
x: number; | ||
y: number; | ||
wrap: number; | ||
fullyVisible: boolean; | ||
}; | ||
|
||
export type CoveringZoomOptions = { | ||
/** | ||
* Whether to round or floor the target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored. | ||
*/ | ||
roundZoom?: boolean; | ||
/** | ||
* Tile size, expressed in screen pixels. | ||
*/ | ||
tileSize: number; | ||
}; | ||
|
||
export type CoveringTilesOptions = CoveringZoomOptions & { | ||
/** | ||
* Smallest allowed tile zoom. | ||
*/ | ||
minzoom?: number; | ||
/** | ||
* Largest allowed tile zoom. | ||
*/ | ||
maxzoom?: number; | ||
/** | ||
* `true` if tiles should be sent back to the worker for each overzoomed zoom level, `false` if not. | ||
* Fill this option when computing covering tiles for a source. | ||
* When true, any tile at `maxzoom` level that should be overscaled to a greater zoom will have | ||
* its zoom set to the overscaled greater zoom. When false, such tiles will have zoom set to `maxzoom`. | ||
*/ | ||
reparseOverscaled?: boolean; | ||
/** | ||
* When terrain is present, tile visibility will be computed in regards to the min and max elevations for each tile. | ||
*/ | ||
terrain?: Terrain; | ||
/** | ||
* Optional function to redefine how tiles are loaded at high pitch angles. | ||
*/ | ||
calculateTileZoom?: CalculateTileZoomFunction; | ||
}; | ||
|
||
/** | ||
* Function to define how tiles are loaded at high pitch angles | ||
* @param requestedCenterZoom - the requested zoom level, valid at the center point. | ||
* @param distanceToTile2D - 2D distance from the camera to the candidate tile, in mercator units. | ||
* @param distanceToTileZ - vertical distance from the camera to the candidate tile, in mercator units. | ||
* @param distanceToCenter3D - distance from camera to center point, in mercator units | ||
* @param cameraVerticalFOV - camera vertical field of view, in degrees | ||
* @return the desired zoom level for this tile. May not be an integer. | ||
*/ | ||
export type CalculateTileZoomFunction = (requestedCenterZoom: number, | ||
distanceToTile2D: number, | ||
distanceToTileZ: number, | ||
distanceToCenter3D: number, | ||
cameraVerticalFOV: number) => number; | ||
|
||
export interface CoveringTilesDetailsProvider { | ||
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. Should this interface be in a different file? |
||
/** | ||
* Returns the distance from the point to the tile | ||
* @param pointX - point x. | ||
* @param pointY - point y. | ||
* @param tileID - Tile x, y and z for zoom. | ||
* @param aabb - tile AABB | ||
*/ | ||
distanceToTile2d: (pointX: number, pointY: number, tileID: {x: number; y: number; z: number}, aabb: Aabb) => number; | ||
|
||
// Returns the wrap value for a given tile. | ||
getWrap: (centerCoord: MercatorCoordinate, tileID: {x:number; y: number; z: number}, parentWrap: number) => number; | ||
|
||
/** | ||
* Returns the AABB of the specified tile. | ||
* @param tileID - Tile x, y and z for zoom. | ||
* @param wrap - wrap number of the tile. | ||
* @param elevation - camera center point elevation. | ||
* @param options - CoveringTilesOptions. | ||
*/ | ||
getTileAABB: (tileID: {x: number; y: number; z: number}, wrap: number, elevation: number, options: CoveringTilesOptions) => Aabb; | ||
|
||
/** | ||
* Whether to allow variable zoom, which is used at high pitch angle to avoid loading an excessive amount of tiles. | ||
*/ | ||
allowVariableZoom: (transform: IReadonlyTransform, options: CoveringTilesOptions) => boolean; | ||
} | ||
|
||
/** | ||
* A simple/heuristic function that returns whether the tile is visible under the current transform. | ||
* @returns an {@link IntersectionResult}. | ||
*/ | ||
export function isTileVisible(frustum: Frustum, aabb: Aabb, plane?: vec4): IntersectionResult { | ||
|
||
const frustumTest = aabb.intersectsFrustum(frustum); | ||
if (!plane) { | ||
NathanMOlson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return frustumTest; | ||
} | ||
const planeTest = aabb.intersectsPlane(plane); | ||
|
||
if (frustumTest === IntersectionResult.None || planeTest === IntersectionResult.None) { | ||
return IntersectionResult.None; | ||
} | ||
|
||
if (frustumTest === IntersectionResult.Full && planeTest === IntersectionResult.Full) { | ||
return IntersectionResult.Full; | ||
} | ||
|
||
return IntersectionResult.Partial; | ||
} | ||
|
||
function calculateTileZoom(requestedCenterZoom: number, | ||
distanceToTile2D: number, | ||
distanceToTileZ: number, | ||
distanceToCenter3D: number, | ||
cameraVerticalFOV: number) : number { | ||
/** | ||
* Controls how tiles are loaded at high pitch angles. Higher numbers cause fewer, lower resolution | ||
* tiles to be loaded. At 0, tiles are loaded with approximately constant screen X resolution. | ||
* At 1, tiles are loaded with approximately constant screen area. | ||
* At 2, tiles are loaded with approximately constant screen Y resolution. | ||
*/ | ||
const pitchTileLoadingBehavior = 1.0; | ||
/** | ||
* Controls how tiles are loaded at high pitch angles. Controls how different the distance to a tile must be (compared with the center point) | ||
* before a new zoom level is requested. For example, if tileZoomDeadband = 1 and the center zoom is 14, tiles distant enough to be loaded at | ||
* z13 will be loaded at z14, and tiles distant enough to be loaded at z14 will be loaded at z15. A higher number causes more tiles to be loaded | ||
* at the center zoom level. This also results in more tiles being loaded overall. | ||
*/ | ||
const tileZoomDeadband = 0.0; | ||
let thisTileDesiredZ = requestedCenterZoom; | ||
const thisTilePitch = Math.atan(distanceToTile2D / distanceToTileZ); | ||
const distanceToTile3D = Math.hypot(distanceToTile2D, distanceToTileZ); | ||
// if distance to candidate tile is a tiny bit farther than distance to center, | ||
// use the same zoom as the center. This is achieved by the scaling distance ratio by cos(fov/2) | ||
thisTileDesiredZ = requestedCenterZoom + scaleZoom(distanceToCenter3D / distanceToTile3D / Math.max(0.5, Math.cos(degreesToRadians(cameraVerticalFOV / 2)))); | ||
thisTileDesiredZ += pitchTileLoadingBehavior * scaleZoom(Math.cos(thisTilePitch)) / 2; | ||
thisTileDesiredZ = thisTileDesiredZ + clamp(requestedCenterZoom - thisTileDesiredZ, -tileZoomDeadband, tileZoomDeadband); | ||
return thisTileDesiredZ; | ||
} | ||
|
||
/** | ||
* Return what zoom level of a tile source would most closely cover the tiles displayed by this transform. | ||
* @param options - The options, most importantly the source's tile size. | ||
* @returns An integer zoom level at which all tiles will be visible. | ||
*/ | ||
export function coveringZoomLevel(transform: IReadonlyTransform, options: CoveringZoomOptions): number { | ||
const z = (options.roundZoom ? Math.round : Math.floor)( | ||
transform.zoom + scaleZoom(transform.tileSize / options.tileSize) | ||
); | ||
// At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist. | ||
return Math.max(0, z); | ||
} | ||
|
||
/** | ||
* Returns a list of tiles that optimally covers the screen. Adapted for globe projection. | ||
* Correctly handles LOD when moving over the antimeridian. | ||
* @param transform - The transform instance. | ||
* @param frustum - The covering frustum. | ||
* @param plane - The clipping plane used by globe transform, or null. | ||
* @param cameraCoord - The x, y, z position of the camera in MercatorCoordinates. | ||
* @param cameraCoord - The x, y, z position of the center point in MercatorCoordinates. | ||
* @param options - Additional coveringTiles options. | ||
* @param details - Interface to define required helper functions. | ||
* @returns A list of tile coordinates, ordered by ascending distance from camera. | ||
*/ | ||
export function coveringTiles(transform: IReadonlyTransform, options: CoveringTilesOptions): OverscaledTileID[] { | ||
const frustum = transform.getCameraFrustum(); | ||
const plane = transform.getClippingPlane(); | ||
const cameraCoord = transform.screenPointToMercatorCoordinate(transform.getCameraPoint()); | ||
const centerCoord = MercatorCoordinate.fromLngLat(transform.center, transform.elevation); | ||
cameraCoord.z = centerCoord.z + Math.cos(transform.pitchInRadians) * transform.cameraToCenterDistance / transform.worldSize; | ||
const detailsProvider = transform.getCoveringTilesDetailsProvider(); | ||
const allowVariableZoom = detailsProvider.allowVariableZoom(transform, options); | ||
|
||
const desiredZ = coveringZoomLevel(transform, options); | ||
const minZoom = options.minzoom || 0; | ||
const maxZoom = options.maxzoom !== undefined ? options.maxzoom : transform.maxZoom; | ||
const nominalZ = Math.min(Math.max(0, desiredZ), maxZoom); | ||
|
||
const numTiles = Math.pow(2, nominalZ); | ||
const cameraPoint = [numTiles * cameraCoord.x, numTiles * cameraCoord.y, 0]; | ||
const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0]; | ||
const distanceToCenter2d = Math.hypot(centerCoord.x - cameraCoord.x, centerCoord.y - cameraCoord.y); | ||
const distanceZ = Math.abs(centerCoord.z - cameraCoord.z); | ||
const distanceToCenter3d = Math.hypot(distanceToCenter2d, distanceZ); | ||
|
||
const newRootTile = (wrap: number): CoveringTilesStackEntry => { | ||
return { | ||
zoom: 0, | ||
x: 0, | ||
y: 0, | ||
wrap, | ||
fullyVisible: false | ||
}; | ||
}; | ||
|
||
// Do a depth-first traversal to find visible tiles and proper levels of detail | ||
const stack: Array<CoveringTilesStackEntry> = []; | ||
const result: Array<CoveringTilesResult> = []; | ||
|
||
if (transform.renderWorldCopies) { | ||
// Render copy of the globe thrice on both sides | ||
for (let i = 1; i <= 3; i++) { | ||
stack.push(newRootTile(-i)); | ||
stack.push(newRootTile(i)); | ||
} | ||
} | ||
|
||
stack.push(newRootTile(0)); | ||
|
||
while (stack.length > 0) { | ||
const it = stack.pop(); | ||
const x = it.x; | ||
const y = it.y; | ||
let fullyVisible = it.fullyVisible; | ||
const tileID = {x, y, z: it.zoom}; | ||
const aabb = detailsProvider.getTileAABB(tileID, it.wrap, transform.elevation, options); | ||
|
||
// Visibility of a tile is not required if any of its ancestor is fully visible | ||
if (!fullyVisible) { | ||
const intersectResult = isTileVisible(frustum, aabb, plane); | ||
|
||
if (intersectResult === IntersectionResult.None) | ||
continue; | ||
|
||
fullyVisible = intersectResult === IntersectionResult.Full; | ||
} | ||
|
||
const distToTile2d = detailsProvider.distanceToTile2d(cameraCoord.x, cameraCoord.y, tileID, aabb); | ||
|
||
let thisTileDesiredZ = desiredZ; | ||
if (allowVariableZoom) { | ||
const tileZoomFunc = options.calculateTileZoom || calculateTileZoom; | ||
thisTileDesiredZ = tileZoomFunc(transform.zoom + scaleZoom(transform.tileSize / options.tileSize), | ||
distToTile2d, | ||
distanceZ, | ||
distanceToCenter3d, | ||
transform.fov); | ||
} | ||
thisTileDesiredZ = (options.roundZoom ? Math.round : Math.floor)(thisTileDesiredZ); | ||
thisTileDesiredZ = Math.max(0, thisTileDesiredZ); | ||
const z = Math.min(thisTileDesiredZ, maxZoom); | ||
|
||
// We need to compute a valid wrap value for the tile to keep globe compatibility with mercator | ||
it.wrap = detailsProvider.getWrap(centerCoord, tileID, it.wrap); | ||
|
||
// Have we reached the target depth? | ||
if (it.zoom >= z) { | ||
if (it.zoom < minZoom) { | ||
continue; | ||
} | ||
const dz = nominalZ - it.zoom; | ||
const dx = cameraPoint[0] - 0.5 - (x << dz); | ||
const dy = cameraPoint[1] - 0.5 - (y << dz); | ||
const overscaledZ = options.reparseOverscaled ? thisTileDesiredZ : it.zoom; | ||
result.push({ | ||
tileID: new OverscaledTileID(it.zoom === maxZoom ? overscaledZ : it.zoom, it.wrap, it.zoom, x, y), | ||
distanceSq: vec2.sqrLen([centerPoint[0] - 0.5 - x, centerPoint[1] - 0.5 - y]), | ||
// this variable is currently not used, but may be important to reduce the amount of loaded tiles | ||
tileDistanceToCamera: Math.sqrt(dx * dx + dy * dy) | ||
}); | ||
continue; | ||
} | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const childX = (x << 1) + (i % 2); | ||
const childY = (y << 1) + (i >> 1); | ||
const childZ = it.zoom + 1; | ||
stack.push({zoom: childZ, x: childX, y: childY, wrap: it.wrap, fullyVisible}); | ||
} | ||
} | ||
|
||
return result.sort((a, b) => a.distanceSq - b.distanceSq).map(a => a.tileID); | ||
} |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is mercator units?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"mercator units" are described in
custom_style_layer.ts
line 96. Here's the most relevant part of the description:For this function, the units don't actually matter as long as
distanceToTile2D
,distanceToTileZ
, anddistanceToCenter3D
are all given in the same units. I think it's best to specify units though? Or we could change the inputs to be ratios (distanceToTile2D/distanceToCenter3D
anddistanceToTileZ/distanceToCenter3D
) but that seems less clear.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Units are very important, I just didn't know what it meant.
If there's an easy way to link to what you wrote here it will be great, or link to a class/type that is relevant.
Totally optional.