lines.rst 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. .. _mbstyle_cookbook.lines:
  2. Lines
  3. =====
  4. While lines can also seem to be simple shapes, having length but no width, there are many options and tricks for making
  5. lines display nicely.
  6. .. _mbstyle_cookbook_lines_attributes:
  7. Example lines layer
  8. -------------------
  9. The :download:`lines layer <artifacts/mbstyle_cookbook_line.zip>` used in the examples below contains road information for a
  10. fictional country. For reference, the attribute table for the points in this layer is included below.
  11. .. list-table::
  12. :widths: 30 40 30
  13. :header-rows: 1
  14. * - ``fid`` (Feature ID)
  15. - ``name`` (Road name)
  16. - ``type`` (Road class)
  17. * - line.1
  18. - Latway
  19. - highway
  20. * - line.2
  21. - Crescent Avenue
  22. - secondary
  23. * - line.3
  24. - Forest Avenue
  25. - secondary
  26. * - line.4
  27. - Longway
  28. - highway
  29. * - line.5
  30. - Saxer Avenue
  31. - secondary
  32. * - line.6
  33. - Ridge Avenue
  34. - secondary
  35. * - line.7
  36. - Holly Lane
  37. - local-road
  38. * - line.8
  39. - Mulberry Street
  40. - local-road
  41. * - line.9
  42. - Nathan Lane
  43. - local-road
  44. * - line.10
  45. - Central Street
  46. - local-road
  47. * - line.11
  48. - Lois Lane
  49. - local-road
  50. * - line.12
  51. - Rocky Road
  52. - local-road
  53. * - line.13
  54. - Fleet Street
  55. - local-road
  56. * - line.14
  57. - Diane Court
  58. - local-road
  59. * - line.15
  60. - Cedar Trail
  61. - local-road
  62. * - line.16
  63. - Victory Road
  64. - local-road
  65. * - line.17
  66. - Highland Road
  67. - local-road
  68. * - line.18
  69. - Easy Street
  70. - local-road
  71. * - line.19
  72. - Hill Street
  73. - local-road
  74. * - line.20
  75. - Country Road
  76. - local-road
  77. * - line.21
  78. - Main Street
  79. - local-road
  80. * - line.22
  81. - Jani Lane
  82. - local-road
  83. * - line.23
  84. - Shinbone Alley
  85. - local-road
  86. * - line.24
  87. - State Street
  88. - local-road
  89. * - line.25
  90. - River Road
  91. - local-road
  92. :download:`Download the lines shapefile <artifacts/mbstyle_cookbook_line.zip>`
  93. .. _mbstyle_cookbook_lines_simpleline:
  94. Simple line
  95. -----------
  96. This example specifies lines be colored black with a thickness of 3 pixels.
  97. .. figure:: ../../sld/cookbook/images/line_simpleline.png
  98. Simple line
  99. Code
  100. ~~~~
  101. :download:`Download the "Simple line" MBStyle <artifacts/mbstyle_line_simpleline.json>`
  102. .. code-block:: json
  103. :linenos:
  104. {
  105. "version": 8,
  106. "name": "simple-line",
  107. "layers": [
  108. {
  109. "id": "simple-line",
  110. "type": "line",
  111. "paint": {
  112. "line-color": "#000000",
  113. "line-width": 3
  114. }
  115. }
  116. ]
  117. }
  118. Details
  119. ~~~~~~~
  120. There is one layer style for this MBStyle, which is the simplest possible situation. Styling
  121. lines is accomplished using the line layer. **Line 9** specifies the color of the line to be
  122. black (``"#000000"``), while **line 10** specifies the width of the lines to be 3 pixels.
  123. Line with border
  124. ----------------
  125. This example shows how to draw lines with borders (sometimes called "cased lines").
  126. In this case the lines are drawn with a 3 pixel blue center and a 1 pixel wide gray border.
  127. .. figure:: ../../sld/cookbook/images/line_linewithborder.png
  128. Line with border
  129. Code
  130. ~~~~
  131. :download:`Download the "Line with border" MBStyle <artifacts/mbstyle_line_borderedline.json>`
  132. .. code-block:: json
  133. :linenos:
  134. {
  135. "version": 8,
  136. "name": "simple-borderedline",
  137. "layers": [
  138. {
  139. "id": "simple-borderedline",
  140. "type": "line",
  141. "layout": {
  142. "line-cap": "round"
  143. },
  144. "paint": {
  145. "line-color": "#333333",
  146. "line-width": 5
  147. }
  148. },
  149. {
  150. "id": "simple-line",
  151. "type": "line",
  152. "layout": {
  153. "line-cap": "round"
  154. },
  155. "paint": {
  156. "line-color": "#6699FF",
  157. "line-width": 3
  158. }
  159. }
  160. ]
  161. }
  162. Details
  163. ~~~~~~~
  164. In this example we are drawing the lines twice to achieve the appearance of a line with a border.
  165. Since every line is drawn twice, the order of the rendering is *very* important.
  166. GeoServer renders ``layers`` in the order that they are presented in the MBStyle.
  167. In this style, the gray border lines are drawn first via the first layer style, followed by the blue center lines in a second layer style. This ensures that the blue lines are not obscured by the gray lines, and also ensures proper rendering at intersections, so that the blue lines "connect".
  168. In this example, **lines 5-15** comprise the first layer style, which is the outer line (or "stroke").
  169. **Line 12** specifies the color of the line to be dark gray (``"#333333"``), **line 13** specifies the width of this line to be 5 pixels, and in the ``layout`` **line 9** a ``line-cap`` parameter of ``round``
  170. renders the ends of the line as rounded instead of flat.
  171. (When working with bordered lines using a round line cap ensures that the border connects properly at the ends of the lines.)
  172. **Lines 16-26** comprise the second ``layer``, which is the inner line (or "fill"). **Line 23**
  173. specifies the color of the line to be a medium blue (``"#6699FF"``), **line 24** specifies the width of this line to be 3 pixels, and in the ``layout`` **line 20** again renders the edges of the line to be rounded instead of flat.
  174. The result is a 3 pixel blue line with a 1 pixel gray border, since the 5 pixel gray line will display 1 pixel on each side of the 3 pixel blue line.
  175. Dashed line
  176. -----------
  177. This example alters the :ref:`mbstyle_cookbook_lines_simpleline` to create a dashed line consisting of 5 pixels of drawn
  178. line alternating with 2 pixels of blank space.
  179. .. figure:: ../../sld/cookbook/images/line_dashedline.png
  180. Dashed line
  181. Code
  182. ~~~~
  183. :download:`Download the "Dashed line" MBStyle <artifacts/mbstyle_line_dashedline.json>`
  184. .. code-block:: json
  185. :linenos:
  186. {
  187. "version": 8,
  188. "name": "simple-dashedline",
  189. "layers": [
  190. {
  191. "id": "simple-dashedline",
  192. "type": "line",
  193. "paint": {
  194. "line-color": "#0000FF",
  195. "line-width": 3,
  196. "line-dasharray": [5, 2]
  197. }
  198. }
  199. ]
  200. }
  201. Details
  202. ~~~~~~~
  203. In this example, **line 9** sets the color of the lines to be blue (``"#0000FF"``) and **line 10** sets the width of the lines to be 3 pixels. **Line 11** determines the composition of the line dashes. The value of ``[5, 2]`` creates a repeating pattern of 5 pixels of drawn line, followed by 2 pixels of omitted line.
  204. Offset line
  205. -----------
  206. This example alters the :ref:`mbstyle_cookbook_lines_simpleline` to add a perpendicular offset line on the left side of the line, at five pixels distance.
  207. .. figure:: ../../sld/cookbook/images/line_offset.png
  208. Dashed line
  209. Code
  210. ~~~~
  211. :download:`Download the "Offset line" MBStlye <artifacts/mbstyle_line_offsetline.json>`
  212. .. code-block:: json
  213. :linenos:
  214. {
  215. "version": 8,
  216. "name": "simple-offsetline",
  217. "layers": [
  218. {
  219. "id": "simple-line",
  220. "type": "line",
  221. "paint": {
  222. "line-color": "#000000",
  223. "line-width": 1
  224. }
  225. },
  226. {
  227. "id": "simple-offsetline",
  228. "type": "line",
  229. "paint": {
  230. "line-color": "#FF0000",
  231. "line-width": 1,
  232. "line-dasharray": [5, 2],
  233. "line-offset": 5
  234. }
  235. }
  236. ]
  237. }
  238. Details
  239. ~~~~~~~
  240. In this example, **lines 5-11** draw a simple black line like in the Simple line example. **Lines 13-21** draw a red dashed line like in the above Dashed line example. **Line 20** modifies the dashed line with a 5 pixel offset from the line geometry.