0

I am trying to use the cartodb.core.js library to render my own tiles. According to what I see, the Tiles library is only available in the cartodb.core.js. And if we use that we don't get the createLayer function, which is fine if I can just get the Tiles to load, and I can render them myself:

var layerData = {
  user_name: 'swc28',
  sublayers: [{
    sql: "SELECT * FROM zoning",
    cartocss: '#layer { marker-fill: #F0F0F0; }'
  }]
};
cartodb.Tiles.getTiles(layerData, function(tiles, err) {
  if(tiles == null) {
    console.log("error: ", err.errors.join('\n'));
  }
  console.log("url template is ", tiles.tiles[0]);
})

But I've never rendered layers like this myself, and I looked at the library without much success to figure out how to do it. So my question is: How does the CartoDB UI library render the tiles from a template url that is returned form the call above?

The template url looks like this:

http://{s}.ashbu.cartocdn.com/swc28/api/v1/map/fad6aaab9c3d921f76e0e07f3da6071f:1414011659683.92/{z}/{x}/{y}.png?cache_policy=persist
1

It depends on the mapping library you are using, each one has its own way to add tiled layers.

For example for leaflet the way to do this would be:

L.tileLayer('http://{s}.ashbu.cartocdn.com/swc28/api/v1/map/fad6aaab9c3d921f76e0e07f3da6071f:1414011659683.92/{z}/{x}/{y}.png?cache_policy=persist').addTo(map)

I've created a full example.

https://github.com/CartoDB/cartodb.js/blob/develop/examples/leaflet_core_library.html

2
  • Thanks! I wonder if it's possible to also simulate the featureOver events of the vis library with this approach.
    – picardo
    Oct 25 '14 at 15:41
  • Yes, you'd need to use leaflet utfgrid plugin and the urls cartodb provides for interaction Oct 25 '14 at 23:25

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.