0

I am currently working with project.mml and associated .mss files. I am looking at replacing OSM admin labels with a secondary source and I am wondering how Carto does the labeling along the lines labeled by

#admin-text[zoom > 11] {
  text-name: "[name]";
  text-face-name: @book-fonts;
  text-fill: @admin-boundaries;
  text-halo-radius: @standard-halo-radius;
  text-halo-fill: @standard-halo-fill;
  text-placement: line;
  text-clip: true;
  text-vertical-alignment: middle;
  text-dy: -10;

My understanding (being new to this), text-dy is the offset, but I am wondering how it knows to display the labels correctly on the left or right side. I assume that there are multiple OSM boundary lines overlapping and depending on the direction of the line then the label appears -10 offset.

The data that I want to use, has a left and a right name attribute. Therefore I assume that I could add to separate labels, 1 for the left with a -10 offset and 1 for the right with a +10 offset in theory.

What are Carto or OSM left and right naming conventions?

1

I managed to do this by adding 2 text layers in the project.mml file as below (and the same for left name)

{
        "name": "bnd_lines_right_text",
        "srs-name": "3395",
        "geometry": "linestring",
        "class": "",
        "srs": "+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
        "Datasource": {
          "estimate_extent": "false",
          "extent": "-20037507.843,-30198185.170,20037507.843,30198185.170",
          "table": "(select wkb_geometry, right_name, admin_level, type from osm_bnd_lines ORDER BY admin_level DESC) AS bnd_lines_right_text",
          "geometry_field": "wkb_geometry",
          "srid": "3395",
          "type": "postgis",
          "key_field": "",
          "dbname": "osm_bdy_test",
          "host": "ximena",
          "user": "postgres"
        },
        "extent": [
          -180,
          -90,
          180,
          90
        ],
        "id": "admin-low-zoom",
        "properties": {
          "maxzoom": 10,
          "minzoom": 4
        },
        "advanced": {}
      },

Then adding the following to the mss file

#bnd_lines_left_text {
  text-name: "[left_name]";
  text-face-name: @book-fonts;
  text-fill: @admin-boundaries;
  text-halo-radius: @standard-halo-radius;
  text-halo-fill: @standard-halo-fill;
  text-placement: line;
  text-clip: true;
  text-vertical-alignment: middle;
  text-dy: 10;
}

 #bnd_lines_right_text {
  text-name: "[right_name]";
  text-face-name: @book-fonts;
  text-fill: @admin-boundaries;
  text-halo-radius: @standard-halo-radius;
  text-halo-fill: @standard-halo-fill;
  text-placement: line;
  text-clip: true;
  text-vertical-alignment: middle;
  text-dy: -10;
}

Seems to work very well.

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.