Always dispatch pointermove, but calculate coordinates lazily

This commit is contained in:
Andreas Hocevar
2019-09-23 14:04:37 +02:00
parent 3992aede9d
commit a139b01f8e
2 changed files with 35 additions and 9 deletions

View File

@@ -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.

View File

@@ -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));
}
/**