You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by "Georg A." <at...@eva.mpg.de> on 2003/05/21 19:48:20 UTC

circle on top of existing file?

I am trying to draw a circle on top of a existing svg
  sample code below,
but it doesn't work, the map is rendered without the circle
what am i doing wrong?
thanks
Georg


#######sample code##########
try {
       String parser = XMLResourceDescriptor.getXMLParserClassName();
       SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
       svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
     svgCanvas.addSVGLoadEventDispatcherListener
     (new SVGLoadEventDispatcherAdapter() {
       public void svgLoadEventDispatchStarted
       (SVGLoadEventDispatcherEvent e) {
       }
     });
       String uri = "file:" + new 
File("/0_Samples/worldcollapsed_jc.svg").getAbsolutePath();
       doc = f.createDocument(uri);
       svg = doc.getDocumentElement();
       circle = doc.createElementNS(uri, "rect");
       circle.setAttributeNS(null, "cx", "600");
       circle.setAttributeNS(null, "cy", "200");
       circle.setAttributeNS(null, "r", "100");
       circle.setAttributeNS(null, "style", "fill: red; stroke: blue; 
stroke-width: 10");
       svg.appendChild(circle);
	   svgCanvas.setSVGDocument((org.w3c.dom.svg.SVGDocument)doc);// 
invokes the rendering
	} catch (Exception ex) {
       // ...
     }

-- 



Georg Apitz

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WALS Project
Executive Programmer

Max Planck Institute for Evolutionary Anthropology
Deutscher Platz 6
04103 Leipzig
Germany
Phone: +49 (0) 341 3550 - 314
Telefax: +49 (0)341 3550 - 333

georg@apitz.de
www.eva.mpg.de
www.ge-org.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org


RE: circle on top of existing file?

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "GA" == Georg A <at...@eva.mpg.de> writes:

GA> I am trying to draw a circle on top of a existing svg sample code
GA> below, but it doesn't work, the map is rendered without the circle
GA> what am i doing wrong?


       String uri = "file:" + 
          new File("/0_Samples/worldcollapsed_jc.svg").getAbsolutePath();
       doc = f.createDocument(uri);
       svg = doc.getDocumentElement();

       circle = doc.createElementNS(uri, "rect");

       This line is all wrong.  First if you want a circle the
element name is... 'circle' not 'rect'.

        Second the NameSpace is the SVG Namespace not the URI of
the document(?) 

        Your code will likely work better with the following lines:

import org.apache.batik.util.SVGConstants;

      circle = doc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, "circle");

       circle.setAttributeNS(null, "cx", "600");
       circle.setAttributeNS(null, "cy", "200");

GA> #######sample code########## try { String parser =
GA> XMLResourceDescriptor.getXMLParserClassName();
GA> SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
GA> svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
GA> svgCanvas.addSVGLoadEventDispatcherListener (new
GA> SVGLoadEventDispatcherAdapter() { public void
GA> svgLoadEventDispatchStarted (SVGLoadEventDispatcherEvent e) { }
GA> }); String uri = "file:" + new
GA> File("/0_Samples/worldcollapsed_jc.svg").getAbsolutePath(); doc =
GA> f.createDocument(uri); svg = doc.getDocumentElement(); circle =
GA> doc.createElementNS(uri, "rect"); circle.setAttributeNS(null,
GA> "cx", "600"); circle.setAttributeNS(null, "cy", "200");
GA> circle.setAttributeNS(null, "r", "100");
GA> circle.setAttributeNS(null, "style", "fill: red; stroke: blue;
GA> stroke-width: 10"); svg.appendChild(circle);
GA> svgCanvas.setSVGDocument((org.w3c.dom.svg.SVGDocument)doc);//
GA> invokes the rendering } catch (Exception ex) { // ...  }

GA> --



GA> Georg Apitz

GA> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WALS Project
GA> Executive Programmer

GA> Max Planck Institute for Evolutionary Anthropology Deutscher Platz
GA> 6 04103 Leipzig Germany Phone: +49 (0) 341 3550 - 314 Telefax: +49
GA> (0)341 3550 - 333

GA> georg@apitz.de www.eva.mpg.de www.ge-org.com
GA> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


GA> ---------------------------------------------------------------------
GA> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
GA> additional commands, e-mail: batik-users-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org