From: Wojtek Z. <w.z...@gm...> - 2006-02-12 15:47:57
|
This is one of the methods I use to create styles for my map layers. I use MySQL database to hold the features and their names. The "NAME" attribute i= s the name of the feature. I would like to find some way to hide/show the tex= t labels depending on the zoom of the map. If the user zooms the map out, the text labels should disappear (if there is a lot of them, the image gets really messy). If he zooms in, they should appear again. Can it be done by adding some rules here? private static Style createStar() { Mark star =3D sb.createMark(StyleBuilder.MARK_STAR, Color.YELLOW, Color.BLACK, 0); Graphic gr =3D sb.createGraphic(null ,star, null, 0.7, 30, 0); PointSymbolizer ps =3D sb.createPointSymbolizer(gr); Rule r; TextSymbolizer ts =3D null; try { ts =3D sb.createTextSymbolizer(Color.BLACK, sb.createFont(new Font("Arial", Font.PLAIN, 12)), "NAME"); // the NAME attribute holds the text of the label } catch(IllegalFilterException ife) {} if(ts !=3D null) { ts.setHalo(sb.createHalo(Color.WHITE, 1, 1)); ts.setLabelPlacement(sb.createPointPlacement(0, 0, 5, 0, 0)); r =3D sb.createRule(new Symbolizer[] {ps, ts}); } else r =3D sb.createRule(new Symbolizer[] {ps}); Style newStyle =3D sb.createStyle(); newStyle.addFeatureTypeStyle(sb.createFeatureTypeStyle(null, r)); return newStyle; } Any help would be appreciated wojtek |