Skip to content

Instantly share code, notes, and snippets.

@marishaf
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save marishaf/3cc9bfbeb412c1120e93 to your computer and use it in GitHub Desktop.
Save marishaf/3cc9bfbeb412c1120e93 to your computer and use it in GitHub Desktop.
adapt oakland maps
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.6.0/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.6.0/mapbox.css' rel='stylesheet' />
<!--[if lte IE 8]>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.6.0/mapbox.ie.css' rel='stylesheet'>
<![endif]-->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
#map-ui {
position: absolute;
top: 75px;
left: 10px;
list-style: none;
margin: 0;
padding: 0;
z-index: 100;
}
#map-ui a {
font: normal 13px/18px 'Helvetica Neue', Helvetica, sans-serif;
background: #FFF;
color: #3C4E5A;
display: block;
margin: 0;
padding: 0;
border: 1px solid #BBB;
border-bottom-width: 0;
min-width: 138px;
padding: 10px;
text-decoration: none;
}
#map-ui a:hover {
background: #ECF5FA;
}
#map-ui li:last-child a {
border-bottom-width: 1px;
-webkit-border-radius: 0 0 3px 3px;
border-radius: 0 0 3px 3px;
}
#map-ui li:first-child a {
-webkit-border-radius: 3px 3px 0 0;
border-radius: 3px 3px 0 0;
}
#map-ui a.active {
background: #3887BE;
border-color: #3887BE;
border-top-color: #FFF;
color: #FFF;
}
</style>
<ul id='map-ui'></ul>
<div id='map'></div>
<script type='text/javascript'>
var southWest = L.latLng(37.581209, -122.498682),
northEast = L.latLng(37.897507, -122.080184),
bounds = L.latLngBounds(southWest, northEast);
var map = L.mapbox.map('map', 'ubmaps.map-kb224le4', {
zoomControl: false,
minZoom: 12,
maxZoom: 19,
maxBounds: bounds
})
.setView([37.8119,-122.3028], 15)
var ui = document.getElementById('map-ui');
//I put this here
var thelayer = null;
L.control.layers({
'Satellite' : L.mapbox.tileLayer('ubmaps.h2pdghi7'),
'Streets' : L.mapbox.tileLayer('ubmaps.map-kb224le4'),
}).addTo(map);
var baaqmd = L.mapbox.tileLayer('ubmaps.hgd2f95d');
var oaklandowner = L.mapbox.tileLayer('ubmaps.hnb26i58');
var zoning = L.mapbox.tileLayer('ubmaps.h6b0lp81');
addLayer(baaqmd, L.mapbox.gridLayer('ubmaps.hgd2f95d'),'Point Source Pollution', 4);
addLayer(oaklandowner, L.mapbox.gridLayer('ubmaps.hnb26i58'),'Public Land', 3);
addLayer(zoning, L.mapbox.gridLayer('ubmaps.h6b0lp81'),'Zoning', 2);
function addLayer(layer, gridlayer, name, zIndex) {
layer
.setZIndex(zIndex)
gridlayer
// add the gridControl to the active gridlayer
var gridControl = L.mapbox.gridControl(gridlayer, {follow: false}).addTo(map);
// Create a simple layer switcher that toggles layers on and off.
var item = document.createElement('li');
var link = document.createElement('a');
link.href = '#';
link.className = 'active';
link.innerHTML = name;
link.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
if (map.hasLayer(layer)) {
map.removeLayer(layer);
map.removeLayer(gridlayer);
map.legendControl.removeLegend(thelayer.getTileJSON().legend);
thelayer.link.className = '';
this.className = '';
} else {
map.addLayer(layer);
map.addLayer(gridlayer);
this.className = 'active';
map.legendControl.addLegend(layer.getTileJSON().legend);
}
thelayer = layer;
};
item.appendChild(link);
ui.appendChild(item);
}
new L.Control.Zoom({ position: 'topleft' }).addTo(map);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment