metadata.rst 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. .. _css_metadata:
  2. Metadata
  3. ========
  4. .. highlight:: xml
  5. One feature that appears in SLD that has no analog in CSS is the ability to
  6. provide *metadata* for styles and style rules. For example, this SLD embeds
  7. a title for its single rule::
  8. <?xml version="1.0" encoding="ISO-8859-1"?>
  9. <StyledLayerDescriptor version="1.0.0"
  10. xmlns="http://www.opengis.net/sld"
  11. xmlns:ogc="http://www.opengis.net/ogc"
  12. xmlns:xlink="http://www.w3.org/1999/xlink"
  13. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  14. xmlns:gml="http://www.opengis.net/gml"
  15. xsi:schemaLocation="http://www.opengis.net/sld
  16. http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd"
  17. >
  18. <NamedLayer>
  19. <Name>Country Borders</Name>
  20. <UserStyle>
  21. <Name>borders</Name>
  22. <Title>Country Borders</Title>
  23. <Abstract>
  24. Borders of countries, in an appropriately sovereign aesthetic.
  25. </Abstract>
  26. <FeatureTypeStyle>
  27. <Rule>
  28. <Title>Borders</Title>
  29. <LineSymbolizer>
  30. <Stroke>
  31. <CssParameter name="stroke-width">0.2</CssParameter>
  32. </Stroke>
  33. </LineSymbolizer>
  34. </Rule>
  35. </FeatureTypeStyle>
  36. </UserStyle>
  37. </NamedLayer>
  38. </StyledLayerDescriptor>
  39. .. highlight:: css
  40. Software such as GeoServer can use this metadata to automatically generate nice
  41. legend images directly from the style. You don't have to give up this ability
  42. when styling maps in CSS; just add comment *before* your rules including
  43. lines that start with ``@title`` and ``@abstract``. Here is the analogous style in
  44. CSS::
  45. /*
  46. * @title This is a point layer.
  47. * @abstract This is an abstract point layer.
  48. */
  49. * {
  50. mark: mark(circle);
  51. }
  52. Rules can provide either a title, an abstract, both, or neither. The SLD Name
  53. for a rule is autogenerated based on the filters from the CSS rules that
  54. combined to form it, for aid in troubleshooting.
  55. Combined rules
  56. --------------
  57. One thing to keep in mind when dealing with CSS styles is that multiple rules
  58. may apply to the same subset of map features, especially as styles get more
  59. complicated. Metadata is inherited similarly to CSS properties, but metadata
  60. fields are **combined** instead of overriding less specific rules. That means
  61. that when you have a style like this::
  62. /* @title Borders */
  63. * {
  64. stroke: black;
  65. }
  66. /* @title Parcels */
  67. [category='parcel'] {
  68. fill: blue;
  69. }
  70. The legend entry for parcels will have the title ``'Parcels with Borders'``.
  71. If you don't like this behavior, then only provide titles for the most specific
  72. rules in your style. (Or, suggest something better in an issue report!) Rules
  73. that don't provide titles are simply omitted from title aggregation.