-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
TileLayer: add zoomOffset prop #5896
Changes from 3 commits
987c759
0329f45
befd681
6c0fdec
53f8e4e
f8045cd
478b795
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ At each integer zoom level (`z`), the XY plane in the view space is divided into | |
|
||
When the `TileLayer` is used with a geospatial view such as the [MapView](/docs/api-reference/core/map-view.md), x, y, and z are determined from [the OSM tile index](https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames). | ||
|
||
When the `TileLayer` is used used with a non-geospatial view such as the [OrthographicView](/docs/api-reference/core/orthographic-view.md) or the [OrbitView](/docs/api-reference/core/orbit-view.md), `x` and `y` increment from the world origin, and each tile's width and height match that defined by the `tileSize` prop. For example, the tile `x: 0, y: 0` occupies the square between `[0, 0]` and `[tileSize, tileSize]`. | ||
When the `TileLayer` is used used with a non-geospatial view such as the [OrthographicView](/docs/api-reference/core/orthographic-view.md) or the [OrbitView](/docs/api-reference/core/orbit-view.md), `x` and `y` increment from the world origin, and each tile's width and height match that defined by the `tileSize` prop. For example, the tile `x: 0, y: 0` occupies the square between `[0, 0]` and `[tileSize, tileSize]`. If you need to offset the `z` level at which the tiles are fetched, there is a `tileOffset` prop. | ||
|
||
|
||
## Properties | ||
|
@@ -138,10 +138,17 @@ if (signal.aborted) { | |
|
||
The pixel dimension of the tiles, usually a power of 2. | ||
|
||
The tile size represents the target pixel width and height of each tile when rendered. Smaller tile sizes display the content at higher resolution, while the layer needs to load more tiles to fill the same viewport. | ||
For geospatial viewports, tile size represents the target pixel width and height of each tile when rendered. Smaller tile sizes display the content at higher resolution, while the layer needs to load more tiles to fill the same viewport. | ||
Pessimistress marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For non-geospatial viewports, the tile size should correspond to the true pixel size of the tiles. | ||
|
||
- Default: `512` | ||
|
||
##### `tileOffset` (Number, optional) | ||
|
||
For non-geospatial viewports, this offset changes the zoom level at which the tiles are fetched. | ||
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. Additional changes:
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. The last one doesn't quite work that way, I think. I need to think about this a bit. I think the issue might be the 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. On second thought, this isn't really how I intended this prop to be used. It is meant more for fetching tiles at a higher or lower resolution given the current zoom level. So changing this prop independent of other things just changes the resolution of the image but this 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. The map-tiles use case makes sense to me though, but maybe I am missing something. There, previously, we were actually intentionally affecting the resolution. 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. Maybe we should clamp z to 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. I think that is a good call. This affects the level of fetching, not the viewport to which 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. One issue this could cause would be if you zoom into zoom level 0 with 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. Re-requesting review. Added a note to the docs. |
||
|
||
- Default: `0` | ||
ilan-gold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
##### `maxZoom` (Number|Null, optional) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,8 +117,8 @@ function getIndexingCoords(bbox, scale, modelMatrixInverse) { | |
return bbox.map(i => (i * scale) / TILE_SIZE); | ||
} | ||
|
||
function getScale(z) { | ||
return Math.pow(2, z); | ||
function getScale(z, tileSize = TILE_SIZE) { | ||
return (Math.pow(2, z) * TILE_SIZE) / tileSize; | ||
} | ||
|
||
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames#Lon..2Flat._to_tile_numbers_2 | ||
|
@@ -130,25 +130,24 @@ export function osmTile2lngLat(x, y, z) { | |
return [lng, lat]; | ||
} | ||
|
||
function tile2XY(x, y, z) { | ||
const scale = getScale(z); | ||
function tile2XY(x, y, z, tileSize) { | ||
const scale = getScale(z, tileSize); | ||
return [(x / scale) * TILE_SIZE, (y / scale) * TILE_SIZE]; | ||
} | ||
|
||
export function tileToBoundingBox(viewport, x, y, z) { | ||
export function tileToBoundingBox(viewport, x, y, z, tileSize = TILE_SIZE) { | ||
if (viewport.isGeospatial) { | ||
const [west, north] = osmTile2lngLat(x, y, z); | ||
const [east, south] = osmTile2lngLat(x + 1, y + 1, z); | ||
return {west, north, east, south}; | ||
} | ||
const [left, top] = tile2XY(x, y, z); | ||
const [right, bottom] = tile2XY(x + 1, y + 1, z); | ||
const [left, top] = tile2XY(x, y, z, tileSize); | ||
const [right, bottom] = tile2XY(x + 1, y + 1, z, tileSize); | ||
return {left, top, right, bottom}; | ||
} | ||
|
||
function getIdentityTileIndices(viewport, z, extent, modelMatrixInverse) { | ||
function getIdentityTileIndices(viewport, z, tileSize, extent, modelMatrixInverse) { | ||
const bbox = getBoundingBox(viewport, null, extent); | ||
const scale = getScale(z); | ||
const scale = getScale(z, tileSize); | ||
const [minX, minY, maxX, maxY] = getIndexingCoords(bbox, scale, modelMatrixInverse); | ||
const indices = []; | ||
|
||
|
@@ -178,9 +177,12 @@ export function getTileIndices({ | |
extent, | ||
tileSize = TILE_SIZE, | ||
modelMatrix, | ||
modelMatrixInverse | ||
modelMatrixInverse, | ||
tileOffset = 0 | ||
}) { | ||
let z = Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize)); | ||
let z = viewport.isGeospatial | ||
? Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize)) | ||
: Math.ceil(viewport.zoom) + tileOffset; | ||
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. Another option here would be |
||
if (Number.isFinite(minZoom) && z < minZoom) { | ||
if (!extent) { | ||
return []; | ||
|
@@ -196,7 +198,13 @@ export function getTileIndices({ | |
} | ||
return viewport.isGeospatial | ||
? getOSMTileIndices(viewport, z, zRange, extent || DEFAULT_EXTENT) | ||
: getIdentityTileIndices(viewport, z, transformedExtent || DEFAULT_EXTENT, modelMatrixInverse); | ||
: getIdentityTileIndices( | ||
viewport, | ||
z, | ||
tileSize, | ||
transformedExtent || DEFAULT_EXTENT, | ||
modelMatrixInverse | ||
); | ||
} | ||
|
||
/** | ||
|
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.
This actually seemed more reflective of the state of things now than before. Before both methods used the OSM index, from what I can tell, but now the infovis obeys the above.