Today, I'm starting a new blog series written from Foldøy, a tiny island in south west Norway which will be my home for two months. In this first post, I'll show you how to deliver zoomable high-resolution images with Leaflet.
I've brought along 17 kg of mapping and visualization books to keep me occupied:
Fullscreen
Zoom in if you want to see the details! The photo is broken into tiles and then displayed as required. You don't really need Leaflet to create images like this, as Zoomify provides both Flash and HTML5 viewers. I decided to use Leaflet to create an open source alternative, and to learn more about tiling schemes.
This is the JavaScript code needed to show this image:
var map = L.map('photo').setView(new L.LatLng(0,0), 0);
L.tileLayer.zoomify('http://thematicmapping.org/playground/zoomify/books/', {
width: 5472,
height: 3648,
tolerance: 0.8,
attribution: 'Photo: Bjørn Sandvik'
}).addTo(map);
You have to provide the url to the Zoomify image folder and the with and height dimensions of the original image. You can also specify a display tolerance for the inital zoom level. A value lower than 1.0 might center the image and cut of the edges.
![]() |
| Image source: Microsoft Deep Zoom |
The Zoomify tile format is similar to popular map tiling schemes, and I'm extending the Leaflet TileLayer class to show the image. The tiling follows a quadtree or pyramid pattern of increasing resolution, doubling the resolution for each zoom level. The tile size is 256 x 256 px and there are 256 tiles in each folder. The filename for each tile is z-x-y.jpg where z is the zoom level and x/y is the grid position starting from the top left corner.
The code is available on GitHub as a Leaflet plugin.
Fullscreen
You can create Zoomify tiles from your own image with Zoomify Express or from the Export menu in Photoshop.
You can create Zoomify tiles from your own image with Zoomify Express or from the Export menu in Photoshop.

Comments
Thank you, and looking forward to your new series!
I've tried setting the max bounds using map.unproject, but I'm getting strange results - map not showing up at all if the bounds are set... Any suggestions? I think this would be a nice addition to your plugin.
Do tell if you find a way!
http://jsfiddle.net/enNVz/16/
good work!
Pretty cool plugin and article!
But how can I add markers and svg paths over zoomified image? In wich coordinate system I should do this?
I would be thankful if you show me an example.
http://multiplans.net/en_Slicing.htm
which is:
convert "image_source.jpg" -crop 256x256 -set filename:tile "%[fx:page.x/256+1]_%[fx:page.y/256+1]" +repage +adjoin "tile_%[filename:tile].jpg"
This does not create the zoom level. Output file is Tile_X_Y.jpg.
var bottomLeft = new L.LatLng(0, -180),
topRight = new L.LatLng(90, 90),
bounds = new L.LatLngBounds(bottomLeft, topRight);
map.setMaxBounds(bounds);
map.fitBounds(bounds);
Thanks Bjørn Sandvik for the work