//Wrap the map action var map; function init(){ // initiate leaflet map map = new L.Map('map', { center: [44.47960548767, -73.215293884277], zoom: 15 }); //Call some attractive Mapbox tiles as a base L.tileLayer('http://a.tiles.mapbox.com/v3/landplanner.map-b31zy3ud/{z}/{x}/{y}.png', { attribution:'w/ Mapbox' }).addTo(map); //Give CartoDB the parameters of your table by viz.json - //throw in some CartoCSS at "tile_style" to tie the rendered building height to a data field var layerUrl = 'http://geosprocket.cartodb.com/api/v1/viz/btv_prints_011813/viz.json'; var layerOptions = { query: "SELECT * FROM {{table_name}};", tile_style: "Map{buffer-size:512;}#{{table_name}}{building-height:[height]*0.4;building-fill:orange;building-fill-opacity:0.5;}" } //Tack the layer on top of the base tiles cartodb.createLayer(map, layerUrl, layerOptions) .on('done', function(layer) { map.addLayer(layer); }).on('error', function() { //log the error }); //Some jquery packages up to 500 buildings within the current viewport, in //KML FORMAT, $('#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 = "http://geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_011813%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_real%20DESC%20LIMIT%20500&format=kml"; $(this).attr("href", new_sql); }); //SHAPEFILE FORMAT, $('#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 = "http://geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_011813%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_real%20DESC%20LIMIT%20500&format=shp"; $(this).attr("href", new_sql); }); //AND GEOJSON FORMAT $('#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 = "http://geosprocket.cartodb.com/api/v2/sql?q=SELECT%20*%20FROM%20btv_prints_011813%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_real%20DESC%20LIMIT%20500&format=geojson"; $(this).attr("href", new_sql); }); }