Trying to recreate an application made in carto v3 in the new version of carto (v4); here is the one which was create using v3. Problem we are running into is that we can't seem to figure out how to create multiple layers in v4, there is no documentation on a similar method like .createLayer() from v3.

Does anyone have some workable related v4 code I could look at?

function retrieveLayer(map, cartoLayerSource, layerSide) {
    return new Promise(function(resolve, reject) {
      cartodb.createLayer(map, cartoLayerSource)
              function(layer) {
                // console.log(layer);
                layerSides[layerSide] = layer;
          .on('error', function(error) {
            // console.log(error);

Here you have an example, using several layers, with carto.js v4: https://carto.com/developers/carto-js/examples/#example-add-more-layers.

Instead of createLayer you build your layers using new carto.layer.Layer

| improve this answer | |
  • Thanks for that. Could you take a look at another question I have found here ? @Víctor Velarde – cvricella_sbu Oct 16 '19 at 13:47

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.