| 58 | | }}} |
| | 114 | </pre> |
| | 115 | }}} |
| | 116 | }}} |
| | 117 | |
| | 118 | === Child selector === |
| | 119 | If a node is part of a way, we say that it is a ''child'' of this way. Similarly, if a node, a way, or a relation is a member |
| | 120 | of a relation, we say, that it is a ''child'' of this relation. |
| | 121 | |
| | 122 | In MapCSS you can use a '''child selector''' which matches only if both the parent and the child object match. |
| | 123 | |
| | 124 | Example: |
| | 125 | {{{ |
| | 126 | #!html |
| | 127 | <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"> |
| | 128 | /* |
| | 129 | * only matches for a way which is a child of a relation with tags |
| | 130 | * type=route and route=foot |
| | 131 | */ |
| | 132 | relation[type=route][route=foot] > way {...} |
| | 133 | </pre> |
| | 134 | }}} |
| | 135 | |
| | 136 | Notes: |
| | 137 | * Zoom selector and Layer identifier are only relevant for the part to the right of the > sign. |
| | 138 | |
| | 139 | |
| | 140 | === Parent selector === |
| | 141 | In addition to child selectors, JOSMs supports the the notion of a '''parent selector'''. Note, that parent selectors are a |
| | 142 | JOSM-specific extension of MapCSS not present in other MapCSS implementations. |
| | 143 | |
| | 144 | Similar to a child selector, a parent selector only matches if if both the parent and the child object match. In contrast to |
| | 145 | to the child selector, the character < is used. In contrast to the child selector, the right hand side of the selector expression |
| | 146 | denotes the selector for the parent object. |
| | 147 | |
| | 148 | Example: |
| | 149 | {{{ |
| | 150 | #!html |
| | 151 | <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"> |
| | 152 | /* |
| | 153 | * only matches for a way which is a child of a relation with tags |
| | 154 | * type=route and route=foot |
| | 155 | */ |
| | 156 | way < relation[type=route][route=foot] {...} |
| | 157 | </pre> |
| | 158 | }}} |
| | 159 | |
| | 160 | === Condition selector === |
| | 161 | Selectors can include a set of conditions. If any of these conditions evaluates to false, the selector doesn't match and the style |
| | 162 | rule isn't applied. |
| | 163 | |
| | 164 | An '''attribute selector''' specifies a condition on a tag of an OSM object. |
| | 165 | |
| | 166 | [=#condition_selector_operators] |
| | 167 | {{{#!th align=left valign=top |
| | 168 | '''Operator''' |
| | 169 | }}} |
| | 170 | {{{#!th align=left valign=top |
| | 171 | '''Description''' |
| | 172 | }}} |
| | 173 | {{{#!th align=left valign=top |
| | 174 | '''Example''' |
| | 175 | }}} |
| | 176 | |------------------------------------------------------------------------------- |
| | 177 | {{{#!td align=left valign=top |
| | 178 | = |
| | 179 | }}} |
| | 180 | {{{#!td align=left valign=top |
| | 181 | Exact match of the value. |
| | 182 | }}} |
| | 183 | {{{#!td align=left valign=top |
| | 184 | {{{ |
| | 185 | #!html |
| | 186 | <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"> |
| | 187 | way[highway=residential] /* without quotes always case insensitive */ |
| | 188 | node[name="My name"] /* use quotes for if value includes spaces or if case sensitive matching is important */ |
| | 189 | node["MY_Special_TAG"="another value"] /* use quotes for tag names if case sensitive matching is required */ |
| | 190 | node["name:fr"="mon nome"] /* use quotes for tag names with special characters like colons*/ |
| | 191 | </pre> |
| | 192 | }}} |
| | 193 | }}} |
| | 194 | |------------------------------------------------------------------------------- |
| | 195 | {{{#!td align=left valign=top |
| | 196 | != |
| | 197 | }}} |
| | 198 | {{{#!td align=left valign=top |
| | 199 | Value not equal |
| | 200 | }}} |
| | 201 | {{{#!td align=left valign=top |
| | 202 | {{{ |
| | 203 | #!html |
| | 204 | <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"> |
| | 205 | way[highway!=residential] /* without quotes always case insensitive */ |
| | 206 | node[name!="My name"] /* use quotes if value includes spaces or if case sensitive matching is important */ |
| | 207 | node["MY_Special_TAG"!="another value"] /* use quotes for tag names if case sensitive matching is required */ |
| | 208 | node["name:fr"!="mon nome"] /* use quotes for tag names with special characters like colons*/ |
| | 209 | </pre> |
| | 210 | }}} |
| | 211 | }}} |
| | 212 | |------------------------------------------------------------------------------- |
| | 213 | {{{#!td align=left valign=top |
| | 214 | <,>, <=, >= |
| | 215 | }}} |
| | 216 | {{{#!td align=left valign=top |
| | 217 | Comparision for numeric values. |
| | 218 | |
| | 219 | }}} |
| | 220 | {{{#!td align=left valign=top |
| | 221 | {{{ |
| | 222 | #!html |
| | 223 | <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"> |
| | 224 | node[population > 50000] /* without quotes always case insensitive */ |
| | 225 | node[ele <= 3000] /* use quotes for if value includes spaces or if case sensitive matching is important */ |
| | 226 | </pre> |
| | 227 | }}} |
| | 228 | }}} |
| | 229 | |------------------------------------------------------------------------------- |
| | 230 | {{{#!td align=left valign=top |
| | 231 | ^= |
| | 232 | }}} |
| | 233 | {{{#!td align=left valign=top |
| | 234 | Prefix match |
| | 235 | }}} |
| | 236 | {{{#!td align=left valign=top |
| | 237 | {{{ |
| | 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"> |
| | 240 | node[name ^= "myprefix"] /* value starts with 'myprefix' */ |
| | 241 | </pre> |
| | 242 | }}} |
| | 243 | }}} |
| | 244 | |------------------------------------------------------------------------------- |
| | 245 | {{{#!td align=left valign=top |
| | 246 | $= |
| | 247 | }}} |
| | 248 | {{{#!td align=left valign=top |
| | 249 | Postfix match |
| | 250 | }}} |
| | 251 | {{{#!td align=left valign=top |
| | 252 | {{{ |
| | 253 | #!html |
| | 254 | <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"> |
| | 255 | node[name $= "mypostfix"] /* value ends with 'mypostfix' */ |
| | 256 | </pre> |
| | 257 | }}} |
| | 258 | }}} |
| | 259 | |----------------------------------------------- |
| | 260 | {{{#!td align=left valign=top |
| | 261 | *= |
| | 262 | }}} |
| | 263 | {{{#!td align=left valign=top |
| | 264 | Substring match |
| | 265 | }}} |
| | 266 | {{{#!td align=left valign=top |
| | 267 | {{{ |
| | 268 | #!html |
| | 269 | <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"> |
| | 270 | node[name *= "my substring"] /* value contains the substring 'my substring' */ |
| | 271 | </pre> |
| | 272 | }}} |
| | 273 | }}} |
| | 274 | |------------------------------------------------------------------------------- |
| | 275 | {{{#!td align=left valign=top |
| | 276 | =~ |
| | 277 | }}} |
| | 278 | {{{#!td align=left valign=top |
| | 279 | * List membership |
| | 280 | * [http://download.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html#sum Regular expression] match |
| | 281 | |
| | 282 | }}} |
| | 283 | {{{#!td align=left valign=top |
| | 284 | {{{ |
| | 285 | #!html |
| | 286 | <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"> |
| | 287 | |
| | 288 | *[vending~=stamps] /* the tag value for the tag 'vending' consists of a list of ;-separated values */ |
| | 289 | /* and one of these values is 'stamps' */ |
| | 290 | |
| | 291 | name[name=~/^My_pattern.*/] /* the value of the tag 'name' matches with the regular expression '^My_pattern.*' */ |
| | 292 | /* Note, that reqular expressions have to be enclosed in /.../ */ |
| | 293 | </pre> |
| | 294 | }}} |
| | 295 | }}} |
| | 296 | |
| | 297 | In addition, you can test whether a tag is present or not: |
| | 298 | |
| | 299 | {{{#!th align=left valign=top |
| | 300 | '''Condition''' |
| | 301 | }}} |
| | 302 | {{{#!th align=left valign=top |
| | 303 | '''Example''' |
| | 304 | }}} |
| | 305 | |------------------------------------------------------------------------------- |
| | 306 | {{{#!td align=left valign=top |
| | 307 | Presence of tag |
| | 308 | }}} |
| | 309 | {{{#!td align=left valign=top |
| | 310 | {{{ |
| | 311 | #!html |
| | 312 | <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"> |
| | 313 | way[highway] /* matches any way with a tag 'highway' */ |
| | 314 | way["VALSOU"] /* use quotes if case sensitive matching is required */ |
| | 315 | way["name:fr"] /* use quotes if the tag name includes special caracters (white space, colons, etc.) */ |
| | 316 | </pre> |
| | 317 | }}} |
| | 318 | }}} |
| | 319 | |------------------------------------------------------------------------------- |
| | 320 | {{{#!td align=left valign=top |
| | 321 | Absence of tag |
| | 322 | }}} |
| | 323 | {{{#!td align=left valign=top |
| | 324 | {{{ |
| | 325 | #!html |
| | 326 | <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"> |
| | 327 | way[!highway] /* matches any way which does not have a tag 'highway' */ |
| | 328 | way[!"VALSOU"] /* use quotes if case sensitive matching is required */ |
| | 329 | way[!"name:fr"] /* use quotes if the tag name includes special caracters (white space, colons, etc.) */ |
| | 330 | </pre> |
| | 331 | }}} |
| | 332 | }}} |
| | 333 | |
| | 334 | You can test whether the the value of a tag is logical truth value. The value is evaluated to true, if it is either |
| | 335 | "yes", "true", or "1". All other values are evaluated to false. |
| | 336 | |
| | 337 | {{{#!th align=left valign=top |
| | 338 | '''Condition''' |
| | 339 | }}} |
| | 340 | {{{#!th align=left valign=top |
| | 341 | '''Example''' |
| | 342 | }}} |
| | 343 | |------------------------------------------------------------------------------- |
| | 344 | {{{#!td align=left valign=top |
| | 345 | Testing for truth value |
| | 346 | }}} |
| | 347 | {{{#!td align=left valign=top |
| | 348 | {{{ |
| | 349 | #!html |
| | 350 | <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"> |
| | 351 | way[oneway?] /* matches any way with a truth value in the tag 'oneway' */ |
| | 352 | </pre> |
| | 353 | }}} |
| | 354 | }}} |
| | 355 | |
| | 356 | === Link selector === |
| | 357 | In a child selector, you can formulate conditions on the link between a parent and a child object. |
| | 358 | |
| | 359 | If the parent is a relation, you can formulate conditions for the ''role'' a member objects has in this relation. |
| | 360 | {{{ |
| | 361 | #!html |
| | 362 | <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"> |
| | 363 | relation[type=route] >[role="link"] way { /* matches any way which is a member of route relation with role 'link' */ |
| | 364 | color: blue; |
| | 365 | } |
| | 366 | </pre> |
| | 367 | }}} |
| | 368 | |
| | 369 | {{{#!th align=left valign=top |
| | 370 | '''Operator''' |
| | 371 | }}} |
| | 372 | {{{#!th align=left valign=top |
| | 373 | '''Description''' |
| | 374 | }}} |
| | 375 | {{{#!th align=left valign=top |
| | 376 | '''Example''' |
| | 377 | }}} |
| | 378 | |------------------------------------------------------------------------------- |
| | 379 | {{{#!td align=left valign=top |
| | 380 | = |
| | 381 | }}} |
| | 382 | {{{#!td align=left valign=top |
| | 383 | Exact match of the role name. The name name {{{role}}} is compulsory in this context. |
| | 384 | }}} |
| | 385 | {{{#!td align=left valign=top |
| | 386 | {{{ |
| | 387 | #!html |
| | 388 | <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"> |
| | 389 | relation >[role=residential] way /* without quotes always case insensitive */ |
| | 390 | relation >[role="My name"] way /* use quotes for if the role value includes spaces or if case sensitive matching is important */ |
| | 391 | </pre> |
| | 392 | }}} |
| | 393 | }}} |
| | 394 | |
| | 395 | The operators {{{!=, ^=, $=, *=, and ~=}}} are supported too. Please refer to [#condition_selector_operators condition selector operators]. |
| | 396 | |
| | 397 | Nodes in ways and members in relations are ordered. You can formulate conditions on the position of a node in a way or a member |
| | 398 | object in a relation. |
| | 399 | |
| | 400 | {{{ |
| | 401 | #!html |
| | 402 | <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"> |
| | 403 | relation[type=route] >[index=1] way { /* matches the first way which is a member of route relation */ |
| | 404 | color: blue; |
| | 405 | } |
| | 406 | </pre> |
| | 407 | }}} |
| | 408 | |