lines.rst 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. .. _ysld_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. .. _ysld_cookbook_lines_attributes:
  7. Example lines layer
  8. -------------------
  9. The :download:`lines layer <artifacts/ysld_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/ysld_cookbook_line.zip>`
  93. .. _ysld_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" YSLD <artifacts/line_simpleline.ysld>`
  102. .. code-block:: yaml
  103. title: 'YSLD Cook Book: Simple Line'
  104. feature-styles:
  105. - name: name
  106. rules:
  107. - symbolizers:
  108. - line:
  109. stroke-color: '#000000'
  110. stroke-width: 3
  111. Details
  112. ~~~~~~~
  113. There is one rule in one feature style for this YSLD, which is the simplest possible situation. (All
  114. subsequent examples will contain one rule and one feature style unless otherwise specified.) Styling
  115. lines is accomplished via the line symbolizer (**lines 5-8**). **Line 7** specifies the color of the line to be
  116. black (``'#000000'``), while **line 8** specifies the width of the lines to be 3 pixels.
  117. Line with border
  118. ----------------
  119. This example shows how to draw lines with borders (sometimes called "cased lines").
  120. In this case the lines are drawn with a 3 pixel blue center and a 1 pixel wide gray border.
  121. .. figure:: ../../sld/cookbook/images/line_linewithborder.png
  122. Line with border
  123. Code
  124. ~~~~
  125. :download:`Download the "Line with border" YSLD <artifacts/line_linewithborder.ysld>`
  126. .. code-block:: yaml
  127. title: 'YSLD Cook Book: Line with border'
  128. feature-styles:
  129. - name: name
  130. rules:
  131. - symbolizers:
  132. - line:
  133. stroke-color: '#333333'
  134. stroke-width: 5
  135. stroke-linecap: round
  136. - name: name
  137. rules:
  138. - symbolizers:
  139. - line:
  140. stroke-color: '#6699FF'
  141. stroke-width: 3
  142. stroke-linecap: round
  143. Details
  144. ~~~~~~~
  145. Lines in YSLD have no notion of a "fill", only "stroke". Thus, unlike points or polygons, it is not possible to style the "edge" of the line geometry. It is, however, possible to achieve this effect by drawing each line twice: once with a certain width and again with a slightly smaller width. This gives the illusion of fill and stroke by obscuring the larger lines everywhere except along the edges of the smaller lines.
  146. Since every line is drawn twice, the order of the rendering is *very* important.
  147. GeoServer renders ``feature-styles`` in the order that they are presented in the YSLD.
  148. In this style, the gray border lines are drawn first via the first feature style, followed by the blue center lines in a second feature 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".
  149. In this example, **lines 3-9** comprise the first feature style, which is the outer line (or "stroke").
  150. **Line 7** specifies the color of the line to be dark gray (``'#333333'``), **line 8** specifies the width of this line to be 5 pixels, and in **line 9** a ``stroke-linecap`` parameter of ``round``
  151. renders the ends of the line as rounded instead of flat.
  152. (When working with bordered lines using a round line cap ensures that the border connects properly at the ends of the lines.)
  153. **Lines 10-16** comprise the second ``feature-style``, which is the inner line (or "fill"). **Line 14**
  154. specifies the color of the line to be a medium blue (``'#6699FF'``), **line 15** specifies the width of this line to be 3 pixels, and **line 16** again renders the edges of the line to be rounded instead of flat.
  155. 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.
  156. Dashed line
  157. -----------
  158. This example alters the :ref:`ysld_cookbook_lines_simpleline` to create a dashed line consisting of 5 pixels of drawn
  159. line alternating with 2 pixels of blank space.
  160. .. figure:: ../../sld/cookbook/images/line_dashedline.png
  161. Dashed line
  162. Code
  163. ~~~~
  164. :download:`Download the "Dashed line" YSLD <artifacts/line_dashedline.ysld>`
  165. .. code-block:: yaml
  166. title: 'YSLD Cook Book: Dashed line'
  167. feature-styles:
  168. - name: name
  169. rules:
  170. - symbolizers:
  171. - line:
  172. stroke-color: '#0000FF'
  173. stroke-width: 3
  174. stroke-dasharray: 5 2
  175. Details
  176. ~~~~~~~
  177. In this example, **line 8** sets the color of the lines to be blue (``'#0000FF'``) and **line 8** sets the width of the lines to be 3 pixels. **Line 9** 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.
  178. Offset line
  179. -----------
  180. This example alters the :ref:`ysld_cookbook_lines_simpleline` to add a perpendicular offset line on the left side of the line, at five pixels distance.
  181. .. figure:: ../../sld/cookbook/images/line_offset.png
  182. Dashed line
  183. Code
  184. ~~~~
  185. :download:`Download the "Offset line" YSLD <artifacts/line_offsetline.ysld>`
  186. .. code-block:: yaml
  187. title: 'YSLD Cook Book: Dashed line'
  188. feature-styles:
  189. - name: name
  190. rules:
  191. - symbolizers:
  192. - line:
  193. stroke-color: '#000000'
  194. stroke-width: 2
  195. - line:
  196. stroke-color: '#0000FF'
  197. stroke-width: 3
  198. stroke-dasharray: 5 2
  199. offset: 3
  200. Details
  201. ~~~~~~~
  202. In this example, **lines 6-8** draw a simple black line like in the Simple line example. **Lines 9-12** draw a blue dashed line like in the above Dashed line example. **Line 13** modifies the dashed line with a 3 pixel offset from the line geometry.
  203. Railroad (hatching)
  204. -------------------
  205. This example uses hatching to create a railroad style. Both the line and the hatches are black, with a 2 pixel
  206. thickness for the main line and a 1 pixel width for the perpendicular hatches.
  207. .. figure:: ../../sld/cookbook/images/line_railroad.png
  208. Railroad (hatching)
  209. Code
  210. ~~~~
  211. :download:`Download the "Railroad (hatching)" YSLD <artifacts/line_railroad.ysld>`
  212. .. code-block:: yaml
  213. title: 'YSLD Cook Book: Railroad (hatching)'
  214. feature-styles:
  215. - name: name
  216. rules:
  217. - symbolizers:
  218. - line:
  219. stroke-color: '#333333'
  220. stroke-width: 3
  221. - line:
  222. stroke-color: '#333333'
  223. stroke-width: 1
  224. stroke-graphic:
  225. size: 12
  226. symbols:
  227. - mark:
  228. shape: shape://vertline
  229. stroke-color: '#333333'
  230. stroke-width: 1
  231. Details
  232. ~~~~~~~
  233. In this example there are two line symbolizers.
  234. The first symbolizer, on **lines 6-8**, draws a standard line, with **line 7** drawing the lines as dark gray
  235. (``'#333333'``) and **line 8** setting the width of the lines to be 2 pixels.
  236. The hatching is invoked in the second symbolizer, on **lines 9-18**. **Line 16** specifies that the symbolizer draw a vertical line hatch (``shape://vertline``) perpendicular to the line geometry. **Lines 17-18** set the hatch color to dark gray (``'#333333'``) and width to 1 pixel. Finally, **line 13** specifies both the length of the hatch and the distance between each hatch to both be 12 pixels.
  237. Spaced graphic symbols
  238. ----------------------
  239. This example uses a graphic stroke along with dash arrays to create a "dot and space" line type.
  240. Adding the dash array specification allows to control the amount of space between one symbol and the next one.
  241. Without using the dash
  242. array the lines would be densely populated with dots, each one touching the previous one.
  243. .. figure:: ../../sld/cookbook/images/line_dashspace.png
  244. Spaced symbols along a line
  245. Code
  246. ~~~~
  247. :download:`Download the "Spaced symbols" YSLD <artifacts/line_dashspace.ysld>`
  248. .. code-block:: yaml
  249. name: Default Styler
  250. title: 'YSLD Cook Book: Dash/Space line'
  251. feature-styles:
  252. - name: name
  253. rules:
  254. - symbolizers:
  255. - line:
  256. stroke-color: '#333333'
  257. stroke-width: 1
  258. stroke-dasharray: 4 6
  259. stroke-graphic:
  260. size: 4
  261. symbols:
  262. - mark:
  263. shape: circle
  264. stroke-color: '#333333'
  265. stroke-width: 1
  266. fill-color: '#666666'
  267. Details
  268. ~~~~~~~
  269. This example, like others before, uses a ``stroke-graphic`` to place a graphic symbol along a line. The symbol, defined on **lines 14-18** is a 4 pixel gray circle with a dark gray outline. The spacing between symbols is controlled with the ``stroke-dasharray`` at **line 9**, which specifies 4 pixels of pen-down (just enough to draw the circle) and 6 pixels of pen-up, to provide the spacing.
  270. .. _ysld_cookbook_lines_defaultlabel:
  271. Alternating symbols with dash offsets
  272. -------------------------------------
  273. This example shows how to create a complex line style which alternates a dashed line and a graphic symbol.
  274. The code builds on features shown in the previous examples:
  275. * ``stroke-dasharray`` controls pen-down/pen-up behavior to generate dashed lines
  276. * ``stroke-graphic`` places symbols along a line
  277. * combining the two allows control of symbol spacing
  278. This also shows the usage of a `dash offset`, which controls where rendering starts
  279. in the dash array.
  280. For example, with a dash array of ``5 10`` and a dash offset of ``7`` the
  281. renderer starts drawing the pattern 7 pixels from the beginning. It skips the 5 pixels pen-down
  282. section and 2 pixels of the pen-up section, then draws the remaining 8 pixels of pen-up, then 5 down, 10 up, and so on.
  283. The example shows how to use these features to create two synchronized sequences of dash arrays,
  284. one drawing line segments and the other symbols.
  285. .. figure:: ../../sld/cookbook/images/line_dashdot.png
  286. Alternating dash and symbol
  287. Code
  288. ~~~~
  289. :download:`Download the "Spaced symbols" YSLD <artifacts/line_dashdot.ysld>`
  290. .. code-block:: yaml
  291. title: 'YSLD Cook Book: Dash/Symbol line'
  292. feature-styles:
  293. - name: name
  294. rules:
  295. - symbolizers:
  296. - line:
  297. stroke-color: '#0000FF'
  298. stroke-width: 1
  299. stroke-dasharray: 10 10
  300. - line:
  301. stroke-color: '#000033'
  302. stroke-width: 1
  303. stroke-dasharray: 5 15
  304. stroke-dashoffset: 7.5
  305. stroke-graphic:
  306. size: 5
  307. symbols:
  308. - mark:
  309. shape: circle
  310. stroke-color: '#000033'
  311. stroke-width: 1
  312. Details
  313. ~~~~~~~
  314. In this example two line symbolizers use ``stroke-dasharray`` and different symbology to produce a sequence of alternating dashes and symbols. The first symbolizer (**lines 6-9**) is a simple dashed line alternating 10 pixels of pen-down with 10 pixels of pen-up. The second symbolizer (**lines 10-21**) alternates a 5 pixel empty circle with 15 pixels of white space.
  315. The circle symbol is produced by a ``mark`` element, with its symbology specified by ``stroke`` parameters (**lines 20-21**).
  316. The spacing between symbols is controlled with the ``stroke-dasharray`` (**line 13**), which specifies 5 pixels of pen-down (just enough to draw the circle) and 15 pixels of pen-up.
  317. In order to have the two sequences positioned correctly the second one uses a ``stroke-dashoffset`` of 7.5 (**line 14**).
  318. This makes the sequence start with 12.5 pixels of white space, then a circle (which is then centered between the two line segments of the other pattern), then 15 pixels of white space, and so on.
  319. Line with default label
  320. -----------------------
  321. This example shows a text label on the simple line. This is how a label will be displayed in the absence of any other
  322. customization.
  323. .. figure:: ../../sld/cookbook/images/line_linewithdefaultlabel.png
  324. Line with default label
  325. Code
  326. ~~~~
  327. :download:`Download the "Line with default label" YSLD <artifacts/line_linewithdefaultlabel.ysld>`
  328. .. code-block:: yaml
  329. name: Default Styler
  330. title: 'YSLD Cook Book: Line with default label'
  331. feature-styles:
  332. - name: name
  333. rules:
  334. - symbolizers:
  335. - line:
  336. stroke-color: '#FF0000'
  337. stroke-width: 1
  338. - text:
  339. label: ${name}
  340. fill-color: '#000000'
  341. font-family: Serif
  342. font-size: 10
  343. font-style: normal
  344. font-weight: normal
  345. placement: point
  346. Details
  347. ~~~~~~~
  348. In this example, there is one rule with a line symbolizer and a text symbolizer. The line symbolizer (**lines 6-8**) draws red lines (``'#FF0000'``). The text symbolizer (**lines 10-17**) determines the labeling of the lines. **Line 10** specifies that the text of the label will be determined by the value of the "name" attribute for each line. (Refer to the attribute table in the :ref:`ysld_cookbook_lines_attributes` section if necessary.) **Line 11** sets the text color to black. All other details about the label are set to the renderer default, which here is Times New Roman font, font color black, and font size of 10 pixels.
  349. .. _ysld_cookbook_lines_labelfollowingline:
  350. Label following line
  351. --------------------
  352. This example renders the text label to follow the contour of the lines.
  353. .. figure:: ../../sld/cookbook/images/line_labelfollowingline.png
  354. Label following line
  355. Code
  356. ~~~~
  357. :download:`Download the "Label following line" YSLD <artifacts/line_labelfollowingline.ysld>`
  358. .. code-block:: yaml
  359. title: 'YSLD Cook Book: Label following line'
  360. feature-styles:
  361. - name: name
  362. rules:
  363. - symbolizers:
  364. - line:
  365. stroke-color: '#FF0000'
  366. stroke-width: 1
  367. - text:
  368. label: ${name}
  369. fill-color: '#000000'
  370. placement: line
  371. offset: 0
  372. x-followLine: true
  373. Details
  374. ~~~~~~~
  375. As the :ref:`ysld_cookbook_lines_defaultlabel` example showed, the default label behavior isn't optimal. The label is displayed at a tangent to the line itself, leading to uncertainty as to which label corresponds to which line.
  376. This example is similar to the :ref:`ysld_cookbook_lines_defaultlabel` example with the exception of **lines 12-14**.
  377. **Line 14** sets the option to have the label follow the line, while **lines 12-13** specify that the label is placed along a line. If ``placement: line`` is not specified in an YSLD, then ``placement: point`` is assumed, which isn't compatible with line-specific rendering options.
  378. .. note:: Not all labels are shown due to label conflict resolution. See the next section on :ref:`ysld_cookbook_lines_optimizedlabel` for an example of how to maximize label display.
  379. .. _ysld_cookbook_lines_optimizedlabel:
  380. Optimized label placement
  381. -------------------------
  382. This example optimizes label placement for lines such that the maximum number of labels are displayed.
  383. .. figure:: ../../sld/cookbook/images/line_optimizedlabel.png
  384. Optimized label
  385. Code
  386. ~~~~
  387. :download:`Download the "Optimized label" YSLD <artifacts/line_optimizedlabel.ysld>`
  388. .. code-block:: yaml
  389. title: 'YSLD Cook Book: Optimized label placement'
  390. feature-styles:
  391. - name: name
  392. rules:
  393. - symbolizers:
  394. - line:
  395. stroke-color: '#FF0000'
  396. stroke-width: 1
  397. - text:
  398. label: ${name}
  399. fill-color: '#000000'
  400. placement: line
  401. offset: 0
  402. x-followLine: true
  403. x-maxAngleDelta: 90
  404. x-maxDisplacement: 400
  405. x-repeat: 150
  406. Details
  407. ~~~~~~~
  408. GeoServer uses "conflict resolution" to ensure that labels aren't drawn on top of other labels, obscuring them both. This accounts for the reason why many lines don't have labels in the previous example, :ref:`ysld_cookbook_lines_labelfollowingline`. While this setting can be toggled, it is usually a good idea to leave it on and use other label placement options to ensure that labels are drawn as often as desired and in the correct places. This example does just that.
  409. This example is similar to the previous example, :ref:`ysld_cookbook_lines_labelfollowingline`. The only differences are contained in **lines 15-17**. **Line 15** sets the maximum angle that the label will follow. This sets the label to never bend more than 90 degrees to prevent the label from becoming illegible due to a pronounced curve or angle. **Line 16** sets the maximum displacement of the label to be 400 pixels. In order to resolve conflicts with overlapping labels, GeoServer will attempt to move the labels such that they are no longer overlapping. This value sets how far the label can be moved relative to its original placement. Finally, **line 17** sets the labels to be repeated every 150 pixels. A feature will typically receive only one label, but this can cause confusion for long lines. Setting the label to repeat ensures that the line is always labeled locally.
  410. .. _ysld_cookbook_lines_optimizedstyledlabel:
  411. Optimized and styled label
  412. --------------------------
  413. This example improves the style of the labels from the :ref:`ysld_cookbook_lines_optimizedlabel` example.
  414. .. figure:: ../../sld/cookbook/images/line_optimizedstyledlabel.png
  415. Optimized and styled label
  416. Code
  417. ~~~~
  418. :download:`Download the "Optimized and styled label" YSLD <artifacts/line_optimizedstyledlabel.ysld>`
  419. .. code-block:: yaml
  420. title: 'YSLD Cook Book: Optimized and styled label'
  421. feature-styles:
  422. - name: name
  423. rules:
  424. - symbolizers:
  425. - line:
  426. stroke-color: '#FF0000'
  427. stroke-width: 1
  428. - text:
  429. label: ${name}
  430. fill-color: '#000000'
  431. font-family: Arial
  432. font-size: 10
  433. font-style: normal
  434. font-weight: bold
  435. placement: line
  436. offset: 0
  437. x-followLine: true
  438. x-maxAngleDelta: 90
  439. x-maxDisplacement: 400
  440. x-repeat: 150
  441. Details
  442. ~~~~~~~
  443. This example is similar to the :ref:`ysld_cookbook_lines_optimizedlabel`. The only difference is in the font information, which is contained in **lines 12-15**. **Line 12** sets the font family to be "Arial", **line 13** sets the font size to 10, **line 14** sets the font style to "normal" (as opposed to "italic" or "oblique"), and **line 15** sets the font weight to "bold" (as opposed to "normal").
  444. Attribute-based line
  445. --------------------
  446. This example styles the lines differently based on the "type" (Road class) attribute.
  447. .. figure:: ../../sld/cookbook/images/line_attributebasedline.png
  448. Attribute-based line
  449. Code
  450. ~~~~
  451. :download:`Download the "Attribute-based line" YSLD <artifacts/line_attributebasedline.ysld>`
  452. .. code-block:: yaml
  453. title: 'YSLD Cook Book: Attribute-based line'
  454. feature-styles:
  455. - name: name
  456. rules:
  457. - name: local-road
  458. filter: ${type = 'local-road'}
  459. symbolizers:
  460. - line:
  461. stroke-color: '#009933'
  462. stroke-width: 2
  463. - name: name
  464. rules:
  465. - name: secondary
  466. filter: ${type = 'secondary'}
  467. symbolizers:
  468. - line:
  469. stroke-color: '#0055CC'
  470. stroke-width: 3
  471. - name: name
  472. rules:
  473. - name: highway
  474. filter: ${type = 'highway'}
  475. symbolizers:
  476. - line:
  477. stroke-color: '#FF0000'
  478. stroke-width: 6
  479. Details
  480. ~~~~~~~
  481. .. note:: Refer to the :ref:`ysld_cookbook_lines_attributes` to see the attributes for the layer. This example has eschewed labels in order to simplify the style, but you can refer to the example :ref:`ysld_cookbook_lines_optimizedstyledlabel` to see which attributes correspond to which points.
  482. There are three types of road classes in our fictional country, ranging from back roads to high-speed freeways:
  483. "highway", "secondary", and "local-road". In order to handle each case separately, there is more than one
  484. feature style, each containing a single rule. This ensures that each road type is rendered in order, as each
  485. feature style is drawn based on the order in which it appears in the YSLD.
  486. The three rules are designed as follows:
  487. .. list-table::
  488. :widths: 20 30 30 20
  489. :header-rows: 1
  490. * - Rule order
  491. - Rule name / type
  492. - Color
  493. - Size
  494. * - 1
  495. - local-road
  496. - ``#009933`` (green)
  497. - 2
  498. * - 2
  499. - secondary
  500. - ``#0055CC`` (blue)
  501. - 3
  502. * - 3
  503. - highway
  504. - ``#FF0000`` (red)
  505. - 6
  506. **Lines 3-10** comprise the first rule. **Line 6** sets the filter for this rule, such that the "type" attribute has a value of "local-road". If this condition is true for a particular line, the rule is rendered according to the line symbolizer which is on **lines 8-10**. **Lines 9-10** set the color of the line to be a dark green (``'#009933'``) and the width to be 2 pixels.
  507. **Lines 11-18** comprise the second rule. **Line 14** sets the filter for this rule, such that the "type" attribute has a value of "secondary". If this condition is true for a particular line, the rule is rendered according to the line symbolizer which is on **lines 16-18**. **Lines 17-18** set the color of the line to be a dark blue (``'#0055CC'``) and the width to be 3 pixels, making the lines slightly thicker than the "local-road" lines and also a different color.
  508. **Lines 19-26** comprise the third and final rule. **Line 22** sets the filter for this rule, such that the "type" attribute has a value of "primary". If this condition is true for a particular line, the rule is rendered according to the line symbolizer which is on **lines 24-26**. **Lines 25-26** set the color of the line to be a bright red (``'#FF0000'``) and the width to be 6 pixels, so that these lines are rendered on top of and thicker than the other two road classes. In this way, the "primary" roads are given priority in the map rendering.
  509. Zoom-based line
  510. ---------------
  511. This example alters the :ref:`ysld_cookbook_lines_simpleline` style at different zoom levels.
  512. .. figure:: ../../sld/cookbook/images/line_zoombasedlinelarge.png
  513. Zoom-based line: Zoomed in
  514. .. figure:: ../../sld/cookbook/images/line_zoombasedlinemedium.png
  515. Zoom-based line: Partially zoomed
  516. .. figure:: ../../sld/cookbook/images/line_zoombasedlinesmall.png
  517. Zoom-based line: Zoomed out
  518. Code
  519. ~~~~
  520. :download:`Download the "Zoom-based line" YSLD <artifacts/line_zoombasedline.ysld>`
  521. .. code-block:: yaml
  522. title: 'YSLD Cook Book: Zoom-based line'
  523. feature-styles:
  524. - name: name
  525. rules:
  526. - name: Large
  527. scale: [min,1.8e8]
  528. symbolizers:
  529. - line:
  530. stroke-color: '#009933'
  531. stroke-width: 6
  532. - name: Medium
  533. scale: [1.8e8,3.6e8]
  534. symbolizers:
  535. - line:
  536. stroke-color: '#009933'
  537. stroke-width: 4
  538. - name: Small
  539. scale: [3.6e8,max]
  540. symbolizers:
  541. - line:
  542. stroke-color: '#009933'
  543. stroke-width: 2
  544. Details
  545. ~~~~~~~
  546. It is often desirable to make shapes larger at higher zoom levels when creating a natural-looking map. This example varies the thickness of the lines according to the zoom level (or more accurately, scale denominator). Scale denominators refer to the scale of the map. A scale denominator of 10,000 means the map has a scale of 1:10,000 in the units of the map projection.
  547. .. note:: Determining the appropriate scale denominators (zoom levels) to use is beyond the scope of this example.
  548. This style contains three rules. The three rules are designed as follows:
  549. .. list-table::
  550. :widths: 15 25 40 20
  551. :header-rows: 1
  552. * - Rule order
  553. - Rule name
  554. - Scale denominator
  555. - Line width
  556. * - 1
  557. - Large
  558. - 1:180,000,000 or less
  559. - 6
  560. * - 2
  561. - Medium
  562. - 1:180,000,000 to 1:360,000,000
  563. - 4
  564. * - 3
  565. - Small
  566. - Greater than 1:360,000,000
  567. - 2
  568. The order of these rules does not matter since the scales denominated in each rule do not overlap.
  569. The first rule (**lines 5-10**) is the smallest scale denominator, corresponding to when the view is "zoomed in". The scale rule is set on **line 6**, so that the rule will apply to any map with a scale denominator of 180,000,000 or less. **Lines 9-10** draw the line to be dark green (``'#009933'``) with a width of 6 pixels.
  570. The second rule (**lines 11-16**) is the intermediate scale denominator, corresponding to when the view is "partially zoomed". **Lines 12** set the scale such that the rule will apply to any map with scale denominators between 180,000,000 and 360,000,000. (The lower bound is inclusive and the upper bound is exclusive, so a zoom level of exactly 360,000,000 would *not* apply here.) Aside from the scale, the only difference between this rule and the previous is the width of the lines, which is set to 4 pixels on **line 16**.
  571. The third rule (**lines 17-22**) is the largest scale denominator, corresponding to when the map is "zoomed out". The scale rule is set on **line 18**, so that the rule will apply to any map with a scale denominator of 360,000,000 or greater. Again, the only other difference between this rule and the others is the width of the lines, which is set to 2 pixels on **line 22**.
  572. The result of this style is that lines are drawn with larger widths as one zooms in and smaller widths as one zooms out.