/** * Creates a rendered style * * <p>Makes use of a symbolizer cache based on identity to avoid recomputing over and over the * same style object and to reduce memory usage. The same Style2D object will be returned by * subsequent calls using the same feature independent symbolizer with the same scaleRange. * * @param drawMe The feature * @param symbolizer The SLD symbolizer * @return A rendered style equivalent to the symbolizer */ public Style2D createStyle(Object drawMe, Symbolizer symbolizer) { return createStyle(drawMe, symbolizer, null); }
SLDStyleFactory styleFactory = new SLDStyleFactory(); Style2D tmp = styleFactory.createStyle( feature, pointSymbolizer,
@Override protected Expression rescaleGraphicSize(Graphic gr) { Expression size = gr.getSize(); if (size == null || size == Expression.NIL) { PointSymbolizer symbolizer = sf.createPointSymbolizer(gr, null); Style2D style = ssf.createStyle(null, symbolizer, INFINITE_RANGE); if (style instanceof IconStyle2D) { IconStyle2D is = (IconStyle2D) style; size = ff.literal(is.getIcon().getIconHeight()); } else if (style instanceof GraphicStyle2D) { GraphicStyle2D gs = (GraphicStyle2D) style; size = ff.literal(gs.getImage().getHeight()); } else if (style instanceof MarkStyle2D) { MarkStyle2D ms = (MarkStyle2D) style; size = ff.literal(ms.getSize()); } } return rescale(size); } }
public void testCreateDynamicExternalGraphics() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "${icon}", "image/png"); symb.getGraphic().addExternalGraphic(eg); GraphicStyle2D gs = (GraphicStyle2D) sld.createStyle(feature, symb, range); // make sure the style has been recognized as dynamic SymbolizerKey key = new SymbolizerKey(symb, range); assertTrue(sld.dynamicSymbolizers.containsKey(key)); BufferedImage img = gs.getImage(); BufferedImage expected = ImageIO.read(StreamingRenderer.class.getResource("test-data/draw.png")); assertEquals(expected.getHeight(), img.getHeight()); assertEquals(expected.getWidth(), img.getWidth()); // the two images are equal, but they have different color models due to the // different ways they have been loaded }
public void testCreateDynamicExternalGraphicsVector() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "${icon}", "image/png"); symb.getGraphic().addExternalGraphic(eg); sld.setVectorRenderingEnabled(true); GraphicStyle2D gs = (GraphicStyle2D) sld.createStyle(feature, symb, range); // make sure the style has been recognized as dynamic SymbolizerKey key = new SymbolizerKey(symb, range); assertTrue(sld.dynamicSymbolizers.containsKey(key)); BufferedImage expected = ImageIO.read(StreamingRenderer.class.getResource("test-data/draw.png")); assertEquals(expected.getHeight(), gs.getImage().getHeight()); assertEquals(expected.getWidth(), gs.getImage().getWidth()); }
public void testCreateDynamicExternalFormat() throws Exception { feature.setAttribute("symb", "image/png"); URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "${icon}", "${symb}"); symb.getGraphic().addExternalGraphic(eg); GraphicStyle2D gs = (GraphicStyle2D) sld.createStyle(feature, symb, range); // make sure the style has been recognized as dynamic SymbolizerKey key = new SymbolizerKey(symb, range); assertTrue(sld.dynamicSymbolizers.containsKey(key)); BufferedImage img = gs.getImage(); BufferedImage expected = ImageIO.read(StreamingRenderer.class.getResource("test-data/draw.png")); assertEquals(expected.getHeight(), img.getHeight()); assertEquals(expected.getWidth(), img.getWidth()); // the two images are equal, but they have different color models due to the // different ways they have been loaded }
public void testCreateDynamicMark() throws Exception { PointSymbolizer symb = sf.createPointSymbolizer(); Mark myMark = sf.createMark(); final String ttfUrl = "ttf://Serif#${symb}"; myMark.setWellKnownName(ff.literal(ttfUrl)); symb.getGraphic().addMark(myMark); MarkStyle2D ms = (MarkStyle2D) sld.createStyle(feature, symb, range); assertNotNull(ms.getShape()); // make sure the style has been recognized as dynamic SymbolizerKey key = new SymbolizerKey(symb, range); assertTrue(sld.dynamicSymbolizers.containsKey(key)); Shape expected = new TTFMarkFactory().getShape(null, ff.literal("ttf://Serif#0xF054"), feature); // no general path equality implemented, we have to check manually PathIterator piExpected = expected.getPathIterator(new AffineTransform()); PathIterator pi = ms.getShape().getPathIterator(new AffineTransform()); double[] coordsExpected = new double[6]; double[] coords = new double[6]; assertEquals(piExpected.getWindingRule(), pi.getWindingRule()); while (!piExpected.isDone()) { assertFalse(pi.isDone()); piExpected.currentSegment(coordsExpected); pi.currentSegment(coords); assertEquals(coordsExpected[0], coords[0], 0.00001); assertEquals(coordsExpected[1], coords[1], 0.00001); piExpected.next(); pi.next(); } assertTrue(pi.isDone()); }
paintCommands++; } else { Style2D style = styleFactory.createStyle(drawMe.feature, symbolizer);
double priorityValue) { TextStyle2D textStyle = (TextStyle2D) styleFactory.createStyle(feature, symbolizer, scaleRange);
private Literal estimateGraphicSize(ExternalGraphic eg) { Graphic testGraphic = sf.createGraphic( new ExternalGraphic[] {eg}, null, null, LITERAL_ONE, Expression.NIL, ff.literal(0)); PointSymbolizer testSymbolizer = sf.createPointSymbolizer(testGraphic, null); Style2D style = sldFactory.createStyle(null, testSymbolizer); int size = SLDStyleFactory.DEFAULT_MARK_SIZE; if (style instanceof GraphicStyle2D) { GraphicStyle2D gs2d = (GraphicStyle2D) style; size = gs2d.getImage().getWidth(); } else if (style instanceof IconStyle2D) { IconStyle2D is2d = (IconStyle2D) style; size = is2d.getIcon().getIconWidth(); } Literal sizeExpression = ff.literal(size); return sizeExpression; }
styleFactory.createStyle(feature, symbolizer, scaleRange); } catch (IllegalArgumentException iae) {
labelCache.put(layerId, (TextSymbolizer) symbolizers[m], feature, shape, scaleRange); } else { Style2D style = styleFactory.createStyle(feature, symbolizers[m], scaleRange); painter.paint(graphics, shape, style, scaleDenominator);
labelCache.put(layerId, (TextSymbolizer) symbolizers[m], feature, shape, scaleRange); } else { Style2D style = styleFactory.createStyle(feature, symbolizers[m], scaleRange); painter.paint(graphics, shape, style, scaleDenominator);
Style2D style2d = styleFactory.createStyle(sampleFeature, symbolizer, scaleRange); LiteShape2 shape = getSampleShape(symbolizer, w, h);
if (!(group)) TextStyle2D textStyle=(TextStyle2D) styleFactory.createStyle(feature, symbolizer, scaleRange); .createStyle(feature, symbolizer, scaleRange); LabelCacheItem item = new LabelCacheItem(layerId, textStyle, shape, label);
shape, scaleRange); } else { Style2D style = styleFactory.createStyle(drawMe.content, symbolizer, scaleRange); painter.paint(graphics, shape, style, scaleDenominator);
Shape shape; try { Style2D style = styleFactory.createStyle(feature, symbolizers[m], scaleRange); if( isJTS ){ Geometry g;
shape, scaleRange); } else { Style2D style = styleFactory.createStyle(drawMe.content, symbolizer, scaleRange);
Shape shape; try { Style2D style = styleFactory.createStyle(feature, symbolizers[m], scaleRange); if( isJTS ){ Geometry g;
private LabelCacheItem buildLabelCacheItem(String layerId, TextSymbolizer symbolizer, Feature feature, LiteShape2 shape, NumberRange scaleRange, String label, double priorityValue) { TextStyle2D textStyle = (TextStyle2D) styleFactory.createStyle(feature, symbolizer, scaleRange);