kml.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. .. _css_example_kml:
  2. KML
  3. ===
  4. Detecting raster to vector switch in KML
  5. ----------------------------------------
  6. GeoServer 2.4 added a new icon server that KML output uses to make sure the point symbolisers look the same as in
  7. a normal WMS call no matter what scale they are looked at.
  8. This may pose some issue when working in the default KML generation mode, where the map is a ground overlay up to
  9. a certain scale, and switches to a vector, clickable representation once the number of features in the visualization
  10. fall below a certain scale (as controlled by the ``KMSCORE`` parameter): the end user is not informed "visually" that
  11. the switch happened.
  12. There is however a custom environment variable, set by the KML generator, that styles can leverage to know whether
  13. the KML generation is happening in ground overlay or vector mode.
  14. The following example leverages this function to show a larger point symbol when points become clickable:
  15. .. code-block:: css
  16. * {
  17. mark: symbol("circle");
  18. }
  19. :mark [env('kmlOutputMode') = 'vector'] {
  20. size: 8;
  21. }
  22. :mark {
  23. size: 4;
  24. fill: yellow;
  25. stroke: black;
  26. }
  27. This will result in the following output:
  28. .. figure:: images/kml-raster.png
  29. :align: center
  30. *Raster output, points are not yet clickable*
  31. .. figure:: images/kml-vector.png
  32. :align: center
  33. *Vector output, points are clickable and painted as larger icons*
  34. One important bit about the above CSS is that the order of the rules is important. The CSS to SLD translator uses specificity to decide which rule overrides which other one, and the specificity is driven, at the time of writing, only by scale rules and access to attributes. The filter using the ``kmlOutputMode`` filter is not actually using any feature attribute, so it has the same specificity as the catch all ``:mark`` rule. Putting it first ensures that it overrides the catch all rule anyways, while putting it second would result in the output size being always 4.
  35. Getting KML marks similar to the old KML encoder
  36. ------------------------------------------------
  37. The old KML generator (prior to GeoServer 2.4) was not able to truly respect the marks own shape, and as a result, was simply applying the
  38. mark color to a fixed bull's eye like icon, for example:
  39. .. figure:: images/legacy-kml-marks.png
  40. :align: center
  41. Starting with GeoServer 2.4 the KML engine has been rewritten, and among other things, it can produce an exact
  42. representation of the marks, respecting not only color, but also shape and stroking.
  43. However, what if one want to reproduce the old output look?
  44. The solution is to leverage the ability to respect marks appearance to the letter, and combine two superimposed
  45. marks to generate the desired output:
  46. .. code-block:: css
  47. * {
  48. mark: symbol('circle'), symbol('circle');
  49. mark-size: 12, 4;
  50. }
  51. :nth-mark(1) {
  52. fill: red;
  53. stroke: black;
  54. stroke-width: 2;
  55. }
  56. :nth-mark(2) {
  57. fill: black;
  58. }
  59. Which results in the following Google Earth output:
  60. .. figure:: images/kml-eyesbull-mark.png
  61. :align: center