Skip to content

Commit

Permalink
[GEOS-9094] GetLegendGraphics JSON output generates the same link for…
Browse files Browse the repository at this point in the history
… stacked symbols in the same rule
  • Loading branch information
ianturton committed Jan 11, 2019
1 parent 52bdc6b commit c0a1b1e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ public static Graphic getGraphic(Symbolizer symbolizer, boolean includeNonPointG
} else if (symbolizer instanceof LineSymbolizer) {
final Stroke stroke = ((LineSymbolizer) symbolizer).getStroke();
if (stroke != null) {
return stroke.getGraphicStroke();
if (stroke.getGraphicStroke() != null) return stroke.getGraphicStroke();
if (stroke.getGraphicFill() != null) {
return stroke.getGraphicFill();
}
}
} else if (symbolizer instanceof TextSymbolizer2) {
return ((TextSymbolizer2) symbolizer).getGraphic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ public class JSONLegendGraphicBuilder extends LegendGraphicBuilder {

private WMS wms;
private String ruleName;
private int symbolizerCount;

/**
* @param request
Expand Down Expand Up @@ -334,6 +335,7 @@ public JSONObject buildLegendGraphic(GetLegendGraphicRequest request) {
feature = null;
}
List<Symbolizer> symbolizers = rule.symbolizers();
symbolizerCount = 0;
for (Symbolizer symbolizer : symbolizers) {
JSONObject jSymb = new JSONObject();
JSONObject symb = processSymbolizer(symbolizer);
Expand Down Expand Up @@ -505,7 +507,7 @@ private JSONObject processGraphic(JSONObject ret, Graphic graphic) {
List<Integer> origRuleNo = new ArrayList<>();
int ruleCount = 0;
for (List<MiniRule> m : miniStyle) {
List<MiniRule> newRules = new ArrayList<>(m.size());
List<MiniRule> newRules = new ArrayList<>(miniStyle.size());
for (MiniRule r : m) {
String rName = r.getName();
if (rName != null && !rName.equalsIgnoreCase(ruleName)) {
Expand All @@ -529,9 +531,16 @@ private JSONObject processGraphic(JSONObject ret, Graphic graphic) {
String base = iconUrl.substring(0, index + 1);
String[] refs = iconUrl.substring(index + 1).split("&");
for (int i = 0; i < refs.length; i++) {
String ref =
refs[i].replaceAll("(\\d\\.)\\d(\\.\\d=)", "$1" + origRuleNo.get(0) + "$2");
base += ref + "&";
if (refs[i].matches("(\\d\\.)\\d(\\.\\d[\\.\\w+]*=[\\d.]*)")) {
String ref =
refs[i].replaceAll(
"(\\d\\.)\\d(\\.\\d=)", "$1" + origRuleNo.get(0) + "$2");
String[] split = refs[i].split("\\.");
int symCount = Integer.parseInt(split[2].replaceAll("=", ""));
if (symbolizerCount == symCount) base += ref + "&";
} else {
base += refs[i] + "&";
}
}
if (base.endsWith("&")) {
iconUrl = base.substring(0, base.length() - 1);
Expand Down Expand Up @@ -577,6 +586,7 @@ private JSONObject processGraphic(JSONObject ret, Graphic graphic) {
ret.element(ANCHOR_POINT, anchor);
}
ret.element(GRAPHICS, jGraphics);
symbolizerCount++;
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -880,14 +880,14 @@ public void testExternalGraphic() throws Exception {
CoverageInfo cInfo = getCatalog().getCoverageByName("world");
assertNotNull(cInfo);

// printStyle(externalGraphicStyle);
printStyle(externalGraphicStyle);
req.setStyle(externalGraphicStyle);

req.setScale(1.0);

JSONObject result = this.legendProducer.buildLegendGraphic(req);
assertNotEmpty(result);
// System.out.println(result.toString(2) );
print(result);
JSONArray lx = result.getJSONArray(JSONLegendGraphicBuilder.LEGEND);
assertEquals(1, lx.size());
// rule 1 is a mark
Expand Down Expand Up @@ -932,12 +932,12 @@ public void testThickPolygonBorder() throws Exception {
req.setLayer(ftInfo.getFeatureType());
Style style = readSLD("ThickBorder.sld");
req.setStyle(style);
// printStyle(style);
printStyle(style);
JSONObject result = this.legendProducer.buildLegendGraphic(req);

assertNotNull(result);
assertFalse(result.isEmpty());
// System.out.println(result.toString(2));
print(result);
JSONArray legend = result.getJSONArray(JSONLegendGraphicBuilder.LEGEND);
assertNotNull(legend);
assertFalse(legend.isEmpty());
Expand Down Expand Up @@ -982,9 +982,9 @@ public void testSimplePoint() throws Exception {
req.setLayer(ftInfo.getFeatureType());
Style style = readSLD("point.sld");
req.setStyle(style);
// printStyle(style);
printStyle(style);
JSONObject result = this.legendProducer.buildLegendGraphic(req);
// System.out.println(result.toString(2));
print(result);
assertNotNull(result);
// blue 2px wide line
JSONArray legend = result.getJSONArray(JSONLegendGraphicBuilder.LEGEND);
Expand Down Expand Up @@ -1017,9 +1017,9 @@ public void testHospitalPoint() throws Exception {
req.setLayer(ftInfo.getFeatureType());
Style style = readSLD("hospital.sld");
req.setStyle(style);
// printStyle(style);
printStyle(style);
JSONObject result = this.legendProducer.buildLegendGraphic(req);
// System.out.println(result.toString(2));
print(result);
assertNotNull(result);
// blue 2px wide line
JSONArray legend = result.getJSONArray(JSONLegendGraphicBuilder.LEGEND);
Expand All @@ -1036,7 +1036,12 @@ public void testHospitalPoint() throws Exception {
symbolizers.getJSONObject(0).getJSONObject(JSONLegendGraphicBuilder.POINT);
assertNotNull(pointSymb);
assertEquals(
"http://local-test:8080/geoserver/kml/icon/Hospital?0.0.0=&0.0.1=",
"http://local-test:8080/geoserver/kml/icon/Hospital?0.0.0=",
pointSymb.getString("url"));
pointSymb = symbolizers.getJSONObject(1).getJSONObject(JSONLegendGraphicBuilder.POINT);
assertNotNull(pointSymb);
assertEquals(
"http://local-test:8080/geoserver/kml/icon/Hospital?0.0.1=",
pointSymb.getString("url"));
}

Expand All @@ -1059,7 +1064,7 @@ public void testTrickyGraphic() throws Exception {
req.setStyle(style);
printStyle(style);
JSONObject result = this.legendProducer.buildLegendGraphic(req);
// System.out.println(result.toString(2));
print(result);
assertNotNull(result);
// blue 2px wide line
JSONArray legend = result.getJSONArray(JSONLegendGraphicBuilder.LEGEND);
Expand All @@ -1083,7 +1088,12 @@ public void testTrickyGraphic() throws Exception {
pointSymb = symbolizers.getJSONObject(0).getJSONObject(JSONLegendGraphicBuilder.POINT);
assertNotNull(pointSymb);
assertEquals(
"http://local-test:8080/geoserver/kml/icon/tricky_point?0.2.0=&0.2.1=",
"http://local-test:8080/geoserver/kml/icon/tricky_point?0.2.0=",
pointSymb.getString("url"));
pointSymb = symbolizers.getJSONObject(1).getJSONObject(JSONLegendGraphicBuilder.POINT);
assertNotNull(pointSymb);
assertEquals(
"http://local-test:8080/geoserver/kml/icon/tricky_point?0.2.1=",
pointSymb.getString("url"));
}

Expand Down Expand Up @@ -1386,9 +1396,13 @@ public void testFullLine() throws Exception {
JSONObject lineSymb2 =
symbolizers.getJSONObject(2).getJSONObject(JSONLegendGraphicBuilder.LINE);
assertFalse(lineSymb2.isNullObject());
assertFalse(lineSymb2.getJSONObject(JSONLegendGraphicBuilder.GRAPHIC_FILL).isNullObject());
assertEquals("#0000FF", lineSymb.get(JSONLegendGraphicBuilder.STROKE));
assertEquals("2", lineSymb.get(JSONLegendGraphicBuilder.STROKE_WIDTH));
final JSONObject graphicFill2 =
lineSymb2.getJSONObject(JSONLegendGraphicBuilder.GRAPHIC_FILL);

assertFalse(graphicFill2.isNullObject());
assertEquals(
"http://local-test:8080/geoserver/kml/icon/Default%20Styler?0.0.1=&0.0.1.rotation=0.0&npg=true",
graphicFill2.getString("url"));
}

@org.junit.Test
Expand Down Expand Up @@ -1630,12 +1644,6 @@ public void testContrastRaster() throws Exception {
assertEquals("0.5", ce.getString(JSONLegendGraphicBuilder.GAMMA_VALUE));
assertEquals("true", ce.get(JSONLegendGraphicBuilder.NORMALIZE));
}
/** @param result */
private void assertNotEmpty(JSONObject result) {
assertNotNull(result);
assertFalse(result.isNullObject());
assertFalse(result.isEmpty());
}

@org.junit.Test
public void testDescreteRaster() throws Exception {
Expand Down Expand Up @@ -1679,6 +1687,13 @@ public void testDescreteRaster() throws Exception {

assertEquals("intervals", colormap.get(JSONLegendGraphicBuilder.COLORMAP_TYPE));
}
/** @param result */
private void assertNotEmpty(JSONObject result) {
assertNotNull(result);
assertFalse(result.isNullObject());
assertFalse(result.isEmpty());
}

/**
* @param sldName
* @throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<GraphicFill>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<WellKnownName>circle</WellKnownName>
<Fill>
<CssParameter name="fill">#ffff00</CssParameter>
</Fill>
Expand Down

0 comments on commit c0a1b1e

Please sign in to comment.