Skip to contents

MEASURED, not derived. The formula this replaces – log2(360 / span) + 0.55 – was inherited from the bbox-fitting code and is about 1.3 zoom levels too tight on a globe, which is why Alaska came up cropped: it asked for z 3.64 to show a 19.2 degree radius, and z 3.64 actually shows 8.7.

Usage

view_zoom(radius_deg, margin = 0.1)

Arguments

radius_deg

angular radius from the centre, degrees

margin

fraction to inflate the radius by before computing the zoom, so the area sits inside the frame rather than flush against its edge

Value

a MapLibre zoom, clamped to [1.7, 5]

Details

Probed in-browser on the deployed map by un-projecting the mid-point of the canvas's top edge, which is the binding constraint because the viewport is wider than it is tall:

zoomvertical half-extenthorizontal half-extent
2.0030.2 deg65.1 deg
2.5020.148.0
3.0013.827.0
3.648.715.9
4.006.712.0

log2(half_extent) falls almost exactly 1 per zoom level, so zoom = C - log2(radius). C solves to 6.74-6.92 across that range; 6.75 is taken deliberately from the low end, since erring small zooms OUT and showing a little too much is the harmless direction.

The lower clamp is 1.7, not 0. Past roughly there the globe stops growing to meet the viewport and simply shrinks inside it – a sphere shows at most a hemisphere, so zooming out further buys nothing and costs the frame. The Pacific hits this: its enclosing radius of 46.5 deg asks for z 1.07, which rendered the globe as a small ball with empty space around it.

The table above is the VERTICAL half-extent, which is the binding constraint for a tall region. A wide one like the Pacific – Guam to California – has about twice that horizontally to spend, which is what makes the clamp safe rather than merely tolerable.