Changes between Version 31 and Version 32 of Help/Styles/MapCSSImplementation
- Timestamp:
- 2013-12-29T14:32:07+01:00 (12 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Help/Styles/MapCSSImplementation
v31 v32 4 4 A MapCSS style sheet has rules of the form 5 5 {{{ 6 #!mapcss 6 7 selector { 7 8 prop: value; 8 ...9 /* ... */ 9 10 prop: value; 11 /* and/or */ 12 set: class; 13 set: .class; 10 14 } 11 15 }}} … … 26 30 Some basic examples: 27 31 {{{ 28 #!html 29 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 32 #!mapcss 30 33 /* applied to ways with a tag highway=residential */ 31 34 way[highway=residential] { /* the styles */} … … 39 42 area[amenity=parking][access=public], area[amenity=parking][!access] {...} 40 43 relation[type=route][route=foot] > way::relation_underlay {..} 41 </pre>42 44 }}} 43 45 … … 75 77 Matches with any area regardless of whether the area border is only modelled with a single way or with a set of ways glued together with a relation. 76 78 {{{ 77 #!html 78 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 79 #!mapcss 79 80 area[natural=beach] {...} 80 81 /* ... is equal to ... */ 81 82 way[natural=beach], relation[type=multipolygon][natural=beach] {...} 82 </pre>83 83 }}} 84 84 Note that {{{area}}} selects unclosed ways as well, so it may be useful to add the {{{:closed}}} pseudo class. The JOSM Validator will give a warning for unclosed ways that have an area style. … … 91 91 The {{{meta}}} selector starts a special rule that should stand at the beginning of the file. It gives some general information on the style sheet. All software that supports MapCSS should be able to parse this sections without errors, so do not use exotic syntax extensions in this part. 92 92 {{{ 93 #!html 94 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 93 #!mapcss 95 94 meta { 96 95 title: "Parking lanes"; /* title shown in the menu */ 97 96 icon: "images/logo.png"; /* small icon shown in the menu next to the title */ 98 97 } 99 </pre>100 98 }}} 101 99 }}} … … 107 105 Some style information not specific to nodes, ways or relations. 108 106 {{{ 109 #!html 110 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 107 #!mapcss 111 108 canvas { 112 109 background-color: #ffffea; … … 114 111 default-lines: false; 115 112 } 116 </pre>117 113 }}} 118 114 {{{#!th … … 177 173 Example: 178 174 {{{ 179 #!html 180 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 175 #!mapcss 181 176 /* 182 177 * only matches for a way which is a child of a relation with tags … … 184 179 */ 185 180 relation[type=route][route=foot] > way {...} 186 </pre>187 181 }}} 188 182 … … 202 196 Example: 203 197 {{{ 204 #!html 205 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 198 #!mapcss 206 199 /* 207 200 * matches for a highway which has at least one node tagged as traffic_calming=* 208 201 */ 209 202 node[traffic_calming] < way[highway] {...} 210 </pre>211 203 }}} 212 204 … … 236 228 {{{#!td align=left valign=top 237 229 {{{ 238 #!html 239 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 230 #!mapcss 240 231 way[highway=residential] /* without quotes always case insensitive */ 241 232 node[name="My name"] /* use quotes for if value includes spaces or if case sensitive matching is important */ … … 243 234 node["ÖPVN"=tram] /* use quotes for tag keys with special characters */ 244 235 /* note that these are not common in OSM at the moment */ 245 </pre>246 236 }}} 247 237 }}} … … 255 245 {{{#!td align=left valign=top 256 246 {{{ 257 #!html 258 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 247 #!mapcss 259 248 way[highway!=residential] /* without quotes always case insensitive */ 260 249 node[name!="My name"] /* use quotes if value includes spaces or if case sensitive matching is important */ 261 250 node["MY_Special_TAG"!="another value"] /* use quotes for tag names if case sensitive matching is required */ 262 251 node["name:fr"!="mon nome"] /* use quotes for tag names with special characters like colons*/ 263 </pre>264 252 }}} 265 253 }}} … … 274 262 {{{#!td align=left valign=top 275 263 {{{ 276 #!html 277 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 264 #!mapcss 278 265 node[population > 50000] /* without quotes always case insensitive */ 279 266 node[ele <= 3000] /* use quotes for if value includes spaces or if case sensitive matching is important */ 280 </pre>281 267 }}} 282 268 }}} … … 290 276 {{{#!td align=left valign=top 291 277 {{{ 292 #!html 293 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 278 #!mapcss 294 279 node[name ^= "myprefix"] /* value starts with 'myprefix' */ 295 </pre>296 280 }}} 297 281 }}} … … 305 289 {{{#!td align=left valign=top 306 290 {{{ 307 #!html 308 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 291 #!mapcss 309 292 node[name $= "mypostfix"] /* value ends with 'mypostfix' */ 310 </pre>311 293 }}} 312 294 }}} … … 320 302 {{{#!td align=left valign=top 321 303 {{{ 322 #!html 323 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 304 #!mapcss 324 305 node[name *= "my substring"] /* value contains the substring 'my substring' */ 325 </pre>326 306 }}} 327 307 }}} … … 335 315 {{{#!td align=left valign=top 336 316 {{{ 337 #!html 338 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 317 #!mapcss 339 318 *[vending~=stamps] /* the tag value for the tag 'vending' consists of a list of ;-separated values */ 340 319 /* and one of these values is 'stamps' */ 341 </pre>342 320 }}} 343 321 }}} … … 352 330 {{{#!td align=left valign=top 353 331 {{{ 354 #!html 355 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 332 #!mapcss 356 333 name[name=~/^My_pattern.*/] /* the value of the tag 'name' matches with the regular expression '^My_pattern.*' */ 357 334 /* Note, that reqular expressions have to be enclosed in /.../ */ 358 </pre>359 335 }}} 360 336 }}} … … 369 345 {{{#!td align=left valign=top 370 346 {{{ 371 #!html 372 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 373 *[surface!~/paved|unpaved/]</pre> 347 #!mapcss 348 *[surface!~/paved|unpaved/] 374 349 }}} 375 350 }}} … … 389 364 {{{#!td align=left valign=top 390 365 {{{ 391 #!html 392 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 366 #!mapcss 393 367 way[highway] /* matches any way with a tag 'highway' */ 394 368 way["VALSOU"] /* use quotes if case sensitive matching is required */ 395 369 way["name:fr"] /* use quotes if the tag name includes special caracters (white space, colons, etc.) */ 396 </pre>397 370 }}} 398 371 }}} … … 403 376 {{{#!td align=left valign=top 404 377 {{{ 405 #!html 406 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 378 #!mapcss 407 379 way[!highway] /* matches any way which does not have a tag 'highway' */ 408 380 way[!"VALSOU"] /* use quotes if case sensitive matching is required */ 409 381 way[!"name:fr"] /* use quotes if the tag name includes special caracters (white space, colons, etc.) */ 410 </pre>411 382 }}} 412 383 }}} … … 434 405 {{{#!td align=left valign=top 435 406 {{{ 436 #!html 437 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 407 #!mapcss 438 408 way[oneway?] /* matches any way with a truth value in the tag 'oneway' */ 439 </pre>440 409 }}} 441 410 }}} … … 446 415 {{{#!td align=left valign=top 447 416 {{{ 448 #!html 449 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 417 #!mapcss 450 418 way[oneway?!] /* matches any way with a false value in the tag 'oneway' */ 451 </pre>452 419 }}} 453 420 }}} … … 458 425 If the parent is a relation, you can formulate conditions for the ''role'' a member objects has in this relation. 459 426 {{{ 460 #!html 461 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 427 #!mapcss 462 428 relation[type=route] >[role="link"] way { /* matches any way which is a member of route relation with role 'link' */ 463 429 color: blue; 464 430 } 465 </pre>466 431 }}} 467 432 … … 484 449 {{{#!td align=left valign=top 485 450 {{{ 486 #!html 487 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 451 #!mapcss 488 452 relation >[role=residential] way /* without quotes always case insensitive */ 489 453 relation >[role="My name"] way /* use quotes for if the role value includes spaces or if case sensitive matching is important */ 490 </pre>491 454 }}} 492 455 }}} … … 498 461 499 462 {{{ 500 #!html 501 <pre class="mapcss" style="text-align: left; font: Courier; font-size: 10pt; background:rgb(242,243,210); border-style: dotted; border-width:1pt; border-color:darkGray; padding: 5pt"> 463 #!mapcss 502 464 relation[type=route] >[index=1] way { /* matches the first way which is a member of route relation */ 503 465 color: blue; 504 466 } 505 </pre>506 467 }}} 507 468 … … 540 501 Layers can be used to create more than one style for a single object. Here is an example: 541 502 {{{ 503 #!mapcss 542 504 way[highway=secondary] { 543 505 width: 3; … … 574 536 It overrides all existing subparts, so 575 537 {{{ 538 #!mapcss 576 539 way::A { a; } 577 540 way::B { b; } … … 580 543 is equivalent to 581 544 {{{ 545 #!mapcss 582 546 way::A { a; } 583 547 way::B { b; } … … 587 551 And it initializes new subparts. In other words: 588 552 {{{ 553 #!mapcss 589 554 way::* { a; } 590 555 way::A { b; } … … 592 557 is equivalent to 593 558 {{{ 559 #!mapcss 594 560 way::A {} 595 561 way::* { a; } … … 598 564 which is in turn the same as 599 565 {{{ 566 #!mapcss 600 567 way::A { a; } 601 568 way::A { b; } … … 603 570 or 604 571 {{{ 572 #!mapcss 605 573 way::A { a; b; } 606 574 }}} … … 611 579 Rules with common declaration block can be grouped into one: 612 580 {{{ 581 #!mapcss 613 582 area[landuse=forest] { color: green; width: 2; } 614 583 area[natural=wood] { color: green; width: 2; } … … 616 585 is the same as 617 586 {{{ 587 #!mapcss 618 588 area[landuse=forest], area[natural=wood] { color: green; width: 2; } 619 589 }}} 620 590 621 591 === Classes === 592 You may assign classes to matched elements, and define other selectors using those classes: 593 594 {{{ 595 #!mapcss 596 /* assigning classes */ 597 selector { 598 set class; 599 /* or equivalently */ 600 set .class; 601 } 602 603 /* matching classes */ 604 way.class, node[foo=bar].class { 605 /* ... */ 606 } 607 }}} 608 609 610 Example for assigning/matching a class named `path`: 611 {{{ 612 #!mapcss 613 way[highway=footway] { set path; color: #FF6644; width: 2; } 614 way[highway=path] { set path; color: brown; width: 2; } 615 way.path { text:auto; text-color: green; text-position: line; text-offset: 5; } 616 }}} 622 617 623 618 … … 859 854 * circle symbol for house number with size depending of the number of digits 860 855 {{{ 856 #!mapcss 861 857 node[addr:housenumber] { 862 858 symbol-shape: circle; … … 879 875 * invert colors 880 876 {{{ 877 #!mapcss 881 878 *::* { 882 879 color: eval(rgb(1 - red(prop(color)), 1 - green(prop(color)), 1 - blue(prop(color)))); … … 886 883 * random stuff 887 884 {{{ 885 #!mapcss 888 886 way { 889 887 width: eval(random() * 20); … … 894 892 * regexp matching example: change "nameXXXsubname" to "name::subname" 895 893 {{{ 894 #!mapcss 896 895 *[name=~/.+XXX.+/] 897 896 { … … 912 911 * JOSM MapCSS is not liberal with white spaces in the selector, they are only permitted before and after ''comma'' and ''greater sign'' (Grouping and Child combinator). 913 912 * {{{way[oneway=yes]}}} does not have any magic, you can use {{{way[oneway?]}}} instead 914 * {{{set}}} is not supported, instead of915 {{{916 way[highway=footway] { set path; color: #FF6644; width: 2; }917 way[highway=path] { set path; color: brown; width: 2; }918 way.path { text:auto; text-color: green; text-position: line; text-offset: 5; }919 }}}920 you can write921 {{{922 way[highway=footway] { path-set : true; color: #FF6644; width: 2; }923 way[highway=path] { path-set : true; color: brown; width: 2; }924 way[eval(prop(path-set))] { text:auto; text-color: green; text-position: line; text-offset: 5; }925 }}}926 913 * no stacking of declaration blocks, you have to provide explicit layer names 927 914 * no {{{@import}}} … … 945 932 * Text label is placed in the center of the icon. For compatibility with Halcyon put 946 933 {{{ 934 #!mapcss 947 935 node { text-anchor-vertical: center; text-anchor-horizontal: center; } 948 936 }}}