Beacons, lightsabers, fireflies and other cartography tricks in CARTO BUILDER
Almost one year from last blog post, here we are again. Lots of things have happened since then. I would like to mention some key events such as CARTO Locations, SIGLibre (where I gave a talk about A series of unfortunate maps) and several GeoInquietos Madrid talks and workshops.
This time I will give you some easy tips to elaborate very useful artifacts with BUILDER STYLE UI but also switching to a more pro mode with CartoCSS. Before reading further, I will recommend to have a look at CARTO’s Styling Guides. They were written by Mamata Akella, the real expert here. But if you want to skip go through those guides, log into your CARTO account and follow the instructions below. In doing so, at the end of the day, you will be able to create outstanding visualizations in a manner of minutes displaying markers as beacons and fireflies among others.
How to convert markers into beacons
A very common use case in cartography is highlighting some elements to stand out from the rest. A traffic map showing accidents locations as intermittent markers could be a good example. I have learnt this trick from the people of Geographica. Basically, you need to create an animated map with just two steps. But let me show you how to do it step by step:
- First, create a New Map connecting
Roadsdataset from the Data Library.
- Add a new empty layer.
- Rename them as “Roads” (instead of
ne_10m_roads) and “Accidents” (I also recommend changing the dataset name to
accidents). You can rename the map as well as “Roads and accidents”.
- I have also filtered the roads, showing just the ones from North America. This (optional) step can be done with a simple SQL query like:
SELECT * FROM ne_10m_roads WHERE continent like ‘North America’
- Change the basemap from “Positron” to “Dark Matter Lite”.
- Style the roads by
- Add some points to the “Accidents” layer using the
- Using the SQL panel in the DATA tab, we are going to duplicate our data adding to each row a new
WITH temp AS (
the_geom, the_geom_Webmercator, 1 as step
the_geom, the_geom_Webmercator, 2 as step
SELECT *, row_number() over() as cartodb_id FROM temp
5. Create an animated map from the STYLE tab selecting the
step column. Then set the
STEPS parameters to
2. After removing the time series widget, you should have a map similar to this one:
How to transform lines into lightsabers
I am huge fan of Star Wars, so when John Nelson publish this blogpost about transforming lines into lightsabers (I mean firefly lines), I quickly run to replicate it with CartoCSS. So we are going to follow his same tutorial but applying it within the CartoCSS console:
- Create a New Map selecting
world_border_hddataset from the Data Library.
- Rename both the layer and the dataset as “Countries” and “Lightsaber World Borders”.
- Again, change the basemap to a dark one.
- Go to the STYLE tab and switch to the CartoCSS panel. Replace the standard code with this one to make your lines glow:
5. Don’t forget to publish and share your map! You can apply the same trick with points (but you would need to use
marker properties instead).
How to assign colors and numeric values to style properties
Imagine that you want to style your layer base upon a column value. Now you can do it thanks to the STYLE BY VALUE option in BUILDER. After applying this technique, if you are curious enough, switch to the CartoCSS panel. There you can check the code which convert UI options to choropleths, category and/or bubble maps. These are TurboCARTO
ramp functions. TurboCARTO is great when you do not know about your data structure but also works perfectly when filtering by widgets in BUILDER.
But if you know your data, vanilla CartoCSS is enough (and sometimes recommended). In this last tutorial, I will show you another hidden trick: assigning values directly to a CartoCSS property. This time I have prepared a dataset for you. You can download it from this link. As you can see they are all the Madrid Metro lines with one string column added storing the color hexcodes for each line.
- Create a New Map selecting the
madrid_metro_linesdataset which we have previously imported.
- Secondly, rename the map and layer as “Madrid Metro Lines” and “Lines” respectivaly.
- Go to the STYLE tab and switch to the CartoCSS panel, and replacte the
Again, you can use the same technique with
marker-width as explained here.
I would love to hear your comments about these techniques!
*This post was originally published on my personal blog.