Instantly share code, notes, and snippets.

What would you like to do?
Full example of using leaflet to pan and zoom a big image, as described at
<!-- See also: -->
<link rel="stylesheet" href=""></script>
#image-map {
width: 100%;
height: 300px;
border: 1px solid #ccc;
margin-bottom: 10px;
<div id="image-map"></div>
<script src=""></script>
// Using leaflet.js to pan and zoom a big image.
// See also:
// create the slippy map
var map ='image-map', {
minZoom: 1,
maxZoom: 4,
center: [0, 0],
zoom: 1,
crs: L.CRS.Simple
// dimensions of the image
var w = 2000,
h = 1500,
url = '';
// calculate the edges of the image, in coordinate space
var southWest = map.unproject([0, h], map.getMaxZoom()-1);
var northEast = map.unproject([w, 0], map.getMaxZoom()-1);
var bounds = new L.LatLngBounds(southWest, northEast);
// add the image overlay,
// so that it covers the entire map
L.imageOverlay(url, bounds).addTo(map);
// tell leaflet that the map is exactly as big as the image

This comment has been minimized.

stefansl commented Feb 2, 2017

Nice. :) One little issue in this one: It's not </script> in Line 4


This comment has been minimized.

yogevizhak commented Jan 7, 2018



This comment has been minimized.

hussainb commented Jan 29, 2018

wonderful... saved me efforts


This comment has been minimized.

Salitehkat commented Jul 4, 2018

Hi, my image is 2000x1000px. I need it to be full screen when it opens. (full size) and that is the minimum zoom. Which values should i adjust?
And last, is there a way to make it responsive? (that is shrinks proportionally depending on the screen size).
Sorry for so many questions and thanks a lot for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment