2009/10/23 Oliver Gottwald wrote:
> By the way if I wanted to add a Label to the point for the code snipped
> below do you have an example for that possibly or could you point me in
> the right direction? Labels are on my hit list for tomorrow.
>
Labelling features involves including a TextSymbolizer in your Style
along with PointSymbolizer (or whatever).
Some options for doing it programmatically (there are others too)...
1. Really cheat and use JSimpleStyleDialog which gives the option of
adding labels...
SimpleFeatureType TYPE = ...
Style = JSimpleStyleDialog.showDialog(null, TYPE);
2. Cheat just a little bit and use the SLD utility class...
Color lineColor = ...
Color fillColor = ...
float opacity = 1.0f;
float size = 5.0f;
String labelAttribute = "name";
Font font = styleFactory.getDefaultFont();
Style = SLD.createPointStyle("Circle", lineColor, fillColor, opacity,
size, labelAttribute, font);
3. Spurn easy solutions and do it all by hand...
StyleFactory sf = ...
FilterFactory ff = ...
String symbolName = "Circle"; // or Cross, Square, X, Triangle, Star
Color lineColor = ...
float lineWidth = ...
Color fillColor = ...
float opacity = ..
float size = ..
String labelAttribute = "name";
Font font = sf.getDefaultFont();
Stroke stroke = sf.createStroke(ff.literal(lineColor), ff.literal(lineWidth));
Fill fill = sf.createFill(ff.literal(fillColor), ff.literal(opacity));
Mark mark = sf.createMark(ff.literal(symbolName), stroke, fill,
ff.literal(size), ff.literal(0));
Graphic graphic = sf.createDefaultGraphic();
graphic.graphicalSymbols().clear();
graphic.graphicalSymbols().add(mark);
graphic.setSize(ff.literal(size));
PointSymbolizer pointSym = sf.createPointSymbolizer(graphic, null);
Fill labelFill = sf.createFill(ff.literal(Color.BLACK));
AnchorPoint anchor = sf.createAnchorPoint(ff.literal(0.5), ff.literal(0.0));
Displacement disp = sf.createDisplacement(ff.literal(0), ff.literal(size));
LabelPlacement placement = sf.createPointPlacement(anchor, disp, ff.literal(0));
TextSymbolizer textSym = sf.createTextSymbolizer(
labelFill, new Font[]{font}, null, ff.property(labelField),
placement, null);
Rule rule = sf.createRule();
rule.symbolizers().add( pointSym );
rule.symbolizers().add( textSym );
FeatureTypeStyle fts = sf.createFeatureTypeStyle(new Rule[] {rule});
Style style = sf.createStyle();
style.featureTypeStyles().add(fts);
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users