index.html
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="//geosprocket.com/assets/cartodb/2.0.24/cartodb.css" />
<link rel="stylesheet" href="//geosprocket.com/assets/bootstrap/css/bootstrap-cosmo.css" />
<link rel="stylesheet" href="//geosprocket.com/assets/leaflet/L.GeoSearch-master/src/css/l.geosearch.css" />
<style>
html, body {width:100%; height:100%; padding: 0; margin: 0;}
#map {width: 100%; position: absolute; top: 10px; bottom: 0px; background: black; z-index:1;}
.leaflet-container .leaflet-control-zoom {margin-top:10;}
div.cartodb-popup div.cartodb-popup-content {max-height:none | inherit}
</style>
<script type="infowindow/html" id="infowindow_template">
<div class="cartodb-popup">
<a href="#close" class="cartodb-popup-close-button close">x</a>
<div class="cartodb-popup-content-wrapper">
<div class="cartodb-popup-content">
<h2>{{content.data.name}}</h2><h4 style="color:#222;">{{content.data.newstr}}</h4><hr>
<em>Zoning: {{content.data.subdistric}}<br>
Height: {{content.data.height}} meters</em><br>
<hr>
<a type="button" class="btn btn-info" href="//www.burlingtonvt.gov/PropertyDetails.aspx?a=6998" target="_blank"><i class="icon-download icon-white"></i> Go to fact sheet</a>
</div>
</div>
<div class="cartodb-popup-tip-container"></div>
</div>
</script>
</head>
<body onload="init()">
<div id='map'></div>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand">Building Zoning: Burlington, VT</a>
<ul class="nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><small><i class="icon-download icon-white"></i> Download buildings in this view<b class="caret"></b></small></a>
<ul class="dropdown-menu">
<li><a id="downkml" href="#" target="_blank">KML</a></li>
<li><a id="downshp" href="#">Shapefile</a></li>
<li><a id="downgeojson" href="#">GeoJSON</a></li>
<li><a id="downtopojson" href="#">TopoJSON</a></li>
</ul>
</li>
</div>
</div>
</div>
</body>
<script>
function getURLParameter(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, ])[1]);
}
var regionParameter = getURLParameter('region');
var region = (regionParameter === 'undefined') ? '' : regionParameter;
var map;
function init() {
map = new L.Map('map', {
center: [44.4795, -73.2070],
zoom: 16,
minZoom: 12,
maxZoom: 18
});
new L.Control.GeoSearch({
provider: new L.GeoSearch.Provider.Google({
region: region
})
}).addTo(map);
L.tileLayer('//a.tiles.mapbox.com/v3/landplanner.map-b31zy3ud/{z}/{x}/{y}.png', {
attribution: '<a href="//mapbox.com/about/maps/" target="_blank">w/ Mapbox</a>'
}).addTo(map);
var reference = L.tileLayer('//a.tiles.mapbox.com/v3/landplanner.map-50ghoxbt/{z}/{x}/{y}.png');
var layerUrl = '//geosprocket.cartodb.com/api/v1/viz/btv_prints_041513f/viz.json';
var layerOptions = {
query: "SELECT * FROM {{table_name}} order by st_ymax(the_geom) desc",
tile_style: "Map{buffer-size:512;}#{{table_name}}{[zoom<=16]{line-color: #FFF;line-opacity: 0.5;line-width: 0.3;polygon-opacity: 0.8;[type='Enterprise']{polygon-fill:#f6e03f;}[type='Institutional']{polygon-fill:#adbd06;}[type='Mixed Use']{polygon-fill:#cfc8a2;}[type='RCO']{polygon-fill:#f6f7bd;}[type='Residential']{polygon-fill:#895793;}[type='Urban Reserve']{polygon-fill:#de3f33;}}[zoom>16]{building-height:[height]*1.5;building-fill-opacity:0.8;text-name:[name];text-face-name:'DejaVu Serif Bold';text-size: 10;text-wrap-width:12;text-fill:#222;text-allow-overlap:true;text-halo-fill:rgba(255,255,255,0.7);text-halo-radius:1;text-dy:-10;[type='Enterprise']{building-fill:#f6e03f;}[type='Institutional']{building-fill:#adbd06;}[type='Mixed Use']{building-fill:#cfc8a2;}[type='RCO']{building-fill:#f6f7bd;}[type='Residential']{building-fill:#895793;}[type='Urban Reserve']{building-fill:#de3f33;}}}"
}
cartodb.createLayer(map, layerUrl, layerOptions)
.on('done', function (layer) {
map.addLayer(layer);
map.addLayer(reference);
layer.infowindow.set('template', $('#infowindow_template').html());
}).on('error', function () {
});
map.on('moveend', function () {
if (map.getZoom() > 16 && map.hasLayer(reference)) {
map.removeLayer(reference);
}
if (map.getZoom() <= 16 && map.hasLayer(reference) == false) {
map.addLayer(reference);
}
});
var hash = new L.Hash(map);
$('#downkml').click(function () {
var nwlat = map.getBounds().getNorthWest().lat,
nwlon = map.getBounds().getNorthWest().lng,
selat = map.getBounds().getSouthEast().lat,
selon = map.getBounds().getSouthEast().lng;
var new_sql = "//geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_041513f%20WHERE%20the_geom%20%26%26%20ST_SetSRID(ST_MakeBox2D(ST_Point(" + nwlon + "%2C%20" + nwlat + ")%2C%20ST_Point(" + selon + "%2C%20" + selat + "))%2C4326)%20ORDER%20BY%20height%20DESC%20LIMIT%202000&format=kml";
$(this).attr("href", new_sql);
});
$('#downshp').click(function () {
var nwlat = map.getBounds().getNorthWest().lat,
nwlon = map.getBounds().getNorthWest().lng,
selat = map.getBounds().getSouthEast().lat,
selon = map.getBounds().getSouthEast().lng;
var new_sql = "//geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_041513f%20WHERE%20the_geom%20%26%26%20ST_SetSRID(ST_MakeBox2D(ST_Point(" + nwlon + "%2C%20" + nwlat + ")%2C%20ST_Point(" + selon + "%2C%20" + selat + "))%2C4326)%20ORDER%20BY%20height%20DESC%20LIMIT%202000&format=shp";
$(this).attr("href", new_sql);
});
$('#downgeojson').click(function () {
var nwlat = map.getBounds().getNorthWest().lat,
nwlon = map.getBounds().getNorthWest().lng,
selat = map.getBounds().getSouthEast().lat,
selon = map.getBounds().getSouthEast().lng;
var new_sql = "//geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_041513f%20WHERE%20the_geom%20%26%26%20ST_SetSRID(ST_MakeBox2D(ST_Point(" + nwlon + "%2C%20" + nwlat + ")%2C%20ST_Point(" + selon + "%2C%20" + selat + "))%2C4326)%20ORDER%20BY%20height%20DESC%20LIMIT%202000&format=geojson";
$(this).attr("href", new_sql);
});
$('#downtopojson').click(function () {
var nwlat = map.getBounds().getNorthWest().lat,
nwlon = map.getBounds().getNorthWest().lng,
selat = map.getBounds().getSouthEast().lat,
selon = map.getBounds().getSouthEast().lng;
var new_sql = "//geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_041513f%20WHERE%20the_geom%20%26%26%20ST_SetSRID(ST_MakeBox2D(ST_Point(" + nwlon + "%2C%20" + nwlat + ")%2C%20ST_Point(" + selon + "%2C%20" + selat + "))%2C4326)%20ORDER%20BY%20height%20DESC%20LIMIT%202000&format=topojson";
$(this).attr("href", new_sql);
});
}
</script>
<script src="//geosprocket.com/assets/cartodb/2.0.24/cartodb.js"></script>
<script src="//geosprocket.com/assets/bootstrap/js/bootstrap.min.js"></script>
<script src="//geosprocket.com/assets/leaflet/leaflet-hash.js"></script>
<script src="//geosprocket.com/assets/leaflet/L.GeoSearch-master/src/js/l.control3.geosearch.js"></script>
<script src="//geosprocket.com/assets/leaflet/L.GeoSearch-master/src/js/l.geosearch.provider.google.js"></script>
</html>