Changes between Initial Version and Version 1 of Help/Styles/MapCSSTutorial


Ignore:
Timestamp:
2011-02-10T14:38:22+01:00 (14 years ago)
Author:
bastiK
Comment:

added short tutorial for MapCSS

Legend:

Unmodified
Added
Removed
Modified
  • Help/Styles/MapCSSTutorial

    v1 v1  
     1= MapCSS Tutorial =
     2
     3=== Example 1 ===
     4{{{
     5node[amenity=restaurant]
     6{
     7    icon-image: "food/restaurant.png";
     8    text: auto;
     9}
     10}}}
     11
     12This draws a restaurant icon and a text label for each node that is tagged {{{amenity=restaurant}}}. The image can be specified in one of the following forms:
     13 * absolute path
     14 * URL
     15 * a path relative to the current *.mapcss file
     16 * relative path that revers to a build-in image (see Example 1). The {{{josm-tested.jar}}} file is a simple zip archive; you can extract it and use all files from the {{{images}}} folder.
     17The declaration '''{{{text: auto;}}}''' tells JOSM to derive the text for the label automatically. At time of writing, the following tags are searched and the first one that is found will be used: "{{{name:}}}"+''<LANG>'', "{{{name}}}", "{{{int_name}}}", "{{{ref}}}", "{{{operator}}}", "{{{brand}}}" and "{{{addr:housenumber}}}". You can also pick a specific tag e.g. '''{{{text: "cuisine";}}}'''.
     18
     19=== Example 2 ===
     20{{{
     21way[highway=residential]
     22{
     23    width: 4;
     24    color: lightgray;
     25}
     26}}}
     27Here we have all residential roads drawn in lightgray and with line width 4 px. Color can be given in one of the followin formats:
     28 * named color as found in [http://www.w3.org/TR/css3-color/#svg-color this] list
     29 * html style: '''{{{#ff0000}}}'''
     30 * '''{{{rgb(0.0, 1.0 , 0.2)}}}''' - rgb value with arguments from 0.0 to 1.0
     31 
     32=== Example 3 ===
     33{{{
     34way[highway=living_street]
     35{
     36    width: 7;
     37    color: #c0c0c0;
     38    dashes: 15,9;
     39    dashes-background-color: #00ff00;
     40
     41    text: "name";
     42    text-position: line;
     43    text-offset: 9;
     44    font-size: 12;
     45    font-color: lightyellow;
     46}
     47}}}
     48In the first part of the declarations, we define a dash pattern of gray and green. Leave out the {{{dashes-background-color}}} to display a broken line with no color in between the dashes.
     49
     50In the second part, the name of the street ('''{{{text: "name";}}}''') will be displayed along the line ('''{{{text-position: line;}}}''') with an vertical offset of 9 px. An offset of 0 would render the text on top of the line.
     51
     52=== Example 4 ===
     53
     54{{{
     55area[building]
     56{
     57    fill-color: orange;
     58}
     59}}}
     60
     61The '''{{{area}}}''' type selector acts on ways and multipolygon relations. Note that the outline of the building is painted as well, although we haven't specefied any line properties. This is because JOSM will alway draw at least one line element for each way. If no line properties are found, a default line element is generated.
     62
     63=== Example 5 ===
     64
     65{{{
     66area[landuse=forest], area[natural=wood]
     67{
     68    fill-image: "http://trac.openstreetmap.org/export/25265/applications/rendering/mapnik/symbols/forest.png";
     69    fill-opacity: 0.8;
     70}
     71}}}
     72
     73This shows, how you can list multiple selectors for one rule. We fill the area with a pattern, if it is tagged {{{landuse=forest}}} or {{{natural=wood}}}. The opacity is set to 0.8, where 1.0 means opaque and 0.0 is fully transparent. You can set opacity, whenever a color or an image is defined. E.g. {{{icon-opacity}}} for {{{icon-image}}} and {{{opacity}}} for {{{color}}}.
     74
     75