tillnagel / unfolding

A library to create interactive maps and geovisualizations in Processing and Java
http://unfoldingmaps.org
Other
478 stars 244 forks source link

Cannot draw atop maps in JAVA2D since Processing 3 beta 6 #118

Open tillnagel opened 9 years ago

tillnagel commented 9 years ago

Java2DMapDisplay uses papplet.g as canvas directly, and thus beginDraw() in mapDisplay.draw() messes up things.

Solution: Either add new method preDraw() and only call beginDraw for OpenGLMapDisplay (and keep it empty in Java2DMapDisplay), or use an offscreen buffer in Java2D too (which might fix #117, too).

tillnagel commented 7 years ago

Work-around: Switch to P2D, e.g. use

size(800,800, P2D);

r-hmn commented 5 years ago

I Updated the Java2DMapDisplay.java, and now the examples work in my environment.(JDK1.8, JAVA2D, unfolding0.9.9beta )

I did have to change the examples a bit;

Next the patch difference (used WinMerge):

--- de\fhpotsdam\unfolding\mapdisplay\Java2DMapDisplay.java Fri Sep 27 09:47:43 2019
+++ unfolding/releases/0.9.9beta/fixes/Java2DMapDisplay.java    Fri Sep 27 09:45:17 2019
@@ -33,6 +33,9 @@
    // Used for loadImage and float maths
    public PApplet papplet;

+   // Double buffer created from papplet's PGraphics
+   private PGraphics innerPg;
+
    /** The inner transformation matrix. Scales and rotates the map. */
    protected PMatrix3D innerMatrix = new PMatrix3D();

@@ -61,6 +64,8 @@
        super(provider, width, height);
        this.papplet = papplet;

+       this.innerPg = papplet.createGraphics((int)width, (int)height, JAVA2D);
+
        this.offsetX = offsetX;
        this.offsetY = offsetY;

@@ -323,12 +328,12 @@
    // DRAWING --------------------------------------------------

    public PGraphics getInnerPG() {
-       // NB Always inner graphics, this one not used. Implemented in sub classes.
-       return papplet.g;
+       // Return the PGraphics object which is used during draw() to image() onto the main PGraphics
+       return innerPg;
    }

    public PGraphics getOuterPG() {
-       return papplet.g;
+       return innerPg;
    }

    /**
@@ -401,11 +406,16 @@
        }

        pg.popMatrix();
-       pg.endDraw();

+       // Ensure Markers are drawn before endDraw
        postDraw();

+       pg.endDraw();
+
+       papplet.image( getInnerPG(), offsetX, offsetY);
+
        cleanupImageBuffer();
+
    }

    /**
tillnagel commented 4 years ago

Thanks for the suggestion @r-hmn. Alas, with that change and using P2D/P3D renderer, markers are not visible, and non-markers (i.e. objects drawn atop the map directly) are not at their correct positions when using an offset.

r-hmn commented 4 years ago

Thanks @tillnagel interesting.. i must have missed the non-markers examples failing.

Since September i've changed to using jxmapviewer2 as the basis for my development because the "processing" paint-loop was too massive to incorporate. But it was nice to experience unfolding & processing! Cheers