Skip to content
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

allow rendering full world smaller than 512px #9028

Merged
merged 7 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,11 @@ class Transform {
* @returns {number} zoom level
*/
coveringZoomLevel(options: {roundZoom?: boolean, tileSize: number}) {
return (options.roundZoom ? Math.round : Math.floor)(
const z = (options.roundZoom ? Math.round : Math.floor)(
this.zoom + this.scaleZoom(this.tileSize / options.tileSize)
);
// At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.
return Math.max(0, z);
}

/**
Expand Down
9 changes: 1 addition & 8 deletions src/source/source_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,13 +317,6 @@ class SourceCache extends Evented {
return this._tiles[id];
}

/**
* get the zoom level adjusted for the difference in map and source tilesizes
*/
getZoom(transform: Transform): number {
return transform.zoom + transform.scaleZoom(transform.tileSize / this._source.tileSize);
}

/**
* For a given set of tiles, retain children that are loaded and have a zoom
* between `zoom` (exclusive) and `maxCoveringZoom` (inclusive)
Expand Down Expand Up @@ -487,7 +480,7 @@ class SourceCache extends Evented {
}

// Determine the overzooming/underzooming amounts.
const zoom = (this._source.roundZoom ? Math.round : Math.floor)(this.getZoom(transform));
const zoom = transform.coveringZoomLevel(this._source);
const minCoveringZoom = Math.max(zoom - SourceCache.maxOverzooming, this._source.minzoom);
const maxCoveringZoom = Math.max(zoom + SourceCache.maxUnderzooming, this._source.minzoom);

Expand Down
6 changes: 1 addition & 5 deletions src/ui/handler/touch_zoom_rotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ class TouchZoomRotateHandler {
}

const duration = Math.abs(speed / (inertiaDeceleration * inertiaLinearity)) * 1000;
let targetScale = lastScale + speed * duration / 2000;

if (targetScale < 0) {
targetScale = 0;
}
const targetScale = lastScale + speed * duration / 2000;

map.easeTo({
zoom: targetScale,
Expand Down
11 changes: 8 additions & 3 deletions src/ui/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type MapOptions = {
locale?: Object
};

const defaultMinZoom = 0;
const defaultMinZoom = -2;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stick with 0 by default, and allow folks to explicitly pass in a negative minZoom if they really want to enable this.

const defaultMaxZoom = 22;

// the default values, but also the valid range
Expand Down Expand Up @@ -614,8 +614,13 @@ class Map extends Camera {
* If the map's current zoom level is lower than the new minimum,
* the map will zoom to the new minimum.
*
* @param {number | null | undefined} minZoom The minimum zoom level to set (0-24).
* If `null` or `undefined` is provided, the function removes the current minimum zoom (i.e. sets it to 0).
* It is not always possible to zoom out and reach the set `minZoom`.
* Other factors such as map height may restrict zooming. For example,
* if the map is 512px tall it will not be possible to zoom below zoom 0
* no matter what the `minZoom` is set to.
*
* @param {number | null | undefined} minZoom The minimum zoom level to set (-2 - 24).
* If `null` or `undefined` is provided, the function removes the current minimum zoom (i.e. sets it to -2).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment should be expanded to clarify that negative zoom levels equate to containers < 512px square. It's not possible to set a map to a negative zoom when the container is larger than a tile.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does fb015e8 look clear enough?

* @returns {Map} `this`
* @example
* map.setMinZoom(12.25);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions test/integration/render-tests/zoomed-fill/negative-zoom/style.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 8,
"metadata": {
"test": {
"width": 256,
"height": 256
}
},
"center": [
0,
0
],
"zoom": -1,
"sources": {
"mapbox": {
"type": "vector",
"maxzoom": 14,
"tiles": [
"local://tiles/{z}-{x}-{y}.mvt"
]
}
},
"layers": [
{
"id": "background",
"type": "background",
"paint": {
"background-color": "white"
}
},
{
"id": "fill",
"type": "fill",
"source": "mapbox",
"source-layer": "water",
"paint": {
"fill-color": "black"
}
}
]
}
10 changes: 6 additions & 4 deletions test/unit/ui/handler/touch_zoom_rotate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ test('TouchZoomRotateHandler fires zoomstart, zoom, and zoomend events at approp

simulate.touchend(map.getCanvas(), {touches: []});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 1);
t.equal(zoom.callCount, 2);
// incremented because inertia starts a second zoom
vakila marked this conversation as resolved.
Show resolved Hide resolved
t.equal(zoomstart.callCount, 2);
t.equal(zoom.callCount, 3);
t.equal(zoomend.callCount, 1);

map.remove();
Expand Down Expand Up @@ -142,8 +143,9 @@ test('TouchZoomRotateHandler starts zoom immediately when rotation disabled', (t

simulate.touchend(map.getCanvas(), {touches: []});
map._renderTaskQueue.run();
t.equal(zoomstart.callCount, 1);
t.equal(zoom.callCount, 2);
// incremented because inertia starts a second zoom
t.equal(zoomstart.callCount, 2);
t.equal(zoom.callCount, 3);
t.equal(zoomend.callCount, 1);

map.remove();
Expand Down
2 changes: 1 addition & 1 deletion test/unit/ui/map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ test('Map', (t) => {

t.test('#getMinZoom', (t) => {
const map = createMap(t, {zoom: 0});
t.equal(map.getMinZoom(), 0, 'returns default value');
t.equal(map.getMinZoom(), -2, 'returns default value');
map.setMinZoom(10);
t.equal(map.getMinZoom(), 10, 'returns custom value');
t.end();
Expand Down