Skip to content

Instantly share code, notes, and snippets.

@glenrobertson
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glenrobertson/a3fbddb0e275a7db9260 to your computer and use it in GitHub Desktop.
Save glenrobertson/a3fbddb0e275a7db9260 to your computer and use it in GitHub Desktop.
Map with TMS params
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<style type="text/css">
html, body, #map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
function getURLParameters() {
// http://stackoverflow.com/questions/8648892/convert-url-parameters-to-a-javascript-object
var search = location.search.substring(1);
return JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}')
}
var map = new L.Map('map'),
cloudmadeUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data &copy; 2011 OpenStreetMap contributors, Imagery &copy; 2011 CloudMade';
map.setView(new L.LatLng(37.7833, -122.4167), 13);
var baseLayer = new L.TileLayer(cloudmadeUrl, { attribution: cloudmadeAttribution});
baseLayer.addTo(map);
var parameters = getURLParameters();
var heatmapUrl = parameters.uri;
if (Object.keys(parameters).length > 1) {
heatmapUrl += '?';
for(var k in parameters) {
if (k === 'uri') { continue; }
heatmapUrl += k + '=' + parameters[k] + '&';
}
}
var overlayLayer = new L.TileLayer(heatmapUrl);
overlayLayer.addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment