From commits-return-13464-apmail-sis-commits-archive=sis.apache.org@sis.apache.org Sun Apr 12 09:46:30 2020 Return-Path: X-Original-To: apmail-sis-commits-archive@www.apache.org Delivered-To: apmail-sis-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id 5499B192A7 for ; Sun, 12 Apr 2020 09:46:30 +0000 (UTC) Received: (qmail 30466 invoked by uid 500); 12 Apr 2020 09:46:29 -0000 Delivered-To: apmail-sis-commits-archive@sis.apache.org Received: (qmail 30444 invoked by uid 500); 12 Apr 2020 09:46:29 -0000 Mailing-List: contact commits-help@sis.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sis-dev@sis.apache.org Delivered-To: mailing list commits@sis.apache.org Received: (qmail 30435 invoked by uid 99); 12 Apr 2020 09:46:29 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Apr 2020 09:46:29 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id A11A08B6AA; Sun, 12 Apr 2020 09:46:28 +0000 (UTC) Date: Sun, 12 Apr 2020 09:46:28 +0000 To: "commits@sis.apache.org" Subject: [sis] branch geoapi-4.0 updated: Fix wrong position when performing pan or zooms with keyboard while the map is rendering in background thread. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <158668478860.18251.5609785987774014442@gitbox.apache.org> From: desruisseaux@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: sis X-Git-Refname: refs/heads/geoapi-4.0 X-Git-Reftype: branch X-Git-Oldrev: f2f577180863a162b48bdc9563e1a80f80ce2d84 X-Git-Newrev: e51cfe55ed10ef2ecf65c5788d771bbe384bf6ac X-Git-Rev: e51cfe55ed10ef2ecf65c5788d771bbe384bf6ac X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 e51cfe5 Fix wrong position when performing pan or zooms with keyboard while the map is rendering in background thread. e51cfe5 is described below commit e51cfe55ed10ef2ecf65c5788d771bbe384bf6ac Author: Martin Desruisseaux AuthorDate: Sun Apr 12 11:44:37 2020 +0200 Fix wrong position when performing pan or zooms with keyboard while the map is rendering in background thread. --- .../java/org/apache/sis/gui/map/MapCanvas.java | 39 ++++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java index 8bcb84b..630d91b 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java @@ -22,8 +22,6 @@ import javafx.geometry.Bounds; import javafx.geometry.Point2D; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; -import javafx.scene.shape.Rectangle; -import javafx.scene.transform.Affine; import javafx.scene.input.KeyEvent; import javafx.scene.input.ZoomEvent; import javafx.scene.input.RotateEvent; @@ -34,6 +32,9 @@ import javafx.scene.Cursor; import javafx.event.EventType; import javafx.beans.Observable; import javafx.concurrent.Task; +import javafx.scene.shape.Rectangle; +import javafx.scene.transform.Affine; +import javafx.scene.transform.NonInvertibleTransformException; import org.opengis.geometry.Envelope; import org.apache.sis.referencing.operation.matrix.Matrices; import org.apache.sis.referencing.operation.matrix.MatrixSIS; @@ -42,11 +43,13 @@ import org.apache.sis.referencing.operation.transform.LinearTransform; import org.apache.sis.geometry.Envelope2D; import org.apache.sis.geometry.ImmutableEnvelope; import org.apache.sis.util.ArgumentChecks; +import org.apache.sis.util.logging.Logging; import org.apache.sis.internal.util.Numerics; import org.apache.sis.internal.gui.BackgroundThreads; import org.apache.sis.internal.gui.ExceptionReporter; import org.apache.sis.internal.map.PlanarCanvas; import org.apache.sis.internal.map.RenderException; +import org.apache.sis.internal.system.Modules; /** @@ -358,7 +361,7 @@ public abstract class MapCanvas extends PlanarCanvas { */ private void applyZoomOrRotate(final GestureEvent event, final double zoom, final double angle) { if (zoom != 1 || angle != 0) { - final double x, y; + double x, y; if (event != null) { x = event.getX(); y = event.getY(); @@ -366,6 +369,18 @@ public abstract class MapCanvas extends PlanarCanvas { final Bounds bounds = floatingPane.getLayoutBounds(); x = bounds.getCenterX(); y = bounds.getCenterY(); + try { + final Point2D p = transform.inverseTransform(x, y); + x = p.getX(); + y = p.getY(); + } catch (NonInvertibleTransformException e) { + /* + * `event` is null only when this method is invoked from `onKeyTyped(…)`. + * Keep old coordinates. The map may appear shifted, but its location will + * be fixed when `repaint()` completes its work. + */ + unexpectedException("onKeyTyped", e); + } } final Point2D p = changeInProgress.transform(x, y); if (zoom != 1) { @@ -413,6 +428,17 @@ public abstract class MapCanvas extends PlanarCanvas { angle /= CONTROL_KEY_FACTOR; zoom = (zoom - 1) / CONTROL_KEY_FACTOR + 1; } + try { + final Point2D p = transform.inverseDeltaTransform(tx, ty); + tx = p.getX(); + ty = p.getY(); + } catch (NonInvertibleTransformException e) { + /* + * Should never happen. If happen anyway, keep old coordinates. The map may appear + * shifted, but its location will be fixed when `repaint()` completes its work. + */ + unexpectedException("onKeyTyped", e); + } applyZoomOrRotate(null, zoom, angle); applyTranslation(tx, ty, false); event.consume(); @@ -766,6 +792,13 @@ public abstract class MapCanvas extends PlanarCanvas { } /** + * Invoked when an unexpected exception occurred but it is okay to continue despite it. + */ + private static void unexpectedException(final String method, final NonInvertibleTransformException e) { + Logging.unexpectedException(Logging.getLogger(Modules.APPLICATION), MapCanvas.class, method, e); + } + + /** * Clears the map. * Invoking this method may help to release memory when the map is no longer shown. *