leafletmapboxgeojsoncartographycartocss

How to serve styled vector map data via CartoCSS


I've got an example data set of lines and points, representing peoples' journey to work and where they feel at risk from road accidents.

Now, the data have attributes such as Place (Home, Work, Danger) and the severity of accidents they fear in different places. So the wider question is how to visualise this on a web map. For that I've looked into Google Maps, Leaflet and OpenLayers3. Each of these looks great and allow nice styling but none, to my eye, have the neatness of CartoCSS for fast, complex and intuitive styling, like the code below used to create the image below:

So I tried it out in tile mill and this is what I came up with, after converting the things to raster tiles via TileMill.

mb raster

But this is a silly way to do things: it cannot overlay a base layer and would be much more efficient to just serve the vector data and style them in the client side, perhaps using something like mapbox.js. But I cannot work out how to use the lovely CartoCSS language in the client side to style GeoJSON files. (How) Is this possible?

p.s. here's how I styled the above map

#tlines {
  line-width:1;
  line-color: #0b0;
}

#tpoints.points{
  marker-width: 6;
}


#tpoints.points[Place='Danger'] {
  marker-fill:#db0d0d;
}
#tpoints.points[Place='Home'] {
  marker-fill:#db0;
}

#tpoints.points[Severity='1']{
  marker-width: 4;}
#tpoints.points[Severity='2']{
  marker-width: 6;}
#tpoints.points[Severity='3']{
  marker-width: 10;}

Solution

  • I cannot work out how to use the lovely CartoCSS language in the client side to style GeoJSON files. (How) Is this possible?

    It is not possible to use CartoCSS for styling features browser side.

    To learn how to style GeoJSON in Mapbox.js/Leaflet.js take a look at the docs here: