From 3c500e0b4b958b3163d9f9f42b1c63119a2b9999 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Sat, 8 Sep 2018 11:10:56 +0200 Subject: [PATCH] Sensible touch behavior of the MousePosition control --- src/ol/control/MousePosition.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ol/control/MousePosition.js b/src/ol/control/MousePosition.js index 4b42d87d22..23c77387f1 100644 --- a/src/ol/control/MousePosition.js +++ b/src/ol/control/MousePosition.js @@ -44,6 +44,9 @@ const COORDINATE_FORMAT = 'coordinateFormat'; * By default the control is shown in the top right corner of the map, but this * can be changed by using the css selector `.ol-mouse-position`. * + * On touch devices, which usually do not have a mouse cursor, the coordinates + * of the currently touched position are shown. + * * @api */ class MousePosition extends Control { @@ -175,11 +178,13 @@ class MousePosition extends Control { if (map) { const viewport = map.getViewport(); this.listenerKeys.push( - listen(viewport, EventType.MOUSEMOVE, this.handleMouseMove, this) + listen(viewport, EventType.MOUSEMOVE, this.handleMouseMove, this), + listen(viewport, EventType.TOUCHSTART, this.handleMouseMove, this) ); if (this.renderOnMouseOut_) { this.listenerKeys.push( - listen(viewport, EventType.MOUSEOUT, this.handleMouseOut, this) + listen(viewport, EventType.MOUSEOUT, this.handleMouseOut, this), + listen(viewport, EventType.TOUCHEND, this.handleMouseOut, this) ); } } @@ -244,7 +249,8 @@ class MousePosition extends Control { /** - * Update the mouseposition element. + * Update the projection. Rendering of the coordinates is done in + * `handleMouseMove` and `handleMouseUp`. * @param {import("../MapEvent.js").default} mapEvent Map event. * @this {MousePosition} * @api @@ -259,7 +265,6 @@ export function render(mapEvent) { this.transform_ = null; } } - this.updateHTML_(this.lastMouseMovePixel_); }