0

I am attempting to adjust the visibility of a polygon layer in Carto by zoom level. To keep it simple for now I am looking to have the opacity of 1 from zoom 0-7 and opacity 0 from zoom 8+. I am working directly in Carto (not tilemill, or elsewhere) and have tried a few methods. Most notably, this method (found on this question) only worked for point data, not polygons.

Getting the zooms to adjust for point data worked using the following, now I'm just trying to adapt it for use with polygons.

    #layer {
    marker-allow-overlap: true;
    [zoom = 0]{opacity:1}
    [zoom = 8]{opacity:0}
    }

Right now I've gotten myself stuck at

    #layer {
    [zoom = 0]{opacity:1}
    [zoom = 8]{opacity:0}
    }
0

Take a look to this guide. Zooms need to be specified as ranges, you are changing opacity only for the zoom 0 and 8.

Example: go to http://bl.ocks.org/jsanz/raw/d945737eb42ca83654301e66dac365cb/ and put this SQL to draw polygons

select * from world_borders

And this CartoCSS to render with different opacity based on zoom.

#layer{
  polygon-fill      : #fabada;
  line-color        : blue;
  line-opacity      : 0.5;
  line-width        : 3;

  [zoom>5]{
    line-color      : red;
    polygon-opacity : 0;
    line-opacity    : 1;
  }
}
  • Thank you. That's one of the items I linked to in the question. My issue is that it works on point data but not polygons and I cannot find in their documentation the necessary command for use with polygons. Any suggestions? – Samantha Bamberger Dec 1 '17 at 15:47
  • Added example to my answer, polygon opacity is driven by the polygon-opacity property. – Jorge Sanz Dec 4 '17 at 11:12

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.