This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 53b6c18fc0 More complete implementation of `MapCanvas.clear()`. It 
resolves a problem of map upside-down when a `MapCanvas` is reused.
53b6c18fc0 is described below

commit 53b6c18fc08fa7ab939a3805a945243d382e12cb
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Wed Apr 8 12:17:45 2026 +0200

    More complete implementation of `MapCanvas.clear()`.
    It resolves a problem of map upside-down when a `MapCanvas` is reused.
---
 .../main/org/apache/sis/portrayal/Canvas.java      | 22 ++++++++++-
 .../org/apache/sis/portrayal/PlanarCanvas.java     | 20 ++++++++--
 .../apache/sis/gui/coverage/CoverageCanvas.java    | 18 ++++++++-
 .../main/org/apache/sis/gui/map/MapCanvas.java     | 44 +++++++++++-----------
 .../main/org/apache/sis/gui/map/MapCanvasAWT.java  |  3 +-
 .../main/org/apache/sis/gui/map/MultiCanvas.java   |  2 +-
 6 files changed, 79 insertions(+), 30 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/Canvas.java
 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/Canvas.java
index d0ab1fbd45..f81facfc8e 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/Canvas.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/Canvas.java
@@ -146,7 +146,7 @@ import 
org.opengis.coordinate.MismatchedCoordinateMetadataException;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.4
+ * @version 1.7
  * @since   1.1
  */
 public class Canvas extends Observable implements Localized {
@@ -411,6 +411,26 @@ public class Canvas extends Observable implements 
Localized {
         operationContext = new CanvasContext(locale);
     }
 
+    /**
+     * Resets this canvas to the same state as after construction, except 
listeners which are kept.
+     * This method can be invoked for discarding the content currently shown 
by the canvas,
+     * while keeping this {@code Canvas} instance for showing new content 
later.
+     *
+     * @since 1.7
+     */
+    protected void clear() {
+        objectiveCRS           = null;
+        objectiveToDisplay     = null;
+        pointOfInterest        = null;
+        objectivePOI           = null;
+        multidimToObjective    = null;
+        augmentedObjectiveCRS  = null;
+        supplementalDimensions = 0;
+        axisTypes              = null;
+        gridGeometry           = null;
+        operationContext.setObjectiveToGeographic(null);
+    }
+
     /**
      * Returns the locale used for texts or for producing some error messages.
      * May be {@code null} if no locale has been specified, in which case
diff --git 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/PlanarCanvas.java
 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/PlanarCanvas.java
index 5842a823c8..ef7ea9a38b 100644
--- 
a/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/PlanarCanvas.java
+++ 
b/endorsed/src/org.apache.sis.portrayal/main/org/apache/sis/portrayal/PlanarCanvas.java
@@ -41,7 +41,7 @@ import 
org.apache.sis.referencing.internal.shared.AffineTransform2D;
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.3
+ * @version 1.7
  * @since   1.1
  */
 public abstract class PlanarCanvas extends Canvas {
@@ -72,6 +72,20 @@ public abstract class PlanarCanvas extends Canvas {
         objectiveToDisplay = new AffineTransform();
     }
 
+    /**
+     * Resets this canvas to the same state as after construction, except 
listeners which are kept.
+     * This method can be invoked for discarding the content currently shown 
by the canvas,
+     * while keeping this {@code PlanarCanvas} instance for showing new 
content later.
+     *
+     * @hidden because nothing new to said.
+     * @since 1.7
+     */
+    @Override
+    protected void clear() {
+        objectiveToDisplay.setToIdentity();
+        super.clear();
+    }
+
     /**
      * Returns the number of dimensions of the display device.
      */
@@ -106,8 +120,8 @@ public abstract class PlanarCanvas extends Canvas {
      * Returns the size and location of the display device. The unit of 
measurement is
      * {@link Units#PIXEL} and coordinate values are usually (but not 
necessarily) integers.
      *
-     * <p>This value may be {@code null} on newly created {@code Canvas}, 
before data are added and canvas
-     * is configured. It should not be {@code null} anymore once a {@code 
Canvas} is ready for displaying.</p>
+     * <p>This value may be {@code null} on newly created {@code 
PlanarCanvas}, before data are added and canvas
+     * is configured. It should not be {@code null} anymore once a {@code 
PlanarCanvas} is ready for displaying.</p>
      *
      * <p>The returned envelope is a copy:
      * display changes happening after this method invocation will not be 
reflected in the returned envelope.</p>
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java
 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java
index 73045b52f3..78dc98a0ef 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/coverage/CoverageCanvas.java
@@ -660,7 +660,10 @@ public class CoverageCanvas extends MapCanvasAWT {
             if (resource != null) resource.addListener  (TileReadEvent.class, 
tileReadListener);
         }
         if (resource == null && coverage == null) {
-            clearLater();
+            runAfterRendering(() -> {
+                clear();
+                requestRepaint();
+            });
         } else if (controls != null && controls.isAdjustingSlice) {
             runAfterRendering(() -> {
                 clearRenderedImage();
@@ -751,6 +754,7 @@ public class CoverageCanvas extends MapCanvasAWT {
                             requestRepaint();                   // Cause 
`Worker` class to be executed.
                         } catch (RuntimeException ex) {         // Mostly for 
`BackingStoreException`.
                             clear();
+                            requestRepaint();
                             ExceptionReporter.canNotUseResource(fixedPane, 
Exceptions.unwrap(ex));
                         }
                     });
@@ -1475,13 +1479,23 @@ public class CoverageCanvas extends MapCanvasAWT {
      * <p>Subclasses should override this method for cleaning their fields.
      * Implementations in subclasses shall invoke {@code super.clear()}.</p>
      *
-     * @see #clearLater()
+     * @hidden because nothing new to said.
      */
     @Override
     protected void clear() {
         if (TRACE) {
             trace("clear()");
         }
+        showTileReads(false);
+        isCoverageHidden = false;
+        isCoverageAdjusting = true;
+        try {
+            resourceProperty.set(null);
+            coverageProperty.set(null);
+            sliceExtentProperty.set(null);
+        } finally {
+            isCoverageAdjusting = false;
+        }
         setNewSource(null, null, null);
         super.clear();
     }
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
index 4e8fc1b150..c04841424c 100644
--- a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
+++ b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvas.java
@@ -686,9 +686,9 @@ public abstract class MapCanvas extends PlanarCanvas {
 
     /**
      * Resets the map view to its default zoom level and default position with 
no rotation.
-     * Contrarily to {@link #clearLater()}, this method does not remove the 
map content.
+     * Contrarily to {@link #clear()}, this method does not remove the map 
content.
      *
-     * @see #clearLater()
+     * @see #clear()
      */
     public void reset() {
         invalidObjectiveToDisplay = true;
@@ -1693,42 +1693,42 @@ public abstract class MapCanvas extends PlanarCanvas {
     }
 
     /**
-     * Removes map content and clears the properties of this canvas.
-     * This method should not be invoked directly by users.
-     * The public <abbr>API</abbr> is {@link #clearLater()}.
+     * Removes the content shown by this canvas while keeping the listeners.
+     * This method is invoked for discarding the content currently shown by 
the canvas,
+     * while keeping this {@code MapCanvas} instance for showing new content 
later.
+     * Invoking this method may help to release memory when the map is no 
longer shown.
      *
      * <p>Subclasses should override this method for cleaning their fields.
      * Implementations in subclasses shall invoke {@code super.clear()}.</p>
      *
-     * @see #clearLater()
+     * <p>This method should usually not be invoked directly.
+     * Instead, a recommended usage pattern is as below.
+     * The call to {@link #requestRepaint()} can be omitted if this {@code 
MapCanvas}
+     * is removed from the tree of nodes shown by JavaFX.</p>
+     *
+     * {@snippet lang="java" :
+     *     runAfterRendering(() -> {
+     *         clear();
+     *         requestRepaint();
+     *     });
+     *     }
+     *
      * @see #reset()
+     * @see #runAfterRendering(Runnable)
      */
+    @Override
     protected void clear() {
         assert Platform.isFxApplicationThread();
         transform.setToIdentity();
         invalidObjectiveToDisplay = true;
+        objectiveBounds = null;
         initialState = null;
         clearError();
         isDragging = false;
         isNavigationDisabled = false;
         positionalAccuracy.set(null);
         isRendering.set(false);
-        requestRepaint();
-    }
-
-    /**
-     * Removes map content and clears the properties of this canvas.
-     * Invoking this method may help to release memory when the map is no 
longer shown.
-     * The effect of the cleanup action may not be immediate, but may happen 
an arbitrary
-     * time after this method call.
-     *
-     * <p>For overriding this method in subclasses, see {@link #clear()}.</p>
-     *
-     * @see #reset()
-     * @since 1.7
-     */
-    public final void clearLater() {
-        runAfterRendering(this::clear);
+        super.clear();
     }
 
     /**
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvasAWT.java 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvasAWT.java
index 72ca3a19b9..7173e40f2e 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvasAWT.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MapCanvasAWT.java
@@ -663,11 +663,12 @@ public abstract class MapCanvasAWT extends MapCanvas {
      * <p>Subclasses should override this method for cleaning their fields.
      * Implementations in subclasses shall invoke {@code super.clear()}.</p>
      *
-     * @see #clearLater()
+     * @hidden
      */
     @Override
     protected void clear() {
         image.setImage(null);
+        clearWarning();
         clearBuffer();
         super.clear();
     }
diff --git 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MultiCanvas.java 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MultiCanvas.java
index 70026ff3a6..924c229236 100644
--- 
a/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MultiCanvas.java
+++ 
b/optional/src/org.apache.sis.gui/main/org/apache/sis/gui/map/MultiCanvas.java
@@ -691,7 +691,7 @@ final class MultiCanvas extends Widget implements 
Observable {
         if (resource != null) {
             resource.removeListener(CloseEvent.class, closer);
         }
-        canvas.clearLater();
+        canvas.runAfterRendering(canvas::clear);
         controls.clear();
     }
 

Reply via email to