You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: in our examples so far, we are using Leaflet as the native map
Working with layers
varsublayer=layers[1].getSubLayer(0);
note: in createVis, layers[0] is the basemap
Adding an infobox
// Get the sublayervarsublayer=layers[1].getSubLayer(0);// Add interactivitysublayer.setInteraction(true);// Define which data columns are returned during interactivitysublayer.setInteractivity('cartodb_id, url1, url2, distance_k');// Define our infowindow varinfobox=newcdb.geo.ui.InfoBox({width: 300,layer: layers[1].getSubLayer(0),template: '<p class="cdb-infobox">Distance km: {{distance_k}}</p>'});// Add it to the HTML$("body").append(infobox.render().el);
Updating SQL on the fly
// Get the sublayervarsublayer=layers[1].getSubLayer(0);// Set a new style with a CartoCSS stringsublayer.setSQL("SELECT * FROM cables WHERE distance_k > 18000");
Updating CartoCSS on the fly
// Get the sublayervarsublayer=layers[1].getSubLayer(0);// Set a new style with a CartoCSS stringsublayer.setCartoCSS("#cables { line-color: lightgreen; } ");
Create a button to filter and change styles on the fly
Add a button to the html
<divid="layer_selector" class="cartodb-infobox"><ul><liid="change">Change to Choropleth</li></ul></div>
// Get our sublayervarsublayer=layers[1].getSubLayer(0);// Use jQuery to listen to for the click event on our button$('#layer_selector #change').click(function(){// set our new style based on the style we stored in the template abovesublayer.setCartoCSS($('#cartocss_area_template').html());// filter out the inactive cablessublayer.setSQL('SELECT * FROM cables WHERE notlive = 0')});
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters