1

I am updating an old demo that used the first versions of Cartodb so that is runs with the latest version of cartodb.js.

I am trying to overlay a set of points on the base map and getting the following error:

TypeError: layer should be provided cartodb.createLayer(b=Object { map_canvas="map_canvas", map="map", user_name="tobagoborn", more...}, d=undefined, e=undefined, f=undefined)cartodb.js (line 23) initialize()lndngsites1.html (line 56) onload(event=load )

Here is my code:

<script type="text/javascript">

function initialize()
{
    var map = new L.Map('map_canvas',
    {
        doubleClickZoom:true,zoomControl:true,scrollWheelZoom: false,touchZoom: false,dragging: true, minZoom: 11, maxZoom: 13
    }).setView(new L.LatLng(11.23,  -60.70), 6);

    var tilesUrl = 'http://tobagoborn.com/tiles/tobagobasemap/{z}/{x}/{y}.png';
    L.tileLayer(tilesUrl, {attribution: "Cartodb", maxZoom: 13}).addTo(map);

    //alert(cartodb.VERSION)

    cartodb_leaflet1 = cartodb.createLayer(
    {
        map_canvas: 'map_canvas',
        map: 'map',
        user_name:"tobagoborn",
        type: cartodb,
        sublayers: [{
            table_name: 'lsites',
            query: "SELECT * FROM {{table_name}}",
            interactivity: "landing_sites,number_of_boats,top_species,site_code"
        }]
  }).addTo(map_canvas)

}
</script>
  • If you are using old CartoDB.js versions, perhaps you also find interesting this upgrade guide: github.com/CartoDB/cartodb.js/blob/develop/UPGRADE.md – iriberri Jan 11 '16 at 8:57
  • @iriberri Thanks for the link. Read it but got stuck on the type: option. See my comment to Jags answer – ChrisJ Jan 12 '16 at 0:03
  • It turns out that my links to cartodb's css and js scripts were not correct!! – ChrisJ Jan 17 '16 at 0:01
1

I'm not sure how old your previous version was but the syntax looks a little off from what the docs specify. Take a look here;

http://docs.cartodb.com/cartodb-platform/cartodb-js/layer-source-object/#named-maps-layer-source-object-type-namedmap

They have recently updated this section of the documentation after I very recently had queries/complaints. It is still missing some vital information but it is better than it was (for example they don't mention including an empty layer if you are not using their base map, and we found it necessary to avoid issues with infowindows).

You want something likes this;

cartodb_leaflet1 = cartodb.createLayer(map, 
{
    user_name:"tobagoborn",
    type: 'cartodb',
    sublayers: [
      {
        sql: "SELECT * FROM lsites",
        cartocss: '#lsites {marker-fill: #FF0000;}',
        interactivity['landing_sites','number_of_boats','top_species', 'site_code']
      }]
  })
  .addTo(map)
  .on('done', function(layer) {
      for (var i=0; i < layer.getSubLayerCount(); i++) {
          layer.getSubLayer(i).show();
          layer.getSubLayer(i).setInteraction(true);
      }
  });
  • Thanks for the suggestions. I tried it an getting an error on type:cartodb. The error is: TypeError: a.toLowerCase is not a function Is the any documentation on the type option. – ChrisJ Jan 12 '16 at 0:00
  • With which old CartoDB.js version where you working exactly? In this response, I'm missing the cartocss parameter for the sublayers. Find an example of mine of a basic createLayer (which doesn't contain interactivity, tho) here: bl.ocks.org/iriberri/46ea069744d7f852f2bd – iriberri Jan 12 '16 at 16:07
  • I created the app with version 1. Figured out the TypeError issue... I forgot the quotes!! The problem I'm having now is the layer being loaded but not showing – ChrisJ Jan 12 '16 at 17:09
  • I'm not sure why the layer would not be showing. You could potentially provide a snapshot of your data and a log of the loaded layer that we could have a look at? I have edited my answer to show the on('done') section of code. Depending on how you have configured the layer in the backend sometimes you need to explicitly show the layer. Also you will also need to set interaction to true to interact with your layer. – Jags Jan 12 '16 at 22:02
  • @Jags, I added the done option and for loop but haven't seen any response to it. Also, in the console I see the following error: "NetworkError: 400 Bad Request - 1.api.cartocdn.com/tobagoborn/api/v1/map/undefined/11/677/…". How do I upload a the log and some of the data to SO? – ChrisJ Jan 13 '16 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.