Skip to content

Commit d4a5961

Browse files
authored
Merge pull request #1914 from lat-lon/fix/lendendSymbolsIfSizeIsCalculated-93
Fixed size of symbols in legends if size is calculated
2 parents b840216 + 0c0c685 commit d4a5961

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

deegree-core/deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/legends/StandardLegendRenderer.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,7 @@ else if (isLine) {
127127
paintLegendText(origin, opts, text, textRenderer);
128128

129129
// normalize symbol sizes
130-
double maxSize = 0;
131-
if (isPoint) {
132-
for (Styling s : stylings) {
133-
if (s instanceof PointStyling) {
134-
maxSize = max(((PointStyling) s).graphic.size, maxSize);
135-
}
136-
}
137-
}
130+
double maxSize = calculateMaxSize(isPoint);
138131

139132
if (rule == null) {
140133
for (Styling s : stylings) {
@@ -146,6 +139,21 @@ else if (isLine) {
146139
paintRule(isPoint, maxSize, opts, geom);
147140
}
148141

142+
private double calculateMaxSize(boolean isPoint) {
143+
double maxSize = 0;
144+
if (isPoint) {
145+
for (Styling s : stylings) {
146+
if (s instanceof PointStyling) {
147+
maxSize = max(((PointStyling) s).graphic.size, maxSize);
148+
}
149+
}
150+
}
151+
if (maxSize > 0)
152+
return maxSize;
153+
// fallback to default size 6 to avoid infinite legend size if maxSize is 0
154+
return 6;
155+
}
156+
149157
private void paintRule(boolean isPoint, double maxSize, LegendOptions opts, Geometry geom) {
150158
LinkedList<Symbolizer<?>> syms = new LinkedList<Symbolizer<?>>();
151159
rule.evaluate(syms, null, null);
@@ -159,6 +167,10 @@ private void paintRule(boolean isPoint, double maxSize, LegendOptions opts, Geom
159167
if (styling instanceof PointStyling && isPoint) {
160168
PointStyling ps = ((PointStyling) styling).copy();
161169
ps.uom = Metre;
170+
// fallback to default size 6 to avoid infinite legend size if maxSize
171+
// is 0
172+
if (ps.graphic.size <= 0)
173+
ps.graphic.size = 6;
162174
ps.graphic.size = ps.graphic.size / maxSize * min(opts.baseWidth, opts.baseHeight);
163175
styling = ps;
164176
}

0 commit comments

Comments
 (0)