Paul: In what way are they not drawn correctly? The Drawer you found is for drawing a legend symbol; did you intend to use Renderer? I am not sure of the limitation of Drawer. -- Jody Garnett
On Wed, Mar 1, 2023 at 1:11 AM <paul.m...@lfv.se> wrote: > I’m trying to draw an example feature in a JFrame/JPanel while I’m > creating a Style. > > When I draw the example feature, with the created style in the Frame, the > feature is not drawn correctly when using hatched polygons, dashed lines, > polygons filled with images etc. > > Other more simple styles are drawn correct. > > But in my map application all the features are drawn correctly together > with the same styles. > > I create the styles for the example features exactly the same way as for > the layers in my map application. > > Features with a style created from the SLD below is drawn correctly in > the map but as a flat grey area in my SymViewer. > > What am I doing wrong? > > > > First I create a temporary Style from all the inputs and an empty > BufferedImage, then I send it SymViewer who draws an example feature in a > JPanel. > > > > Thanks, > > Paul > > > > ----------------------------------------------------------------------- > > import java.awt.Color; > > import java.awt.Graphics; > > import java.awt.image.BufferedImage; > > import javax.swing.JFrame; > > import javax.swing.JPanel; > > import javax.swing.border.EmptyBorder; > > import org.geotools.map.legend.Drawer; > > import org.geotools.styling.Style; > > import org.locationtech.jts.geom.LineString; > > import org.locationtech.jts.geom.Point; > > import org.locationtech.jts.geom.Polygon; > > import org.opengis.feature.simple.SimpleFeature; > > import javax.swing.border.LineBorder; > > import java.awt.SystemColor; > > > > public class SymViewer extends JFrame { > > private static final long serialVersionUID = 1L; > > private JPanel contentPane; > > /** > > * Create the frame. > > */ > > public SymViewer(BufferedImage img, Style style, String title, > String titleExtra, String geoType) { > > setBackground(SystemColor.text); > > setTitle(title + " " + titleExtra); > > BufferedImage image = drawSymbolic(img, style, geoType); > > setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); > > setBounds(0, 0, 439, 266); > > contentPane = new JPanel(); > > contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); > > setContentPane(contentPane); > > contentPane.setLayout(null); > > JPanel panel = new JPanel() { > > private static final long serialVersionUID = 1L; > > @Override > > protected void paintComponent(Graphics g) { > > super.paintComponent(g); > > g.drawImage(image, 0, 0, null); > > } > > }; > > panel.setBorder(new LineBorder(new Color(0, 0, 0))); > > panel.setBounds(0, 0, 434, 261); > > panel.setBackground(SystemColor.menu); > > contentPane.add(panel); > > } > > > > > > private BufferedImage drawSymbolic(BufferedImage img, Style style, > String geoType) { > > Drawer drawer = Drawer.create(); > > SimpleFeature feature = null; > > if (geoType.contains("Line")){ > > LineString line = drawer.line(new int[] { 15, 15, 400, 20, > 15, 200 }); > > feature = drawer.feature(line); > > } > > else if(geoType.contains("Polygon")) { > > Polygon p = drawer.polygon(new int[] { 15, 15, 400, 5, 400, > 200, 15, 200, 15, 15 }); > > feature = drawer.feature(p); > > } > > else if(geoType.contains("Point")) { > > Point p = drawer.point(216, 130); > > feature = drawer.feature(p); > > } > > if(feature != null) { > > drawer.drawDirect(img, feature, style); > > return img; > > } > > return null; > > } > > } > > > --------------------------------------------------------------------------------------- > > > > > > SLD file: > > > > <?xml version="1.0" encoding="ISO-8859-1"?> > > <sld:StyledLayerDescriptor > > xsi:schemaLocation="http://www.opengis.net/sld > StyledLayerDescriptor.xsd" > > xmlns="http://www.opengis.net/sld" > > xmlns:sld="http://www.opengis.net/sld" > > xmlns:ogc="http://www.opengis.net/ogc" > > xmlns:xlink="http://www.w3.org/1999/xlink" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > version="1.0.0"> > > <sld:NamedLayer> > > <sld:Name>Graphic fill</sld:Name> > > <sld:UserStyle> > > <sld:Title>Graphic fill</sld:Title> > > <sld:FeatureTypeStyle> > > <sld:Rule> > > <sld:PolygonSymbolizer> > > <sld:Fill> > > <sld:GraphicFill> > > <sld:Graphic> > > <sld:ExternalGraphic> > > <sld:OnlineResource > > xlink:type="simple" > > xlink:href="magnus.png" /> > > <sld:Format>image/png</sld:Format> > > </sld:ExternalGraphic> > > <sld:Size>93</sld:Size> > > </sld:Graphic> > > </sld:GraphicFill> > > </sld:Fill> > > </sld:PolygonSymbolizer> > > </sld:Rule> > > </sld:FeatureTypeStyle> > > </sld:UserStyle> > > </sld:NamedLayer> > > </sld:StyledLayerDescriptor> > > > _______________________________________________ > GeoTools-GT2-Users mailing list > GeoTools-GT2-Users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users