1

Does TileMill have possibility to design features/labels in my case based on more than one command? I have this carto CSS code

#mainroad_label[type='primary'][zoom>13], {
  text-name:'[name]';
  text-face-name:@sans;
  text-placement:line;
  text-fill:@road_text;
  text-halo-fill:@road_halo;
  text-halo-radius:1;
  text-min-distance:60;
  text-size:9.5;

But i need one type of "primary" road at the zoom level from 12! SO i have written this code:

 #mainroad_label[type='primary'][zoom>13], {
          text-name:'[name]';
          text-face-name:@sans;
          text-placement:line;
          text-fill:@road_text;
          text-halo-fill:@road_halo;
          text-halo-radius:1;
          text-min-distance:60;
          text-size:9.5;
    [name='Leave Road'] [zoom>=12] {
      text-name: '[name]';
      text-face-name:@sans;
      text-placement:line;
      text-fill:@road_text;
      text-halo-fill:@road_halo;
      text-halo-radius:1;
      text-size:10; } 
}

It did not show me this road at Z12 because "Leave Road" is "primary" road and obviously all "primary" roads are shown from zoom>13. When i have changed it to zoom>=12 it showed me all "primary" roads but i need show only "Leave Road" primary road at this zoom level. Is there any way how can i do it? Simply i would write something like [type='primary'], [name='Leave Road'] {.....} The result will be only this one "primary" road with "Leave Road" name shown at my target zoom level. Thanks

1

I think you are looking for this kind-of idea. All the common styling are put in one section of the the style. These will cascade to other parts of the style. At zoom=12 the text-size is changed and name is added to the condition. Everything paints from zoom 13 and beyond. At least that is what I think you are trying to do. The idea is from the MapBox "Geography Class" sample project. Look at the labels.mss #country-name style for additional ideas.

#mainroad_label {
     text-name:'[name]';
     text-face-name:@sans;
     text-placement:line;
     text-fill:@road_text;
     text-halo-fill:@road_halo;
     text-halo-radius:1;
     text-min-distance:60;

     [type='primary'][zoom=12][name='Leave Road'] {
         text-size:10;
     } 
     [type='primary'][zoom>=13] {
         text-size:9.5;
     }
}

Here is a revision based on your comment. The idea is that text-name: needs to be placed in each conditional. I would have you think and arrange your code in zoom order first. This will help you clarify you goals.

#mainroad_label {
   text-face-name:@sans;
   text-placement:line;
   text-fill:@road_text;
   text-halo-fill:@road_halo;
   text-halo-radius:1;

   /*
    * Show only one important road's label at zoom 12.
    */
   [zoom=12][type='primary'][name='Orchard Road'] {
       text-size:9.5;
       text-name: '[name]';
   }
   /*
    * Show all road labels at zoom 13 and below
    * [][] means "logical and" while , means "logical or".
    * The or condition via the comma, cleans up displaying
    * all road labels starting at zoom 13.  I exclude
    * 'Orchard Road' in this group so that I can style it
    * elsewhere. 
    */
   [zoom>=13][type='primary'][name!='Orchard Road'],
   [zoom>=13][type='secondary'],
   [zoom>=13][type='tertiary'] {
       text-size:9.5;
       text-name: '[name]';
   }
   /*
    * Continue to make Orchard Road special at zoom 13 and below.
    * This condition sets us up for zoom 14 styling.
    */
   [zoom=13][type='primary'][name='Orchard Road'] {
       text-size:9.5;
       text-name: '[name]';
   }
   /*
    * Make Orchard Road stand out at zoom 14 with a larger
    * character size.
    */
   [zoom>=14][type='primary'][name='Orchard Road'] {
       text-size:13;
       text-name: '[name]';
   }
}
| improve this answer | |
  • My code looks like this: #mainroad_label { text-name: '[name]'; text-face-name:@sans; text-placement:line; text-fill:@road_text; text-halo-fill:@road_halo; text-halo-radius:1; [type='primary'][zoom>=14][name='Orchard Road'] { text-size:13; } [type='primary'][zoom>12][name='Orchard Road']{ text-size:9.5; } [type='primary'][zoom>13] { text-size:9.5;} [type='secondary'][zoom>13] { text-size:9.5;} [type='tertiary'][zoom>13] { text-size:9.5;} } But it still doesn't look as i would like. + "tertiary" roads are visible at zoom level 12. – L.s. Aug 14 '14 at 12:30
  • I don't understand how it's possible because [type='tertiary'][zoom>13] from 13 but it shows at the zoom level 12 too. – L.s. Aug 14 '14 at 12:33
  • Thank you many times! I'm gonna try it and play with cartoCSS a bit. – L.s. Aug 15 '14 at 7:49
  • When i've used this code it work #mainroad_label { [zoom=12][type='primary'][name='Orchard Road'] { text-name:'[name]'; text-face-name:@sans; text-placement:line; text-fill:@road_text; text-halo-fill:@road_halo; text-halo-radius:1; text-size:6; text-name: '[name]';} } I got just one road at Z12. Anyway is there any option to do "text" bigger "6" is shown at the map but when i use bigger number like 7 or 8 text doesn't show me obviously. It doesn't fit up with road or something like that. – L.s. Aug 15 '14 at 8:58
  • I cannot see what you are seeing. Perhaps at zoom 12 a size larger than 6 is too big for that zoom level and cannot render? I have seen a similar problem that occurs when you are at zoom 18 or 19 and the road is to short for the length of the road name. There's just not enough room to render the text. – Greg Aug 15 '14 at 14:50

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.