2

I'm not using createVis, but rather createLayer to generate my maps on the fly, but can't seem to figure out how to add a legend using something simple like legends: true, which is available when using createVis.

What's the best way to do this?

1

You can manually add Legends to the map using the objects in cdb.geo.ui.Legend

var densityLegend = new cdb.geo.ui.Legend.Density({
            title:   "<a href='http://www.fbi.gov/about-us/cjis/ucr/ucr'>Data From FBI Crime Reporting 2013</a>",
            left: "Low", right: "High", colors: [ "#FFFFB2", "#FED976", "#FEB24C", "#FD8D3C", "#FC4E2A", "#E31A1C", "#B10026"  ]
        });
        $('#map').append(densityLegend.render().el);

An example of doing this for a density legend is given here.

  • 1
    Thanks...this worked, but I don't know why. I can't find any documentation for Legend anywhere. It seems like there are different kinds (density, bubble), but I have no idea where to read up more on this. Any ideas? – jonmrich Jun 8 '15 at 23: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.