3

I have a custom CartoDB map that uses data I have uploaded and styled. The map works perfectly and I would like to use it as a basemap in a different application. Is there any way to use this map as a tile service?

I realize that I could use CartoDB.js in the external application but I do not control that resource and have simply been asked to provide a tile server as input downstream. I'm not certain but I believe the downstream application is using Google Maps API. Any way to accomplish this?

1 Answer 1

3

Yes, you can use our Maps API to get the tiles in an xyz format. It's possible in several languages as you only need to instantiate the map with a POST, but here is how to do that through JavaScript:

var mapconfig = {
  "version": "1.3.1",
  "layers": [{
    "type": "cartodb",
    "options": {
      "cartocss_version": "2.1.1",
      "cartocss": "#layer { polygon-fill: #FFF; }",
      "sql": "select * from european_countries_e"
    }
  }]
}

$.ajax({
  crossOrigin: true,
  type: 'POST',
  dataType: 'json',
  contentType: 'application/json',
  url: 'https://documentation.cartodb.com/api/v1/map',
  data: JSON.stringify(mapconfig),
  success: function(data) {
    var templateUrl = 'https://documentation.cartodb.com/api/v1/map/' + data.layergroupid + '/{z}/{x}/{y}.png'
    console.log(templateUrl);
  }
})

That code is in the Anonymous Maps section of the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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