Skip to content

Commit 8f2cfcd

Browse files
authored
Merge branch 'master' into alasarr/authorization-headers
2 parents 310bfec + 5338f9a commit 8f2cfcd

File tree

7 files changed

+56
-13
lines changed

7 files changed

+56
-13
lines changed

docs/api-reference/geo-layers/tile-layer.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ When the `TileLayer` is used with a geospatial view such as the [MapView](/docs/
8484

8585
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]`.
8686

87+
If you need to offset the `z` level at which the tiles are fetched in order to fetch tiles at a higher resolution in order to produce a "crisper" picture, there is a `zoomOffset` prop.
88+
8789

8890
## Properties
8991

@@ -138,10 +140,17 @@ if (signal.aborted) {
138140

139141
The pixel dimension of the tiles, usually a power of 2.
140142

141-
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.
143+
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.
144+
145+
For non-geospatial viewports, the tile size should correspond to the true pixel size of the tiles.
142146

143147
- Default: `512`
144148

149+
##### `zoomOffset` (Number, optional)
150+
151+
This offset changes the zoom level at which the tiles are fetched. Needs to be an integer.
152+
153+
- Default: `0`
145154

146155
##### `maxZoom` (Number|Null, optional)
147156

docs/upgrade-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The module entry point is now only lightly transpiled for the most commonly used
2424
- `CartoBQTilerLayer` will be deprecated in 8.6. Use `CartoLayer` instead with `type` to `MAP_TYPES.TILESET`.
2525
- `CartoSQLLayer` will be deprecated in 8.6. Use `CartoLayer` instead with `type` to `MAP_TYPES.QUERY`.
2626
- `GeoJsonLayer`'s `getRadius` props is deprecated, replaced by `getPointRadius`.
27+
- It is recommended to use `zoomOffset` in the `TileLayer` when trying to affect the `zoom` resolution at which tiles are fetched.
2728

2829
### onError Callback
2930

examples/website/map-tile/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ export default function App({showBorder = false, onTilesLoad = null}) {
4242
// https://wiki.openstreetmap.org/wiki/Zoom_levels
4343
minZoom: 0,
4444
maxZoom: 19,
45-
tileSize: 512 / devicePixelRatio,
46-
45+
tileSize: 256,
46+
zoomOffset: devicePixelRatio === 1 ? -1 : 0,
4747
renderSubLayers: props => {
4848
const {
4949
bbox: {west, south, east, north}

modules/geo-layers/src/tile-layer/tile-layer.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ const defaultProps = {
2323
maxCacheByteSize: null,
2424
refinementStrategy: STRATEGY_DEFAULT,
2525
zRange: null,
26-
maxRequests: 6
26+
maxRequests: 6,
27+
zoomOffset: 0
2728
};
2829

2930
export default class TileLayer extends CompositeLayer {
@@ -89,7 +90,8 @@ export default class TileLayer extends CompositeLayer {
8990
maxCacheByteSize,
9091
refinementStrategy,
9192
extent,
92-
maxRequests
93+
maxRequests,
94+
zoomOffset
9395
} = props;
9496

9597
return {
@@ -100,7 +102,8 @@ export default class TileLayer extends CompositeLayer {
100102
tileSize,
101103
refinementStrategy,
102104
extent,
103-
maxRequests
105+
maxRequests,
106+
zoomOffset
104107
};
105108
}
106109

modules/geo-layers/src/tile-layer/tileset-2d.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class Tileset2D {
159159

160160
// Returns array of {x, y, z}
161161
getTileIndices({viewport, maxZoom, minZoom, zRange, modelMatrix, modelMatrixInverse}) {
162-
const {tileSize, extent} = this.opts;
162+
const {tileSize, extent, zoomOffset} = this.opts;
163163
return getTileIndices({
164164
viewport,
165165
maxZoom,
@@ -168,7 +168,8 @@ export default class Tileset2D {
168168
tileSize,
169169
extent,
170170
modelMatrix,
171-
modelMatrixInverse
171+
modelMatrixInverse,
172+
zoomOffset
172173
});
173174
}
174175

modules/geo-layers/src/tile-layer/utils.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,12 @@ export function getTileIndices({
177177
extent,
178178
tileSize = TILE_SIZE,
179179
modelMatrix,
180-
modelMatrixInverse
180+
modelMatrixInverse,
181+
zoomOffset = 0
181182
}) {
182183
let z = viewport.isGeospatial
183-
? Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize))
184-
: Math.ceil(viewport.zoom);
184+
? Math.round(viewport.zoom + Math.log2(TILE_SIZE / tileSize)) + zoomOffset
185+
: Math.ceil(viewport.zoom) + zoomOffset;
185186
if (Number.isFinite(minZoom) && z < minZoom) {
186187
if (!extent) {
187188
return [];

test/modules/geo-layers/tile-layer/utils.spec.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,32 @@ const TEST_CASES = [
131131
}),
132132
output: ['2,2,4', '2,3,4', '3,2,4', '3,3,4']
133133
},
134+
{
135+
title: 'non-geospatial with zoom offset',
136+
viewport: new OrthographicView().makeViewport({
137+
width: 800,
138+
height: 400,
139+
viewState: {
140+
target: [100, 100],
141+
zoom: 4
142+
}
143+
}),
144+
zoomOffset: 1,
145+
output: [
146+
'4,5,5',
147+
'4,6,5',
148+
'4,7,5',
149+
'5,5,5',
150+
'5,6,5',
151+
'5,7,5',
152+
'6,5,5',
153+
'6,6,5',
154+
'6,7,5',
155+
'7,5,5',
156+
'7,6,5',
157+
'7,7,5'
158+
]
159+
},
134160
{
135161
title: 'non-geospatial with tile size',
136162
viewport: new OrthographicView().makeViewport({
@@ -295,7 +321,8 @@ test('getTileIndices', t => {
295321
tileSize,
296322
modelMatrix,
297323
extent,
298-
modelMatrixInverse
324+
modelMatrixInverse,
325+
zoomOffset
299326
} = testCase;
300327
const result = getTileIndices({
301328
viewport,
@@ -305,7 +332,8 @@ test('getTileIndices', t => {
305332
tileSize,
306333
modelMatrix,
307334
modelMatrixInverse,
308-
extent
335+
extent,
336+
zoomOffset
309337
});
310338
t.deepEqual(getTileIds(result), testCase.output, testCase.title);
311339
}

0 commit comments

Comments
 (0)