Skip to content

Instantly share code, notes, and snippets.

@dlferro
Created June 27, 2012 15:00
Show Gist options
  • Save dlferro/3004639 to your computer and use it in GitHub Desktop.
Save dlferro/3004639 to your computer and use it in GitHub Desktop.
Leaflet Image Deepzoom
<html>
<head>
<link rel="stylesheet" href="lib/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="lib/leaflet.ie.css" />
<![endif]-->
</head>
<body>
<div id="map" style="width:1004px; height:748px; border: 1px solid black;"></div>
<script type="text/javascript" src="lib/leaflet-src.js"></script>
<script type="text/javascript">
var maxZoom = (data.length - 1), // contains the layer info
maxZoomLayer = data[data.length - 1]; // gets last zoom level object that contains height/width
// Setup the map
var map = new L.Map('map', {
crs: L.CRS.Simple,
worldCopyJump: false,
center: new L.LatLng(0.0, 0.0),
zoom: maxZoom,
maxZoom: maxZoom
});
// Immediately set the view with 0,0 on the top left
map.setView(map.layerPointToLatLng(new L.Point(1004, 748)), maxZoom, true); // bounds of container 1004/748
// Declare a tile layer and add to map
var tileURL = '/test/zoom{z}/row{y}/col{x}.png';
var tiles = new L.TileLayer(tileURL, {
noWrap: true,
maxZoom: maxZoom
});
map.addLayer(tiles);
// Reset the map to bound the image
map.fitBounds(new L.LatLngBounds(
map.layerPointToLatLng(new L.Point(0, maxZoomLayer.height)),
map.layerPointToLatLng(new L.Point(maxZoomLayer.width, 0))
));
</script>
</body>
</html>
@ymalkawi
Copy link

I am currently trying to generate tiles for leaflet js, could you please explain how did you generate the tiles for this code to work?

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