3

I have generated a 'bubble' map in Carto:

enter image description here

Custom CSS:

#layer {
    [capacity >= 70000]  
    {marker-width: 90;
    }
    [capacity >= 60000][capacity < 70000]  
    {marker-width: 80;}
    [capacity >= 50000][capacity < 60000]
      {marker-width: 70;}
    [capacity >= 40000][capacity < 50000]
       {marker-width: 60;}
    [capacity >= 30000][capacity < 40000]
      {marker-width: 50;}
    [capacity >= 20000][capacity < 30000]
       {marker-width: 40;}
    [capacity <= 20000]
       {marker-width: 30;}
 marker-fill: teal;
    marker-fill-opacity: 0.5;
    marker-line-color: #FFF;
    marker-line-width: 1;
    marker-line-opacity: 0.8;
    marker-placement: point;
    marker-type: ellipse;
    marker-allow-overlap: true;
  } 

However there is no option to create a bubble style legend. I have looked at several examples to use custom html to implement this, however none seem to generate what i am after.

The question - CartoDB choropleth + bubble visualization with two independent value ranges in legend seems to show what I am after but the code supplied does not seem to behave the same my end

    <div class='cartodb-legend bubble'> 
 <ul>
  <li>
  1.46
  </li>
  <li class="graph" style="background: linear-gradient(to right,rgb(253, 141, 60), rgb(252, 78, 42), rgb(177, 0, 38));">
    <div class="bubbles"></div>
  </li>
  <li>
  18.5
  </li>
</ul>
</div>

I don't expect this to suddenly work with my data but I don't understand why I return:

enter image description here

Instead of:

enter image description here

Has the functionality of 'cartodb-legend bubble' changed at all?

3

The question and code work for Editor, the former CARTO web UI. According to the screenshot, the map was created using BUILDER, the new CARTO web UI. Bubble and choropleth legends are generated dynamically (and automatically) after styling BY VALUE. So in your case, if the legend is not showing I recommend following these steps to recover it:

  1. Click on the layer.
  2. Go to the LEGEND tab.
  3. Click on SIZE.
  4. Select BUBBLE.

UPDATE:

In order to replicate the CartoCSS code you have shared and at the same time getting a bubble legend follow these steps:

  1. Go to the STYLE tab.
  2. Switch to the UI and click on CLEAR.
  3. Click on the marker width (it shows 7 by default) and select BY VALUE, then choose capacity field from the drop-down menu.
  4. Switch the slider button to show the CartoCSS panel again.
  5. Apply the following CartoCSS code:
#layer {
    marker-width: ramp([capacity], (30,40,50,60,70,80), (20000,30000,40000,50000,60000,70000), >);   
    marker-fill: teal;
    marker-fill-opacity: 0.5;
    marker-line-color: #FFF;
    marker-line-width: 1;
    marker-line-opacity: 0.8;
    marker-placement: point;
    marker-type: ellipse;
    marker-allow-overlap: true;
  }
  1. Apply.

You will end up with a visualization similar to this one but with a nice legend. I have used this app to adjust the bubbles sizes. :-)

enter image description here

  • Thanks for the response @ramiroaznar, unfortunately there are no options to select when i click on the 'size' tab, it just says NONE. I used my own css styling to generate different marker-widths. Is there a simple piece of html I could use here? – ProudGIS Apr 25 '17 at 15:51
  • Legends are generated by using the UI but behind the scenes is applying a TurboCARTO ramp. Could you share the custom CartoCSS? I believe I will be able todo make a workaround. – ramiroaznar Apr 25 '17 at 16:32
  • Custom CSS has been added to original question @ramiroaznar. Is 'Editor' still available for public use? perhaps this would be the easiest option. – ProudGIS Apr 26 '17 at 8:41
  • I have updated my answer. CARTO is migrating all users to BUILDER, so Editor is not available for new and migrated users. – ramiroaznar Apr 26 '17 at 15:26
  • Getting closer. Changing the value to capacity from another value I had previously been looking at has given a legend. I can't seem to get it to apply the width values I have manually styled with. I think the ramp function will do this however I get the following error with your code? Syntax error. Line 2: Invalid code: marker-width: ramp([capacity], (30,40,50,60,70,80), (20000,30000,40000,50000,60000,70000), >); – ProudGIS Apr 26 '17 at 16:28

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.