This is an automated email from the ASF dual-hosted git repository. asf-gitbox-commits pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 64af795f406aa622990014066866c5c2ff252f44 Author: Martin Desruisseaux <[email protected]> AuthorDate: Thu Aug 6 00:11:53 2026 +0200 Fix unintentional crop when showing a large non-pyramided image with an initial zoom for avoiding to load the full image. --- .../apache/sis/gui/coverage/CoverageCanvas.java | 44 ++++++++++++++-------- .../main/org/apache/sis/gui/map/MapCanvas.java | 4 +- 2 files changed, 31 insertions(+), 17 deletions(-) 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 b99963769e..6ac0127c15 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 @@ -221,7 +221,8 @@ public class CoverageCanvas extends MapCanvasAWT { /** * A subspace of the grid coverage extent where all dimensions except two have a size of 1 cell. - * May be {@code null} if the grid coverage has only two dimensions with a size greater than 1 cell. + * The property value may be {@code null} if the grid coverage has only two dimensions with a size + * greater than 1 cell, in which case it is unnecessary to specify a slice. * * @see #getSliceExtent() * @see #setSliceExtent(GridExtent) @@ -699,6 +700,9 @@ public class CoverageCanvas extends MapCanvasAWT { /** Information about all bands. */ private List<SampleDimension> ranges; + /** Initial region to show, used only if the image is too large. */ + private GridGeometry initialArea; + /** * Fetches coverage domain and range. In some {@link GridCoverageResource} implementations, * fetching the grid geometry is a costly operation. So we do it in a background thread and @@ -737,7 +741,9 @@ public class CoverageCanvas extends MapCanvasAWT { * loading of a large amount of data. We are better to limit the zoom to * a small area. */ - if (domain.isDefined(GridGeometry.ENVELOPE | GridGeometry.RESOLUTION)) { + if (visibleArea != null) { + initialArea = visibleArea; + } else if (domain.isDefined(GridGeometry.ENVELOPE | GridGeometry.RESOLUTION)) { if (scales == null) { scales = domain.getResolution(true); } @@ -755,8 +761,7 @@ public class CoverageCanvas extends MapCanvasAWT { final double margin = zoomArea.getSpan(i) * out; zoomArea.setRange(i, zoomArea.getLower(i) + margin, zoomArea.getUpper(i) - margin); } - // Pretend that the data domain is smaller than reality. - domain = domain.derive().subgrid(zoomArea, null).build(); + initialArea = new GridGeometry(zoomArea); } } } @@ -775,7 +780,7 @@ public class CoverageCanvas extends MapCanvasAWT { @Override protected void succeeded() { runAfterRendering(() -> { try { - setNewSource(gridCrsName, getValue(), ranges, visibleArea); + setNewSource(gridCrsName, getValue(), ranges, initialArea, visibleArea == null); requestRepaint(); // Cause `Worker` class to be executed. } catch (RuntimeException ex) { // Mostly for `BackingStoreException`. clear(); @@ -825,20 +830,26 @@ public class CoverageCanvas extends MapCanvasAWT { * * <p>The {@code visibleArea} argument is used when we want to create a new canvas * initialized to the same viewing region and zoom level than an existing canvas. - * It should have a <abbr>CRS</abbr> compatible with the one of the data to show.</p> + * It should have a <abbr>CRS</abbr> compatible with the one of the data to show. + * In such case, {@code visibleArea} is already two-dimensional and therefore + * {@code reduceAreaDim} should be {@code false}.</p> + * + * <p>Alternatively, {@code visibleArea} can also be an initial zoom for avoiding to show the full image. + * Such initial zoom is usually derived from {@code domain}, which may have more than two dimensions. + * In such case, {@code reduceAreaDim} should be {@code true}.</p> * * <p>All arguments can be {@code null} for clearing the canvas. * This method is invoked in JavaFX thread.</p> * - * @param gridCrsName name of the grid <abbr>CRS</abbr>, derived from the resource identifier. - * @param domain the multi-dimensional grid geometry, or {@code null} if there is no data. - * @param ranges descriptions of bands, or {@code null} if there is no data. - * @param visibleArea initial "objective to display" transform to use, or {@code null} for automatic. + * @param gridCrsName name of the grid <abbr>CRS</abbr>, derived from the resource identifier. + * @param domain the multi-dimensional grid geometry, or {@code null} if there is no data. + * @param ranges descriptions of bands, or {@code null} if there is no data. + * @param visibleArea initial "objective to display" transform to use, or {@code null} for automatic. + * @param reduceAreaDim whether the number of dimensions of {@code visibleArea} may need to be reduced. */ - private void setNewSource(final Identifier gridCrsName, - GridGeometry domain, - final List<SampleDimension> ranges, - final GridGeometry visibleArea) + private void setNewSource(final Identifier gridCrsName, GridGeometry domain, + final List<SampleDimension> ranges, GridGeometry visibleArea, + final boolean reduceAreaDim) { if (TRACE) { trace("setNewSource(…): the new domain of data is:%n\t%s", domain); @@ -889,6 +900,9 @@ public class CoverageCanvas extends MapCanvasAWT { } } } + if (visibleArea != null && reduceAreaDim) { + visibleArea = visibleArea.selectDimensions(xyDimensions); + } data.gridCrsName = gridCrsName; data.setImageSpace(domain, ranges, xyDimensions); initialize(visibleArea); @@ -1504,7 +1518,7 @@ public class CoverageCanvas extends MapCanvasAWT { } finally { isCoverageAdjusting = false; } - setNewSource(null, null, null, null); + setNewSource(null, null, null, null, false); 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 7f1074100d..590588ff35 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 @@ -407,7 +407,7 @@ public abstract class MapCanvas extends PlanarCanvas { * {@linkplain #setObjectiveCRS(CoordinateReferenceSystem, DirectPosition) objective CRS} of this canvas. * The {@code visibleArea} {@linkplain GridGeometry#getEnvelope() envelope} defines the (usually constant) * {@linkplain #setObjectiveBounds(Envelope) objective bounds} of this canvas. - * In addition if {@code visibleArea} contains a {@linkplain GridGeometry#getGridToCRS grid to CRS} transform, + * In addition, if {@code visibleArea} contains a {@linkplain GridGeometry#getGridToCRS grid to CRS} transform, * its inverse will define the initial {@linkplain #setObjectiveToDisplay objective to display} transform * (which in turn defines the initial viewed area and zoom level). * @@ -416,7 +416,7 @@ public abstract class MapCanvas extends PlanarCanvas { * cause new repaint event; {@link #requestRepaint()} must be invoked by the caller if desired.</p> * * @param visibleArea bounding box, objective <abbr>CRS</abbr> and or initial zoom level, - * or {@code null} if unknown (in which case an identity transform will be set). + * or {@code null} for a default transform showing fully the map. * @throws MismatchedDimensionException if the given grid geometry is not two-dimensional. * * @see #setObjectiveBounds(Envelope)
