Skip to content

Commit 92e469c

Browse files
authored
Merge pull request #1912 from lat-lon/fix/legendSize-1105
Fixed requesting of legend graphics each time the capabilities are requested
2 parents e59dfa1 + 2ce2de9 commit 92e469c

File tree

2 files changed

+16
-5
lines changed
  • deegree-core
    • deegree-core-rendering-2d/src/main/java/org/deegree/rendering/r2d/legends
    • deegree-core-style/src/main/java/org/deegree/style/se/unevaluated

2 files changed

+16
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ Occam Labs UG (haftungsbeschränkt)
5353
import java.net.URL;
5454
import java.util.List;
5555

56-
import javax.imageio.ImageIO;
57-
5856
import org.deegree.commons.utils.Pair;
59-
import org.deegree.commons.utils.net.HttpUtils;
6057
import org.deegree.geometry.Envelope;
6158
import org.deegree.geometry.GeometryFactory;
6259
import org.deegree.rendering.r2d.Java2DRasterRenderer;
@@ -92,6 +89,9 @@ List<LegendItem> prepareLegend(Style style, Graphics2D g, int width, int height)
9289
}
9390

9491
Pair<Integer, Integer> getLegendSize(Style style) {
92+
if (style.getLegendSize() != null) {
93+
return style.getLegendSize();
94+
}
9595
URL url = style.getLegendURL();
9696
File file = style.getLegendFile();
9797
if (url == null) {
@@ -108,7 +108,7 @@ Pair<Integer, Integer> getLegendSize(Style style) {
108108
try {
109109
BufferedImage legend = get(IMAGE, url.toExternalForm(), null);
110110
if (legend != null) {
111-
return new Pair<Integer, Integer>(legend.getWidth(), legend.getHeight());
111+
style.setLegendSize(new Pair<>(legend.getWidth(), legend.getHeight()));
112112
}
113113
else {
114114
LOG.warn("Legend file {} could not be read, using dynamic legend.", url);
@@ -131,7 +131,8 @@ Pair<Integer, Integer> getLegendSize(Style style) {
131131
res.second = 2 * opts.spacing + opts.baseWidth;
132132
}
133133

134-
return res;
134+
style.setLegendSize(res);
135+
return style.getLegendSize();
135136
}
136137

137138
}

deegree-core/deegree-core-style/src/main/java/org/deegree/style/se/unevaluated/Style.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ public class Style implements Copyable<Style> {
120120

121121
private boolean prefersGetLegendGraphicUrl;
122122

123+
private Pair<Integer, Integer> legendSize;
124+
123125
/**
124126
* @param rules
125127
* @param labels
@@ -451,6 +453,14 @@ public URL getLegendURL() {
451453
return legendUrl;
452454
}
453455

456+
public Pair<Integer, Integer> getLegendSize() {
457+
return legendSize;
458+
}
459+
460+
public void setLegendSize(Pair<Integer, Integer> legendSize) {
461+
this.legendSize = legendSize;
462+
}
463+
454464
public void setPrefersGetLegendGraphicUrl(boolean prefers) {
455465
this.prefersGetLegendGraphicUrl = prefers;
456466
}

0 commit comments

Comments
 (0)