Always dispatch pointermove, but calculate coordinates lazily
This commit is contained in:
@@ -32,16 +32,14 @@ class MapBrowserEvent extends MapEvent {
|
|||||||
/**
|
/**
|
||||||
* The map pixel relative to the viewport corresponding to the original browser event.
|
* The map pixel relative to the viewport corresponding to the original browser event.
|
||||||
* @type {import("./pixel.js").Pixel}
|
* @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.
|
* The coordinate in view projection corresponding to the original browser event.
|
||||||
* @type {import("./coordinate.js").Coordinate}
|
* @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
|
* 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.
|
* Prevents the default browser action.
|
||||||
* See https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault.
|
* See https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault.
|
||||||
|
|||||||
@@ -247,11 +247,9 @@ class MapBrowserEventHandler extends EventTarget {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
relayEvent_(pointerEvent) {
|
relayEvent_(pointerEvent) {
|
||||||
if (this.map_.hasListener(pointerEvent.type)) {
|
const dragging = !!(this.down_ && this.isMoving_(pointerEvent));
|
||||||
const dragging = !!(this.down_ && this.isMoving_(pointerEvent));
|
this.dispatchEvent(new MapBrowserPointerEvent(
|
||||||
this.dispatchEvent(new MapBrowserPointerEvent(
|
pointerEvent.type, this.map_, pointerEvent, dragging));
|
||||||
pointerEvent.type, this.map_, pointerEvent, dragging));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user