From: Oliver G. <ol...@dr...> - 2009-10-23 18:46:46
|
Michael, You Rock! I just got labels working in my example sets with option 3 below. I also added for non default fonts with the following line: Font font=styleFactory.createFont(filterFactory.literal("Arial"), filterFactory.literal(true), filterFactory.literal(true), filterFactory.literal(7)); createFont(fontFamily,fontStyle,fontWeight,fontSize) createFont(String,boolean,boolean,double) 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); |
From: Michael B. <mic...@gm...> - 2009-10-24 02:38:14
|
Hi again Oliver, Sorry - I replied to your other post before I saw this one. Great to hear that you got things working :) Michael |
From: dadar <iam...@ya...> - 2009-11-08 16:28:26
|
I want to ask something. can we labelling features not using ff.property(labelField)?? i want to add another string to labelling the features. how can I do it? Darmawan mbedward wrote: > > Hi again Oliver, > > Sorry - I replied to your other post before I saw this one. Great to > hear that you got things working :) > > Michael > > ------------------------------------------------------------------------------ > 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 > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > -- View this message in context: http://n2.nabble.com/Labeling-Features-tp3880564p3968735.html Sent from the geotools-gt2-users mailing list archive at Nabble.com. |
From: Stefan K. <kr...@wi...> - 2009-11-08 17:06:40
|
Am Sonntag 08 November 2009 17:28:15 schrieb dadar: > I want to ask something. can we labelling features not using > ff.property(labelField)?? > i want to add another string to labelling the features. how can I do it? if you want to use a fixed string, use ff.literal("here!") -- wiki² - Softwareentwicklung Stefan Krüger Straßburger Weg 26 53113 Bonn email kr...@wi... mobile 0151 50543949 webpage wikisquare.de skype alfonx reclaim your net - http://tor.eff.org enforce privacy - http://www.pgpi.org pgp key id: 51B576FD - http://pgp.mit.edu Please note that according to the German law on data retention, information on every electronic information exchange with me is retained for a period of six months. |