0

I've been trying to make use of the CartoDB baseLayers (https://carto.com/location-data-services/basemaps/) in the ArcGis Javascript API v 4.0.

But I have not been able to get it working.

I believe it is correct to make use of the WebTileLayer, and with single domain access I attempted to add it like this:

var layer = new WebTileLayer("http://1.basemaps.cartocdn.com/light_all/{level}/{col}/{row}.png", {
    "id": "cartoDb",
    "copyright": '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, &copy; <a href="https://carto.com/attributions">CARTO</a>'
    });

What am I getting wrong?

1

I was investigating a bit more myself.

First, the WebTiledLayer has been renamed to WebTileLayer (https://developers.arcgis.com/javascript/latest/guide/whats-new/index.html#New_Widgets_52)

Then secondly, using version 4.0, it seems to be mandatory to use the MapView object.

Initializing the map object this way works:

 map = new Map({});

   view = new MapView({
      center: [-111.87, 40.57], // long, lat
      container: "map",
      map: map,
      zoom: 6
    });

Doing it like what worked for 3.17 doesn't:

map = new Map("map", {
      center: [-89.985, 29.822],
      zoom: 8
    });*/

Full working example in fiddle here: https://jsfiddle.net/eivind_ronnevik/tny749fc/

Thanks for the effort anyway @ramiroaznar

  • Well done! Good to know, you can mark your question as answered then. – ramiroaznar Aug 10 '16 at 7:57
0

There is nothing wrong with the code you have shared, it could be the rest of the code. Maybe you are missing map.addLayer(layer); just after those lines. Here I have created a working example replicating the one from WebTiledLayer class.

enter image description here

  • Sorry, pushed the enter button too early. I was initially working with version 4.0, but I got your example to work using API version 3.17 instead, see this fiddle: jsfiddle.net/eivind_ronnevik/p5hwzj07 However, when trying the same with version 4.0, it doesn't work. Modified version of html for version 4.0: jsfiddle.net/eivind_ronnevik/osauzsae – Eivind Rønnevik Aug 9 '16 at 13:08
  • I have not used v4 before, but a little research tell me that the classes have changed, from WebTileLayer to TileLayer. I will try, but maybe someone can give you a faster answer. – ramiroaznar Aug 9 '16 at 16:59

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.