11package geoscript.carto
22
3+ import geoscript.layer.GeoTIFF
34import geoscript.layer.Shapefile
5+ import geoscript.render.Map
46import geoscript.style.ColorMap
57import geoscript.style.Fill
68import geoscript.style.Shape
79import geoscript.style.Stroke
10+ import geoscript.style.UniqueValues
11+ import org.junit.jupiter.api.io.TempDir
12+
813import java.awt.Color
914import org.junit.jupiter.api.Test
1015
@@ -14,6 +19,9 @@ import static org.junit.jupiter.api.Assertions.*
1419
1520class LegendItemTest {
1621
22+ @TempDir
23+ private File folder
24+
1725 @Test
1826 void create () {
1927
@@ -47,4 +55,42 @@ class LegendItemTest {
4755 assertTrue (item. toString(). endsWith(" )" ))
4856 }
4957
58+ @Test
59+ void drawWithNamedSymbolizer () {
60+ File file = new File (getClass(). getClassLoader(). getResource(" states.shp" ). toURI())
61+ Shapefile shapefile = new Shapefile (file)
62+ shapefile. style = new Fill (" white" ) + new Stroke (" black" , 0.1 ). title(" State Outlines" )
63+
64+ Map map = new Map (layers : [
65+ shapefile
66+ ])
67+
68+ File mapFile = new File (" target/carto_legend_symbolizer_name.png" )
69+ mapFile. withOutputStream { OutputStream outputStream ->
70+ new ImageCartoBuilder (PageSize . LETTER_LANDSCAPE , ImageCartoBuilder.ImageType . PNG )
71+ .map(new MapItem (30 , 120 , 742 , 470 ). map(map))
72+ .legend(new LegendItem (640 , 500 , 180 ,80 ). addMap(map))
73+ .build(outputStream)
74+ }
75+ }
76+
77+ @Test
78+ void drawWithNamedUniqueSymbolizer () {
79+ File file = new File (getClass(). getClassLoader(). getResource(" states.shp" ). toURI())
80+ Shapefile shapefile = new Shapefile (file)
81+ shapefile. style = new UniqueValues (shapefile, " SUB_REGION" )
82+
83+ Map map = new Map (layers : [
84+ shapefile
85+ ])
86+
87+ File mapFile = new File (" target/carto_legend_symbolizer_unique_name.png" )
88+ mapFile. withOutputStream { OutputStream outputStream ->
89+ new ImageCartoBuilder (PageSize . LETTER_LANDSCAPE , ImageCartoBuilder.ImageType . PNG )
90+ .map(new MapItem (240 , 120 , 542 , 470 ). map(map))
91+ .legend(new LegendItem (10 , 10 , 220 ,600 ). addMap(map))
92+ .build(outputStream)
93+ }
94+ }
95+
5096}
0 commit comments