@SuppressWarnings("unchecked") @Test public void testExpressionLiteral() throws Exception { String yaml = "text: \n" + " geometry: test literal\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); TextSymbolizer symb = (TextSymbolizer) fs.rules().get(0).symbolizers().get(0); Expression expr = symb.getGeometry(); assertThat( expr, allOf(instanceOf(Literal.class), hasProperty("value", equalTo("test literal")))); }
@Test public void testExpressionEmbeded() throws Exception { String yaml = "text: \n" + " geometry: literal0${attribute1}literal2\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); TextSymbolizer symb = (TextSymbolizer) fs.rules().get(0).symbolizers().get(0); Expression expr = symb.getGeometry(); assertThat(expr, instanceOf(ConcatenateFunction.class)); List<Expression> params = ((ConcatenateFunction) expr).getParameters(); assertThat(params.size(), is(3)); assertThat(params.get(0), literal(equalTo("literal0"))); assertThat(params.get(1), attribute("attribute1")); assertThat(params.get(2), literal(equalTo("literal2"))); }
@Test public void testExpressionAttribute() throws Exception { String yaml = "text: \n" + " geometry: ${testAttribute}\n" + ""; StyledLayerDescriptor sld = Ysld.parse(yaml); FeatureTypeStyle fs = SLD.defaultStyle(sld).featureTypeStyles().get(0); TextSymbolizer symb = (TextSymbolizer) fs.rules().get(0).symbolizers().get(0); Expression expr = symb.getGeometry(); assertThat(expr, attribute("testAttribute")); }
public void testTextSymbolizerWithGeometryFunction() { TextSymbolizer symb = sf.createTextSymbolizer(); // Set a function as geometry Function geomFunc = ff.function("centroid", ff.property("the_geom")); symb.setGeometry(geomFunc); TextSymbolizer copy = (TextSymbolizer) visitor.copy(symb); // compare it assertEquals( "Any Expression set as Geometry must be correctly replicated", geomFunc, copy.getGeometry()); }
public void visit(TextSymbolizer text) { TextSymbolizer copy = sf.createTextSymbolizer(); copy.setFill(copy(text.getFill())); copy.fonts().clear(); copy.fonts().addAll(copyFonts(text.fonts())); copy.setGeometry(copy(text.getGeometry())); copy.setUnitOfMeasure(text.getUnitOfMeasure()); copy.setHalo(copy(text.getHalo())); copy.setLabel(copy(text.getLabel())); copy.setLabelPlacement(copy(text.getLabelPlacement())); copy.setPriority(copy(text.getPriority())); copy.getOptions().putAll(text.getOptions()); if (text instanceof TextSymbolizer2) { TextSymbolizer2 text2 = (TextSymbolizer2) text; TextSymbolizer2 copy2 = (TextSymbolizer2) copy; copy2.setGraphic(copy(text2.getGraphic())); copy2.setSnippet(copy(text2.getSnippet())); copy2.setFeatureDescription(copy(text2.getFeatureDescription())); copy2.setOtherText(copy(text2.getOtherText())); } if (STRICT && !copy.equals(text)) { throw new IllegalStateException( "Was unable to duplicate provided TextSymbolizer:" + text); } pages.push(copy); }
public void visit(org.geotools.styling.TextSymbolizer ts) { pages.push(null); addGeometryExpression(ts.getGeometry(), geometriesOnTextSymbolizer); }
encodeGeometryExpression(text.getGeometry());
if (text.getGeometry() != null) { text.getGeometry().accept(this, null); } else { this.defaultGeometryUsed = true; // they want the default geometry (see GEOS-469)
copy.setGeometry(copy(text.getGeometry()));
public void visit(TextSymbolizer text) { TextSymbolizer copy = sf.createTextSymbolizer(); copy.setFill( copy( text.getFill())); copy.setFont( copy( text.getFont())); copy.setGeometry(copy(text.getGeometry())); copy.setUnitOfMeasure(text.getUnitOfMeasure()); copy.setHalo( copy( text.getHalo() )); copy.setLabel( copy( text.getLabel())); copy.setLabelPlacement( copy( text.getLabelPlacement())); copy.setPriority( copy( text.getPriority())); copy.getOptions().putAll(text.getOptions()); if (text instanceof TextSymbolizer2){ TextSymbolizer2 text2 = (TextSymbolizer2) text; TextSymbolizer2 copy2 = (TextSymbolizer2) copy; copy2.setGraphic( copy(text2.getGraphic())); copy2.setSnippet(copy(text2.getSnippet())); copy2.setFeatureDescription(copy(text2.getFeatureDescription())); copy2.setOtherText(copy(text2.getOtherText())); } if( STRICT && !copy.equals( text )){ throw new IllegalStateException("Was unable to duplicate provided TextSymbolizer:"+text ); } pages.push(copy); }
@Override public void visit(TextSymbolizer text) { if (text.getDescription() != null) { text.getDescription().accept(this); } if (text.getFill() != null) { text.getFill().accept(this); } if (text.getFont() != null) { //text.getFont().accept(this, null); } if (text.getGeometry() != null) { //text.getGeometry().accept(visitor, extraData) } if (text.getHalo() != null) { text.getHalo().accept(this); } if (text.getLabel() != null) { //text.getLabel().accept(visitor, extraData) } if (text.getLabelPlacement() != null) { text.getLabelPlacement().accept(this); } if (text.getPriority() != null) { //text.getPriority().accept(visitor, extraData) } }
FieldIdEnum.GEOMETRY, textSymbolizer.getGeometry());
encodeGeometryExpression(text.getGeometry());
if (text.getGeometry() != null) { text.getGeometry().accept(this, null); } else { this.defaultGeometryUsed = true; // they want the default geometry (see GEOS-469)