Cache starting coordinates and add mapBrowserEvent to translateEvent
This commit is contained in:
@@ -71,7 +71,7 @@ export class TranslateEvent extends Event {
|
|||||||
* @param {Collection<import("../Feature.js").default>} features The features translated.
|
* @param {Collection<import("../Feature.js").default>} features The features translated.
|
||||||
* @param {import("../coordinate.js").Coordinate} coordinate The event coordinate.
|
* @param {import("../coordinate.js").Coordinate} coordinate The event coordinate.
|
||||||
*/
|
*/
|
||||||
constructor(type, features, coordinate) {
|
constructor(type, features,startCoordinate, coordinate,mapBrowserEvent) {
|
||||||
|
|
||||||
super(type);
|
super(type);
|
||||||
|
|
||||||
@@ -90,6 +90,21 @@ export class TranslateEvent extends Event {
|
|||||||
*/
|
*/
|
||||||
this.coordinate = coordinate;
|
this.coordinate = coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The coordinate of the start position before translation started.
|
||||||
|
* @const
|
||||||
|
* @type {import("../coordinate.js").Coordinate}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
this.startCoordinate = startCoordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Associated {@link module:ol/MapBrowserEvent}.
|
||||||
|
* @type {import("../MapBrowserEvent.js").default}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
this.mapBrowserEvent = mapBrowserEvent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -118,6 +133,13 @@ class Translate extends PointerInteraction {
|
|||||||
*/
|
*/
|
||||||
this.lastCoordinate_ = null;
|
this.lastCoordinate_ = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The start position before translation started.
|
||||||
|
* @type {import("../coordinate.js").Coordinate}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.startCoordinate_ = null;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Collection<import("../Feature.js").default>}
|
* @type {Collection<import("../Feature.js").default>}
|
||||||
@@ -174,6 +196,7 @@ class Translate extends PointerInteraction {
|
|||||||
handleDownEvent(event) {
|
handleDownEvent(event) {
|
||||||
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
|
this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map);
|
||||||
if (!this.lastCoordinate_ && this.lastFeature_) {
|
if (!this.lastCoordinate_ && this.lastFeature_) {
|
||||||
|
this.startCoordinate_ =
|
||||||
this.lastCoordinate_ = event.coordinate;
|
this.lastCoordinate_ = event.coordinate;
|
||||||
this.handleMoveEvent(event);
|
this.handleMoveEvent(event);
|
||||||
|
|
||||||
@@ -181,8 +204,8 @@ class Translate extends PointerInteraction {
|
|||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new TranslateEvent(
|
new TranslateEvent(
|
||||||
TranslateEventType.TRANSLATESTART, features,
|
TranslateEventType.TRANSLATESTART, features, this.startCoordinate_,
|
||||||
event.coordinate));
|
event.coordinate, event));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -200,8 +223,10 @@ class Translate extends PointerInteraction {
|
|||||||
|
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new TranslateEvent(
|
new TranslateEvent(
|
||||||
TranslateEventType.TRANSLATEEND, features,
|
TranslateEventType.TRANSLATEEND, features,this.startCoordinate_,
|
||||||
event.coordinate));
|
event.coordinate, event));
|
||||||
|
// cleanup
|
||||||
|
this.startCoordinate_ = null;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -227,8 +252,8 @@ class Translate extends PointerInteraction {
|
|||||||
this.lastCoordinate_ = newCoordinate;
|
this.lastCoordinate_ = newCoordinate;
|
||||||
this.dispatchEvent(
|
this.dispatchEvent(
|
||||||
new TranslateEvent(
|
new TranslateEvent(
|
||||||
TranslateEventType.TRANSLATING, features,
|
TranslateEventType.TRANSLATING, features,this.startCoordinate_,
|
||||||
newCoordinate));
|
newCoordinate,event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user