Hi, everyone,
I've been struggling to get label working with a polygon shapefile (pt/line
works fine). Basically polygon draws fine without any label. Here is my
code, could anyone please help? Thanks a bunch.

        private Style getPolygonLabelStyle(){
                StyleBuilder sb = new StyleBuilder();
                StyleFactory styleFactory = sb.getStyleFactory();
                
                //LinePlacement linePlacement = sb.createLinePlacement(10);
                
                float[] f = {0.5f};
                Stroke stroke = 
styleFactory.createStroke(sb.colorExpression(Color.BLACK), 
                                sb.literalExpression(2), 
sb.literalExpression(1), 
                                sb.attributeExpression(sb.LINE_JOIN_ROUND),
sb.attributeExpression(sb.LINE_CAP_ROUND),
                                f, sb.literalExpression(3), null, null);
                Fill fill = 
styleFactory.createFill(sb.colorExpression(Color.YELLOW),
sb.literalExpression(0.7));
                
                PolygonSymbolizer ploygonSymbolizer =
styleFactory.createPolygonSymbolizer(stroke, fill, null);
                
                TextSymbolizer textSymbolizer =
sb.createTextSymbolizer(sb.createFill(Color.BLACK),
                new org.geotools.styling.Font[] { sb.createFont("Arial",12),
sb.createFont("Arial", 10) },
                sb.createHalo(Color.WHITE, 1, 2),
sb.literalExpression("hello world"), null, "Shape");
                
                Style polygonStyle = sb.createStyle(ploygonSymbolizer);
                polygonStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(null,
sb.createRule(textSymbolizer)));
                
                return polygonStyle;
        }
-- 
View this message in context: 
http://n2.nabble.com/How-to-label-a-polygon--tp2388500p2388500.html
Sent from the geotools-devel mailing list archive at Nabble.com.


------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to