A short example of CartoCSS class-based line rendering.

CartoCSS is everywhere it seems. Well, it’s in Mapbox Studio and CartoDB, as well as whatever hand rolled option you choose. (However it is not geoserver CSS, though it looks somewhat similar). I used CartoCSS to render the below image. It’s a nordic ski map and has a number of line style features worth noting.

1) The trails are catagorised green – blue – black to indicate difficulty.
2) The trails are labelled.
3) Some trails have an outline to indicate it is floodlit.

To achieve this effect we need to consider the line data. The data contains a “name”, a “difficulty” classification, and a “floodlit” boolean. From this we can define the below CartoCSS description. Note, the floodlit ::case must come first, so it is drawn first, if we leave this till the end it will obsure or decolorize, the thinner trail line, by being rendered on top. Additionally, the floodlit style is almost transparent, to give the effect of lighting with out changing the core informational content of the data layer.

#otway_ski_trails {
 line-width: 2.5;
 line-opacity: 0.7;
 
 [floodlit=true]{
 ::case {
 line-width: 12;
 line-color:#FFE403;
 line-opacity: 0.2;
 }
 }
 [difficulty="black"] {
 line-color: #000000;
 }
 [difficulty="blue"] {
 line-color: #1F78B4;
 }
 [difficulty="double black"] {
 line-color: #000000;
 line-dasharray: 10, 4;
 }
 [difficulty="green"] {
 line-color: #33A02C;
 }
 
 ::labels {
 text-name: [name];
 text-face-name: 'Open Sans Bold';
 text-size: 10;
 text-label-position-tolerance: 10;
 text-fill: #575757;
 text-halo-fill: #FFF;
 text-halo-radius: 1;
 text-dy: 0;
 text-allow-overlap: true;
 text-placement: line;
 text-placement-type: simple;
 }
}

The full effect of this style can be seen on our Otway Nordic Ski Center trail map. This map was built using Mapbox base maps, CartoDB line work, all brought together on a LeafletJS map.

Image: Flipboard
Sharing options
blue coupe in front of pink house

Observations • Darren Wiens

Python-based Computer Vision in the Browser

Prototyping and Python are big parts of what I do at Sparkgeo, so when PyScript was announced at PyCon US 2022, I was all ears. PyScript, along with…

Observations • Gordon Logie

Wildfires and Flood Damage

A data-backed research project examining linkages between the wildfires and subsequent flood damages that occurred in BC, 2021.

black and gray binoculars on brown wooden dock

Observations • Darren Wiens

A Free Open Source Full Motion Video Workflow

FOSS FMV FTW: A tutorial on how to accurately map video onto a map, using open source software and standards (STAC & STAC API, Mapbox, MapLibre).

Need a geospatial partner?

Our team complements organizations like yours—by providing on-tap access to geospatial, analytics, and mapping expertise.

Let’s talk

Join our team?

We’re always looking for skilled technologists to help us build the future of geospatial. Got a minute to find out more about us?

Working Here

Image: Flipboard
Sharing options