[GIS] What unit is Zoom in OpenLayer3

openlayers

I need to know the type of unit that Zoom, or maxZoom/minZoom has.
I've been finding in OpenLayers API but without success.

Do you have any idea?

Best Answer

Short answer: The zoom of ol.View is not in any unit, it is just an incrementing integer id for a given resolution.

Longer answer:

Zooming in OpenLayers 3 is entirely based on resolution. The resolution is the number of map units per pixel and can vary continuously between the minResolution and maxResolution. The resolution is however constrained to a set of resolutions, which the map will snap to after zoom interactions.

The zoom index/number is nothing more than an enumeration of these resolutions, where 0 is the highest resolution, 1 is the second and so on. So when you do view.setZoom(6), all you're doing is setting the resolution to the seventh constraint resolution.

So what are those resolutions? It all depends on your configuration:

  • If using the resolution option, it's value is the constraint resolutions
  • Otherwise, the resolutions will be calculated from the maxResolution and zoomFactor:
    • The zoomFactor defaults to 2, but is configurable
    • The maxResolution is calculated as the resolution for fitting the projection's extent in 256*256 pixels, if not explicitly provided
    • The resolution for a given zoom level when calculated this way will be maxResolution / Math.pow(zoomFactor, zoomLevel)
    • The minZoom and maxZoom options will limit which of these resolutions that will be usable. maxZoom will determine how many such resolutions are calculated, if maxZoom is 20 then there will be 21 resolutions. But if minZoom is more than 0 the first minZoom of those resolutions will be ignored.