Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layer.model.attributes.legend inconsistent #523

Closed
knownasilya opened this issue Jun 12, 2015 · 11 comments
Closed

layer.model.attributes.legend inconsistent #523

knownasilya opened this issue Jun 12, 2015 · 11 comments

Comments

@knownasilya
Copy link
Contributor

A layer with type torque has layer.model.attributes.legend, but a layer with type namedmap does not. Not sure if this is related to #480. I'm using createLayer and a custom build from master (last week).

cc @alonsogarciapablo

@knownasilya
Copy link
Contributor Author

Anyone have any ideas about this, is there some other way that I'm supposed to create the Legend?

@alonsogarciapablo
Copy link
Contributor

@knownasilya. Could you please share some of your code with us? We'd like to see how you're using cartodb.createLayer. Thanks!

@knownasilya
Copy link
Contributor Author

function createLayer(map, options) {
  if (!options || !options.url || !options.name) {
    throw 'Invalid layer declaration';
  }

  return new Promise(function (resolve, reject) {
    var layer = cartodb.createLayer(map, options.url, {
      scrollwheel: false,
      cartodb_logo: false,
      infowindow: false,
      tooltip: false,
      legends: false,
      time_slider: false
    });

    layer.on('error', function (error) {
      console.error('CartoDB Layer Error: ', error);
      reject(error);
    })
    .on('done', function (layer) {
      if (typeof layer.setInteraction === 'function') {
        layer.setInteraction(false);
      }

      if (layer.pause) {
        layer.pause();
        layer.slider = new cdb.geo.ui.TimeSlider({
          layer: layer
        }).render();
      }

      if (layer.model.attributes.legend) {
        let legendView = new cdb.geo.ui.Legend.Custom(layer.model.attributes.legend);
        layer.legend = legendView.render();
      }

      layer.legendImage = options.legendImage;
      layer.attribution = options.attribution || layer.options.attribution;
      layer.id = options.id;
      layer.idx = options.idx;

      resolve(layer);
    });
  });
}

@knownasilya
Copy link
Contributor Author

@alonsogarciapablo have you had a chance to look at this?

@alonsogarciapablo
Copy link
Contributor

@knownasilya Thanks for sharing your code! I will take a look and let you know something soon.

@knownasilya
Copy link
Contributor Author

So I was able to do layer.layers[0].legend.. Will confirm if this is also available for torque.

@alonsogarciapablo
Copy link
Contributor

We have just released some new documentation for sublayer.legend. You can check it out here. As you just discovered, this feature is available at the sublayer level.

@knownasilya
Copy link
Contributor Author

@alonsogarciapablo what exactly is a sublayer? And how is it create from the UI?

@alonsogarciapablo
Copy link
Contributor

When you create a map using the editor, it will be composed of:

  • A layer with the basemap.
  • A layer with one/many cartodb/mapnik sublayers.
  • (optionally) a torque layer.

You will see this clearly if you inspect a viz.json file.

So sublayers are the "layers" that you add in the editor. You can programatically add sublayers to an exiting layer using layer.createSubLayer or set the sublayers when you use cartodb.createLayer (check out this example).

@knownasilya
Copy link
Contributor Author

Note: the last example has a typo, hashes within a hash (should be an array somewhere)..

@nobuti
Copy link
Contributor

nobuti commented Nov 16, 2016

There has been no activity on this issue for several months and that's why are closing it (automatically). If you think this still needs to be addressed please reopen it. The good news is that we are now working on the next version of CARTO.js, stay tuned.

@nobuti nobuti closed this as completed Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants