Skip to content

CartoDB Map Provider Tutorial

mphasize edited this page Apr 23, 2012 · 1 revision

CartoDB Map Provider

Hi, I just added a CartoDB Map Provider to Unfolding and wanted to write a short introduction on how to use it.

CartoDB comes with a variety of APIs to access your Geospatial Data, but since Unfolding is mainly tile based, we will use the Maps API which produces nice standard tiles for us to display.

You will need to know the Account-Name and the Table where your data is stored.

// Change ACCOUNT and TABLE to your appropriate values
cartodb = new CartoDBProvider("ACCOUNT", "TABLE");

// We can customize the database query, by providing our own SQL statement
// cartodb.setSql("SELECT * FROM table");

// We can customize the appearance of the cartodb map tiles by setting CartoCSS styles
//String style = "#id { marker-fill:#FF3300; marker-width:20; marker-type:ellipse; marker-allow-overlap:true; }";
//cartodb.setStyle(style);

// CartoDB will provide us with the data rendered on transparent PNG's, 
// so you probably want to display some kind of base map under the CartoDB Layer. 
// In order to do that, just choose another Map Provider and set it as a master provider for the CartoDB Layer
cartodb.masterProvider = new Microsoft.AerialProvider();

After setup, we can just the CartoDB Provider like any other provider.

map = new Map(this, "map", 0, 0, width, height, true, false, cartodb);

KNOWN ISSUES:

  • currently there is no OAuth implementation for the CartoDB Layer, so you will only be able to access PUBLIC tables
  • you can change the SQL Query and the Style settings on the fly and future tile requests will load accordingly, but currently there is no mechanism in unfolding to force a reload of the cached tiles
  • the code was written in Netbeans so the style of class imports might differ from Eclipse projects

Hope you will enjoy this little helper.

Clone this wiki locally