Skip to content

Commit 6fa84a2

Browse files
committed
Add more label options to the simple style reader
1 parent 915ff08 commit 6fa84a2

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/main/groovy/geoscript/style/io/SimpleStyleReader.groovy

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,13 @@ class SimpleStyleReader implements Reader {
120120
}
121121
String placement = options.get("label-placement", "point")
122122
if (placement.equalsIgnoreCase("point")) {
123-
// label-point-anchor, label-point-displace, label-point-rotate
124123
Map params = [
125124
anchor: options.get("label-point-anchor","0.5,0.5")?.split(","),
126125
displace: options.get("label-point-displace","0,0")?.split(","),
127126
rotate: options.get("label-point-rotate",0) as double
128127
]
129128
label.point(params)
130129
} else if (placement.equalsIgnoreCase("line")) {
131-
// label-line-offset, label-line-gap, label-line-igap, label-line-align, label-line-follow,
132-
// label-line-group, label-line-displacement, label-line-repeat
133130
Map params = [
134131
offset: options.get("label-line-offset", 0) as double,
135132
gap: options.get("label-line-gap"),
@@ -142,7 +139,15 @@ class SimpleStyleReader implements Reader {
142139
]
143140
label.linear(params)
144141
}
145-
142+
if (options.containsKey("label-maxdisplacement")) {
143+
label.maxDisplacement(options.get("label-maxdisplacement") as double)
144+
}
145+
if (options.containsKey("label-maxangledelta")) {
146+
label.maxAngleDelta(options.get("label-maxangledelta") as float)
147+
}
148+
if (options.containsKey("label-polygonalign")) {
149+
label.polygonAlign(options.get("label-polygonalign"))
150+
}
146151
parts.add(label)
147152
}
148153
new Composite(parts)

src/test/groovy/geoscript/style/io/SimpleStyleReaderTest.groovy

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package geoscript.style.io
22

33
import geoscript.style.Composite
44
import geoscript.style.Icon
5+
import geoscript.style.Label
56
import geoscript.style.Style
67
import org.junit.jupiter.api.Test
78
import org.junit.jupiter.api.io.TempDir
@@ -83,6 +84,23 @@ class SimpleStyleReaderTest {
8384
assertEquals style.toString(), "Composite (Shape(color = #7e7e7e, size = 6, type = triangle), Label(property = NAME))"
8485
}
8586

87+
@Test void polygonWithAlign() {
88+
SimpleStyleReader styleReader = new SimpleStyleReader()
89+
Style style = styleReader.read("fill=#555555 fill-opacity=0.6 stroke=#555555 stroke-width=0.5 label=name label-polygonalign=mbr")
90+
assertEquals style.toString(), "Composite (Fill(color = #555555, opacity = 0.6), Stroke(color = #555555, width = 0.5), Label(property = name))"
91+
Composite composite = style as Composite
92+
assertEquals("mbr", composite.parts[2].options["polygonAlign"])
93+
}
94+
95+
@Test void labelMaxDisplacementAndMaxAngleDelta() {
96+
SimpleStyleReader styleReader = new SimpleStyleReader()
97+
Style style = styleReader.read("fill=#555555 fill-opacity=0.6 stroke=#555555 stroke-width=0.5 label=name label-maxdisplacement=10 label-maxangledelta=45")
98+
assertEquals style.toString(), "Composite (Fill(color = #555555, opacity = 0.6), Stroke(color = #555555, width = 0.5), Label(property = name))"
99+
Composite composite = style as Composite
100+
assertEquals("45.0", composite.parts[2].options["maxAngleDelta"])
101+
assertEquals("10.0", composite.parts[2].options["maxDisplacement"])
102+
}
103+
86104
@Test void readFromMap() {
87105
SimpleStyleReader styleReader = new SimpleStyleReader()
88106
Style style = styleReader.read([fill: 'wheat', 'stroke-width': 1.2])

0 commit comments

Comments
 (0)