diff --git a/src/ol/MapBrowserEvent.js b/src/ol/MapBrowserEvent.js index 074132afc8..9919d08516 100644 --- a/src/ol/MapBrowserEvent.js +++ b/src/ol/MapBrowserEvent.js @@ -32,16 +32,14 @@ class MapBrowserEvent extends MapEvent { /** * The map pixel relative to the viewport corresponding to the original browser event. * @type {import("./pixel.js").Pixel} - * @api */ - this.pixel = map.getEventPixel(browserEvent); + this.pixel_ = null; /** * The coordinate in view projection corresponding to the original browser event. * @type {import("./coordinate.js").Coordinate} - * @api */ - this.coordinate = map.getCoordinateFromPixel(this.pixel); + this.coordinate_ = null; /** * Indicates if the map is currently being dragged. Only set for @@ -54,6 +52,36 @@ class MapBrowserEvent extends MapEvent { } + /** + * The map pixel relative to the viewport corresponding to the original browser event. + * @type {import("./pixel.js").Pixel} + * @api + */ + get pixel() { + if (!this.pixel_) { + this.pixel_ = this.map.getEventPixel(this.originalEvent); + } + return this.pixel_; + } + set pixel(pixel) { + this.pixel_ = pixel; + } + + /** + * The coordinate in view projection corresponding to the original browser event. + * @type {import("./coordinate.js").Coordinate} + * @api + */ + get coordinate() { + if (!this.coordinate_) { + this.coordinate_ = this.map.getCoordinateFromPixel(this.pixel); + } + return this.coordinate_; + } + set coordinate(coordinate) { + this.coordinate_ = coordinate; + } + /** * Prevents the default browser action. * See https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault. diff --git a/src/ol/MapBrowserEventHandler.js b/src/ol/MapBrowserEventHandler.js index 6498ab1827..2715ae8548 100644 --- a/src/ol/MapBrowserEventHandler.js +++ b/src/ol/MapBrowserEventHandler.js @@ -247,11 +247,9 @@ class MapBrowserEventHandler extends EventTarget { * @private */ relayEvent_(pointerEvent) { - if (this.map_.hasListener(pointerEvent.type)) { - const dragging = !!(this.down_ && this.isMoving_(pointerEvent)); - this.dispatchEvent(new MapBrowserPointerEvent( - pointerEvent.type, this.map_, pointerEvent, dragging)); - } + const dragging = !!(this.down_ && this.isMoving_(pointerEvent)); + this.dispatchEvent(new MapBrowserPointerEvent( + pointerEvent.type, this.map_, pointerEvent, dragging)); } /**