Moore Spatial

GIS and Related Pursuits

By

What Slippy Map Zoom Level Is Ideal For My Source Map?

If you’re creating XYZ tiles for your slippy map (eg. Leaflet or OpenLayers), and your source is a raster image, you might wonder which zoom level will display the map with the least artifacts.

Or you might not. In any case, if you do want to know what zoom level is ideal, here’s how you find it. The code is in PHP, but should be easy to translate to other languages.

$min_dimension = min($image_width_in_pixels,$image_height_in_pixels);
$zoom_level = round(log($min_dimension/256,2)

Take the smaller of the height or width[1], divide it by 256 and find the base-2 logarithm of that. You will likely need to round that result to get an integer value. That integer will be the zoom level which has to resize your image the least to produce the appropriate tiles.

[1] Really, your source map should likely be square since you’re probably using Web Mercator