misc.rst 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. .. _css_example_misc:
  2. Miscellaneous
  3. =============
  4. Markers sized by an attribute value
  5. -----------------------------------
  6. The following produces square markers at each point, but these are sized such that the area of each marker is proportional to the ``REPORTS`` attribute.
  7. When zoomed in (when there are less points in view) the size of the markers is doubled to make the smaller points more noticeable.
  8. .. code-block:: css
  9. * {
  10. mark: symbol(square);
  11. }
  12. [@sd > 1M] :mark {
  13. size: [sqrt(REPORTS)];
  14. }
  15. /* So that single-report points can be more easily seen */
  16. [@sd < 1M] :mark {
  17. size: [sqrt(REPORTS)*2];
  18. }
  19. This example uses the ``sqrt`` function.
  20. There are many functions available for use in CSS and SLD.
  21. For more details read - :doc:`/filter/function_reference`
  22. Specifying a geometry attribute
  23. -------------------------------
  24. In some cases, typically when using a database table with multiple geometry columns, it's necessary to specify which geometry to use.
  25. For example, let's suppose you have a table containing routes ``start`` and ``end`` both containing point geometries.
  26. The following CSS will style the start with a triangle mark, and the end with a square.
  27. .. code-block:: css
  28. * {
  29. geometry: [start], [end];
  30. mark: symbol(triangle), symbol(square);
  31. }
  32. Generating a geometry (Geometry Transformations)
  33. ------------------------------------------------
  34. Taking the previous example a bit further, we can also perform computations on-the-fly to generate the geometries that will be drawn.
  35. Any operation that is available for GeoServer :ref:`geometry_transformations` is also available in CSS styles.
  36. To use them, we simply provide a more complex expression in the ``geometry`` property.
  37. For example, we could mark the start and end points of all the paths in a line layer (you can test this example out with any line layer, such as the ``sf:streams`` layer that is included in GeoServer's default data directory.)
  38. .. code-block:: css
  39. * {
  40. geometry: [startPoint(the_geom)], [endPoint(the_geom)];
  41. mark: symbol(triangle), symbol(square);
  42. }
  43. Rendering different geometry types (lines/points) with a single style
  44. ---------------------------------------------------------------------
  45. As one more riff on the geometry examples, we'll show how to render both the original line and the start/endpoints in a single style.
  46. This is accomplished by using ``stroke-geometry`` and ``mark-geometry`` to specify that different geometry expressions should be used for symbols compared with strokes.
  47. .. code-block:: css
  48. * {
  49. stroke-geometry: [the_geom];
  50. stroke: blue;
  51. mark-geometry: [startPoint(the_geom)], [endPoint(the_geom)];
  52. mark: symbol(triangle), symbol(square);
  53. }