xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jacob Christophersen <jacob.christopher...@gmail.com>
Subject Pan and Zooms being clipped.
Date Tue, 06 Apr 2010 10:54:55 GMT

I've been experimenting with Batik as a possible option for a project I need
to do.

I need to implement a pan/zoom style similar to google maps.

I'm struggling with the issue that when ever I try to pan or zoom out, the
parts of the SVG that were not visible before the interactor started, are
not shown again until I release the mouse.

I've done a bit of searching around, and the consensus seems to be to set
the overflow property of the SVG root element to visible, but that doesn't
seem to have changed anything.

I've made an example (pasted below), where a rectangle is created with x,y =
(-10,-10). The top left of the rectangle is clipped at first, and while
panning and zooming it remains clipped until I release the mouse.
(Panning/Zooming using Shift + left/right mouse button).




import javax.swing.JFrame;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Application extends JFrame {
    private JSVGCanvas canvas;

    public Application(){
        setSize(400, 400);

    private void initComponents(){
        canvas = new JSVGCanvas();

    private Document createSVG(){
        DOMImplementation impl =
        final String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        final Document doc = impl.createDocument(svgNS, "svg", null);

        Element svgRoot = doc.getDocumentElement();
        svgRoot.setAttributeNS(null, "overflow", "visible");
        svgRoot.setAttributeNS(null, "width", "400");
        svgRoot.setAttributeNS(null, "height", "400");

        Element rectangle = doc.createElementNS(svgNS, "rect");
        rectangle.setAttributeNS(null, "x", "-10");
        rectangle.setAttributeNS(null, "y", "-10");
        rectangle.setAttributeNS(null, "width", "200");
        rectangle.setAttributeNS(null, "height", "200");
        rectangle.setAttribute("style", "fill:red");

        return doc;

    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Application().setVisible(true);

View raw message