I'd like to create a zoomable world map where countries/territories are color-coded. This is a pretty standard request and Carto has a nice example.

However, in standard maps like this, small countries are practically invisible unless you zoom in, so I'd like to highlight them the way Wikipedia often does:

enter image description here

Larger version here, and note that small countries have a circle superimposed on top.

Is there an existing library/package/... that can do this in a popular tool like Carto? Bonus points if the circles go away when you zoom in close enough. The closest I could find with some searching was Using 'Style by Value' with Point Geometries, but this uses dots instead of country polygons, which is not what I'm looking to do.


You can add a second layer with just the small countries. Using ST_Area(the_geom) could give you an idea about the ones you are interesting to filter. Then you can apply something like ST_PointOnSurface to get the centroid of the polygons. Finally, you should use conditional styling in combination with zoom level values to show and hide the point layer.

Example of the query in order to select small countries based on their area and generate points on their main polygon area:

select cartodb_id, 
       st_pointonsurface(the_geom) as the_geom, 
from   table
where  st_area(the_geom) < [LIMIT]

Example of CartoCSS to style by zoom level values:

#layer[zoom < 5]{
    marker-fill: #FFA300;

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.