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

Observations • Will Cadell

User-Centred Geospatial

The first thing we do is focus on the problem, then we deliver our advice with an ability to back our words up with code.

Observations • Will Cadell

Strategic Geospatial

Making a map may be a daily activity for many, but thinking about why we do something and whether that activity is fit for purpose differentiates those who are thinking…

Observations • Brian Bancroft

Build a React MapboxGL Component with Hooks

Using React Hooks to build a Mapbox GL React Function Component.

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