Created
January 26, 2014 00:04
-
-
Save e-n-f/8625818 to your computer and use it in GitHub Desktop.
Display map tiles from tiles/{z}/{x}/{y}.png relative to the current directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' /> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" /> | |
<!--[if lte IE 8]> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.ie.css" /> | |
<![endif]--> | |
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script> | |
<style> | |
body { margin:0; padding:0; background:black; } | |
#map { position:absolute; top:0; bottom:0; width:100%; background:black; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script type='text/javascript'> | |
function parseHash(map, hash) { | |
console.log(location.hash); | |
if (hash.indexOf('#') === 0) { | |
hash = hash.substr(1); | |
} | |
var args = hash.split('/'); | |
if (args.length >= 3) { | |
var zoom = parseInt(args[0], 10); | |
var lat = parseFloat(args[1]); | |
var lon = parseFloat(args[2]); | |
if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) { | |
map.setView([lat, lon], zoom); | |
return; | |
} | |
} | |
map.setView([38, -100], 14); | |
} | |
var map = L.map('map', {zoomAnimation: false}); | |
map.addLayer(L.tileLayer('tiles/{z}/{x}/{y}.png', { maxZoom: 22 })); | |
parseHash(map, location.hash); | |
function onMapMove() { | |
var center = map.getCenter(), | |
zoom = map.getZoom(), | |
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); | |
location.replace("#" + zoom + "/" + | |
center.lat.toFixed(precision) + "/" + | |
center.lng.toFixed(precision)); | |
} | |
map.on("moveend", onMapMove, this); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment