Skip to content

Instantly share code, notes, and snippets.

@drewda
Forked from e-n-f/index.html
Created August 24, 2013 18:46
Show Gist options
  • Save drewda/6329795 to your computer and use it in GitHub Desktop.
Save drewda/6329795 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.css' rel='stylesheet' />
<!--[if lte IE 8]>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.ie.css' rel='stylesheet' >
<![endif]-->
<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], 5);
}
var map = L.mapbox.map('map', 'enf.tiger-2013');
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