public ExternalGraphicParser(Factory factory) { super(factory); external = factory.style.createExternalGraphic((String) null, null); }
/** * wrapper for stylefactory method * * @param uri the uri of the image * @param format mime type of the image * @return the external graphic */ public ExternalGraphic createExternalGraphic(String uri, String format) { return sf.createExternalGraphic(uri, format); }
/** * wrapper for stylefactory method * * @param url the url of the image * @param format mime type of the image * @return the external graphic */ public ExternalGraphic createExternalGraphic(java.net.URL url, String format) { return sf.createExternalGraphic(url, format); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { // the Converters wrapper here is a workaround for http://jira.codehaus.org/browse/GEOT-2457 // for some reason on the IBM JDK returns a string, we should really find out why instead // of applying this bandaid URI uri = Converters.convert(node.getChildValue("OnlineResource"), URI.class); String format = (String) node.getChildValue("Format"); return styleFactory.createExternalGraphic(uri.toString(), format); } }
public void visit(ExternalGraphic exgr) { URL uri = null; try { uri = exgr.getLocation(); } catch (MalformedURLException huh) { } String format = exgr.getFormat(); Icon inlineContent = exgr.getInlineContent(); ExternalGraphic copy; if (inlineContent != null) { copy = sf.createExternalGraphic(inlineContent, format); } else { copy = sf.createExternalGraphic(uri, format); } copy.setCustomProperties(copy(exgr.getCustomProperties())); if (STRICT && !copy.equals(exgr)) { throw new IllegalStateException( "Was unable to duplicate provided ExternalGraphic:" + exgr); } pages.push(copy); }
public ExternalGraphic build() { if (unset) { return null; } ExternalGraphic externalGraphic; Collection<ColorReplacement> set = new HashSet<ColorReplacement>(); for (ColorReplacementBuilder replacement : replacements) { set.add(replacement.build()); } if (inline != null) { externalGraphic = sf.externalGraphic(inline, set); } else if (resource != null) { externalGraphic = sf.externalGraphic(resource, format, set); } else { externalGraphic = sf.createExternalGraphic(location, format); } if (parent == null) reset(); return externalGraphic; }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated modifiable */ public Object parse(ElementInstance instance, Node node, Object value) throws Exception { ExternalGraphic g; if (node.hasChild("InlineContent")) { String format = (String) node.getChildValue("Format"); Icon icon = (Icon) node.getChildValue("InlineContent"); g = styleFactory.createExternalGraphic(icon, format); } else { g = (ExternalGraphic) super.parse(instance, node, value); } return g; } }
public void testExternalGraphic() { ExternalGraphic exGraphic = sf.createExternalGraphic("http://somewhere", "image/png"); ExternalGraphic clone = visitor.copy(exGraphic); assertCopy(exGraphic, clone); ExternalGraphic notEq = sf.createExternalGraphic("http://somewhereelse", "image/jpeg"); assertEqualsContract(clone, notEq, exGraphic); // make sure it works for different format, same url ExternalGraphic notEq2 = visitor.copy(clone); notEq2.setFormat("image/jpeg"); assertEqualsContract(clone, notEq2, exGraphic); }
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 testExternalGraphic() { ExternalGraphic exGraphic = styleFactory.createExternalGraphic("http://somewhere", "image/png"); ExternalGraphic clone = (ExternalGraphic) ((Cloneable) exGraphic).clone(); assertClone(exGraphic, clone); ExternalGraphic notEq = styleFactory.createExternalGraphic("http://somewhereelse", "image/jpeg"); assertEqualsContract(clone, notEq, exGraphic); // make sure it works for different format, same url ExternalGraphic notEq2 = (ExternalGraphic) ((Cloneable) clone).clone(); notEq2.setFormat("image/jpeg"); assertEqualsContract(clone, notEq2, exGraphic); }
public void testDefaultSizeExternalGraphic() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); symb.getGraphic().addExternalGraphic(eg); GraphicStyle2D gs = (GraphicStyle2D) sld.createPointStyle(feature, symb, range); BufferedImage img = gs.getImage(); assertEquals(64, img.getHeight()); assertEquals(64, img.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 testResizeExternalGraphic() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); symb.getGraphic().graphicalSymbols().add(eg); symb.getGraphic().setSize(ff.literal(20)); GraphicStyle2D gs = (GraphicStyle2D) sld.createPointStyle(feature, symb, range); BufferedImage img = gs.getImage(); assertEquals(20, img.getHeight()); assertEquals(20, img.getWidth()); }
public void testFallbackGraphicMark() throws Exception { PointSymbolizer symb = sf.createPointSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic("http://foo.com/invalid_or_missing_image_url", null); symb.getGraphic().graphicalSymbols().add(eg); Style2D icon = sld.createPointStyle(feature, symb, range); assertNotNull(icon); }
private static Style createPointStyle() { StyleFactory sf = CommonFactoryFinder.getStyleFactory(); URL iconUrl = ScreenMapShapefileTest.class.getResource("icon.png"); ExternalGraphic icon = sf.createExternalGraphic(iconUrl, "image/png"); Graphic graphic = sf.createGraphic(new ExternalGraphic[] {icon}, null, null, null, null, null); PointSymbolizer symbolizer = sf.createPointSymbolizer(graphic, "the_geom"); Rule rule = sf.createRule(); rule.symbolizers().add(symbolizer); FeatureTypeStyle fts = sf.createFeatureTypeStyle(); fts.rules().add(rule); Style style = sf.createStyle(); style.featureTypeStyles().add(fts); return style; }
public void testExternalGraphicWithInlineContent() { Icon icon = new Icon() { @Override public void paintIcon(Component c, Graphics g, int x, int y) {} @Override public int getIconWidth() { return 16; } @Override public int getIconHeight() { return 16; } }; ExternalGraphic exGraphic = sf.createExternalGraphic(icon, "image/png"); ExternalGraphic clone = visitor.copy(exGraphic); assertCopy(exGraphic, clone); assertSame(exGraphic.getInlineContent(), clone.getInlineContent()); ExternalGraphic notEq = sf.createExternalGraphic(icon, "image/jpeg"); assertEqualsContract(clone, notEq, exGraphic); // make sure it works for different format, same content ExternalGraphic notEq2 = visitor.copy(clone); notEq2.setFormat("image/jpeg"); assertEqualsContract(clone, notEq2, exGraphic); }
public void testResizeGraphicFill() throws Exception { URL url = StreamingRenderer.class.getResource("test-data/"); PolygonSymbolizer symb = sf.createPolygonSymbolizer(); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); Graphic g = sf.createGraphic( new ExternalGraphic[] {eg}, null, null, null, ff.literal(20), null); Fill fill = sf.createFill(null, null, null, g); symb.setFill(fill); PolygonStyle2D ps = sld.createPolygonStyle(feature, symb, range); assertTrue(ps.getFill() instanceof TexturePaint); TexturePaint paint = (TexturePaint) ps.getFill(); assertEquals(20, paint.getImage().getWidth()); }
URL url = StreamingRenderer.class.getResource("test-data/"); StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); ExternalGraphic eg = sf.createExternalGraphic(url + "icon64.png", "image/png"); legend.addExternalGraphic(eg); BufferedImage image = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
@Test public void testLegend() throws Exception { StyleFactory sf = CommonFactoryFinder.getStyleFactory(); FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(); PointSymbolizer p = sf.createPointSymbolizer(); Mark mark = sf.mark(ff.literal("circle"), sf.fill(null, ff.literal("#FF0000"), null), null); p.setGraphic(sf.createGraphic(null, new Mark[] {mark}, null, null, null, null)); Rule rule = sf.createRule(); rule.symbolizers().add(p); ExternalGraphic eg = sf.createExternalGraphic("smileyface.png", "image/png"); rule.setLegend(sf.createGraphic(new ExternalGraphic[] {eg}, null, null, null, null, null)); StringWriter out = new StringWriter(); Ysld.encode(sld(sf.createFeatureTypeStyle(new Rule[] {rule})), out); // System.out.append(out.toString()); YamlMap obj = new YamlMap(YamlUtil.getSafeYaml().load(out.toString())); YamlMap result = obj.seq("feature-styles") .map(0) .seq("rules") .map(0) .map("legend") .seq("symbols") .map(0) .map("external"); assertEquals("smileyface.png", result.str("url")); assertEquals("image/png", result.str("format")); }