styledmarks.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. .. _css_styledmarks:
  2. Styled marks
  3. ============
  4. .. highlight:: scss
  5. GeoServer's CSS module provides a collection of predefined symbols that you can
  6. use and combine to create simple marks, strokes, and fill patterns without
  7. needing an image editing program. You can access these symbols via the
  8. symbol() CSS function. For example, the built-in circle symbol makes it easy
  9. to create a simple 'dot' marker for a point layer::
  10. * {
  11. mark: symbol(circle);
  12. }
  13. Symbols work anywhere you can use a ``url()`` to reference an image (as in, you
  14. can use symbols for stroke and fill patterns as well as markers.)
  15. Symbol names
  16. ------------
  17. GeoServer extensions can add extra symbols (such as the ``chart://`` symbol
  18. family which allows the use of charts as symbols via a naming scheme similar to
  19. the Google Charts API). However, there are a few symbols that are always available:
  20. * circle
  21. * square
  22. * triangle
  23. * arrow
  24. * cross
  25. * star
  26. * x
  27. * shape://horizline
  28. * shape://vertline
  29. * shape://backslash
  30. * shape://slash
  31. * shape://plus
  32. * shape://times
  33. * windbarbs://default(size)[unit]
  34. Symbol selectors
  35. ----------------
  36. Symbols offer some additional styling options beyond those offered for image
  37. references. To specify these style properties, just add another
  38. rule with a special selector. There are 8 "pseudoclass" selectors that are
  39. used to style selectors:
  40. * ``:mark`` specifies that a rule applies to symbols used as point markers
  41. * ``:shield`` specifies that a rule applies to symbols used as label
  42. shields (icons displayed behind label text)
  43. * ``:stroke`` specifies that a rule applies to symbols used as stroke
  44. patterns
  45. * ``:fill`` specifies that a rule applies to symbols used as fill patterns
  46. * ``:symbol`` specifies that a rule applies to any symbol, regardless of
  47. which context it is used in
  48. * ``:nth-mark(n)`` specifies that a rule applies to the symbol used for the
  49. nth stacked point marker on a feature.
  50. * ``:nth-shield(n)`` specifies that a rule applies to the symbol used for
  51. the background of the nth stacked label on a feature
  52. * ``:nth-stroke(n)`` specifies that a rule applies to the symbol used for
  53. the nth stacked stroke pattern on a feature.
  54. * ``:nth-fill(n)`` specifies that a rule applies to the symbol used for the
  55. nth stacked fill pattern on a feature.
  56. * ``:nth-symbol(n)`` specifies that a rule applies to the symbol used for
  57. the nth stacked symbol on a feature, regardless of which context it is
  58. used in.
  59. These pseudoclass selectors can be used in a top level rule, but starting with GeoServer 2.10,
  60. they are more commonly used in sub-rules close to the mark property, to get better readability
  61. (see example below).
  62. Symbol styling properties
  63. -------------------------
  64. Styling a built-in symbol is similar to styling a polygon feature. However, the
  65. styling options are slightly different from those available to a true polygon
  66. feature:
  67. * The ``mark`` and ``label`` families of properties are unavailable for
  68. symbols.
  69. * Nested symbol styling is not currently supported.
  70. * Only the first ``stroke`` and ``fill`` will be used.
  71. * Additional ``size`` (as a length) and ``rotation`` (as an angle)
  72. properties are available. These are analogous to the
  73. ``(mark|stroke|fill)-size`` and ``(mark|stroke|fill)-rotation``
  74. properties available for true geometry styling.
  75. .. note::
  76. The various prefixed '-size' and '-rotation' properties on the
  77. containing style override those for the symbol if they are present.
  78. Example styled symbol
  79. ---------------------
  80. As an example, consider a situation where you are styling a layer that includes data about hospitals in your town. You can create a simple hospital logo by placing a red cross symbol on top of a white circle background::
  81. [usage='hospital'] {
  82. mark: symbol('circle'), symbol('cross');
  83. :nth-mark(1) {
  84. size: 16px;
  85. fill: white;
  86. stroke: red;
  87. };
  88. :nth-mark(2) {
  89. size: 12px;
  90. fill: red;
  91. }
  92. }
  93. Also an windbarb example where you get wind speed and direction from your data fields horSpeed and horDir (direction)::
  94. * {
  95. /* select windbard based on speed( here in meters per second, and south hemisphere) */
  96. mark: symbol('windbarbs://default(${horSpeed})[m/s]?hemisphere=s');
  97. /* rotate windbarb based on horDir property (in degrees) */
  98. mark-rotation: [horDir];
  99. mark-size: 20;
  100. }