var map; function init(){ // initiate leaflet map map = new L.Map('map', { center: [44.47960548767, -73.215293884277], zoom: 13 }); L.tileLayer('http://a.tiles.mapbox.com/v3/landplanner.map-b31zy3ud/{z}/{x}/{y}.png').addTo(map); 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;}" } cartodb.createLayer(map, layerUrl, layerOptions) .on('done', function(layer) { map.addLayer(layer); }).on('error', function() { //log the error }); //packages a CSV of the highest-scoring 10,50 and 100 records within the current viewport $('#down10').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%2010%3B&format=kml"; $(this).attr("href", new_sql); }); $('#down50').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%2050%3B&format=kml"; $(this).attr("href", new_sql); }); $('#bounds100').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%20100%3B&format=kml"; $(this).attr("href", new_sql); }); }