polygons.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. .. _mbstyle_cookbook.polygons:
  2. Polygons
  3. ========
  4. Polygons are two dimensional shapes that contain both an outer stroke (or "outline") and an inside (or "fill"). A polygon can be thought of as an irregularly-shaped point and is styled in similar ways to circles.
  5. .. _mbstyle_cookbook_polygons_attributes:
  6. Example polygons layer
  7. ----------------------
  8. The :download:`polygons layer <artifacts/mbstyle_cookbook_polygon.zip>` used below contains county information for a fictional country. For reference, the attribute table for the polygons is included below.
  9. .. list-table::
  10. :widths: 30 40 30
  11. :header-rows: 1
  12. * - ``fid`` (Feature ID)
  13. - ``name`` (County name)
  14. - ``pop`` (Population)
  15. * - polygon.1
  16. - Irony County
  17. - 412234
  18. * - polygon.2
  19. - Tracker County
  20. - 235421
  21. * - polygon.3
  22. - Dracula County
  23. - 135022
  24. * - polygon.4
  25. - Poly County
  26. - 1567879
  27. * - polygon.5
  28. - Bearing County
  29. - 201989
  30. * - polygon.6
  31. - Monte Cristo County
  32. - 152734
  33. * - polygon.7
  34. - Massive County
  35. - 67123
  36. * - polygon.8
  37. - Rhombus County
  38. - 198029
  39. :download:`Download the polygons shapefile <artifacts/mbstyle_cookbook_polygon.zip>`
  40. .. _mbstyle_cookbook_polygons_simplepolygon:
  41. Simple polygon
  42. --------------
  43. This example shows a polygon filled in blue.
  44. .. figure:: ../../sld/cookbook/images/polygon_simplepolygon.png
  45. Simple polygon
  46. Code
  47. ~~~~
  48. :download:`Download the "Simple polygon" MBStyle <artifacts/mbstyle_cookbook_polygons_simplepolygon.json>`
  49. .. code-block:: json
  50. :linenos:
  51. {
  52. "version": 8,
  53. "name": "simple-polygon",
  54. "layers": [
  55. {
  56. "id": "polygon",
  57. "type": "fill",
  58. "paint": {
  59. "fill-color": "#000080"
  60. }
  61. }
  62. ]
  63. }
  64. Details
  65. ~~~~~~~
  66. There is one layer for this style, which is the simplest possible situation. Styling polygons is accomplished via the fill type (**line 7**). **Line 9** specifies dark blue (``'#000080'``) as the polygon's fill color.
  67. .. note:: The light-colored outlines around the polygons in the figure are artifacts of the renderer caused by the polygons being adjacent. There is no outline in this style.
  68. .. _mbstyle_cookbook_polygons_simplepolygonwithstroke:
  69. Simple polygon with stroke
  70. --------------------------
  71. This example adds a 1 pixel white outline to the :ref:`mbstyle_cookbook_polygons_simplepolygon` example.
  72. .. figure:: ../../sld/cookbook/images/polygon_simplepolygonwithstroke.png
  73. Simple polygon with stroke
  74. Code
  75. ~~~~
  76. :download:`Download the "Simple polygon with stroke" MBStyle <artifacts/mbstyle_cookbook_polygons_simplepolygonwithstroke.json>`
  77. .. code-block:: json
  78. :linenos:
  79. {
  80. "version": 8,
  81. "name": "simple-polygon-outline",
  82. "layers": [
  83. {
  84. "id": "polygon-outline",
  85. "type": "fill",
  86. "paint": {
  87. "fill-outline-color": "#FFFFFF",
  88. "fill-color": "#000080"
  89. }
  90. }
  91. ]
  92. }
  93. Details
  94. ~~~~~~~
  95. This example is similar to the :ref:`mbstyle_cookbook_polygons_simplepolygon` example above, with the addition of ``fill-outline`` paint parameter (**line 9**). **Line 9** also sets the color of stroke to white (``'#FFFFFF'``), the ``"fill-outline-color"`` can only be 1 pixel, a limitation of MBStyle.
  96. Transparent polygon
  97. -------------------
  98. This example builds on the :ref:`mbstyle_cookbook_polygons_simplepolygonwithstroke` example and makes the fill partially transparent by setting the opacity to 50%.
  99. .. figure:: ../../sld/cookbook/images/polygon_transparentpolygon.png
  100. Transparent polygon
  101. Code
  102. ~~~~
  103. :download:`Download the "Transparent polygon" MBStyle <artifacts/mbstyle_polygon_transparentpolygon.json>`
  104. .. code-block:: json
  105. :linenos:
  106. {
  107. "version": 8,
  108. "name": "simple-polygon-transparent",
  109. "layers": [
  110. {
  111. "id": "polygon-transparent",
  112. "type": "fill",
  113. "paint": {
  114. "fill-outline-color": "#FFFFFF",
  115. "fill-color": "#000080",
  116. "fill-opacity": 0.5
  117. }
  118. }
  119. ]
  120. }
  121. Details
  122. ~~~~~~~
  123. This example is similar to the :ref:`mbstyle_cookbook_polygons_simplepolygonwithstroke` example, save for defining the fill's opacity in **line 11**. The value of 0.5 results in partially transparent fill that is 50% opaque. An opacity value of 1 would draw the fill as 100% opaque, while an opacity value of 0 would result in a completely transparent (0% opaque) fill. In this example, since the background is white, the dark blue looks lighter. Were the fill imposed on a dark background, the resulting color would be darker.