From 180e1c86fc279462d13d7ac19d555697450ecd75 Mon Sep 17 00:00:00 2001 From: flexJoly Date: Thu, 26 Sep 2019 18:22:06 +0200 Subject: [PATCH 1/2] Cache starting coordinates and add mapBrowserEvent to translateEvent --- src/ol/interaction/Translate.js | 39 +++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index d6125664b1..3a6e8996d2 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -71,7 +71,7 @@ export class TranslateEvent extends Event { * @param {Collection} features The features translated. * @param {import("../coordinate.js").Coordinate} coordinate The event coordinate. */ - constructor(type, features, coordinate) { + constructor(type, features,startCoordinate, coordinate,mapBrowserEvent) { super(type); @@ -90,6 +90,21 @@ export class TranslateEvent extends Event { */ 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; + /** + * The start position before translation started. + * @type {import("../coordinate.js").Coordinate} + * @private + */ + this.startCoordinate_ = null; + /** * @type {Collection} @@ -174,6 +196,7 @@ class Translate extends PointerInteraction { handleDownEvent(event) { this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map); if (!this.lastCoordinate_ && this.lastFeature_) { + this.startCoordinate_ = this.lastCoordinate_ = event.coordinate; this.handleMoveEvent(event); @@ -181,8 +204,8 @@ class Translate extends PointerInteraction { this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATESTART, features, - event.coordinate)); + TranslateEventType.TRANSLATESTART, features, this.startCoordinate_, + event.coordinate, event)); return true; } return false; @@ -200,8 +223,10 @@ class Translate extends PointerInteraction { this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATEEND, features, - event.coordinate)); + TranslateEventType.TRANSLATEEND, features,this.startCoordinate_, + event.coordinate, event)); + // cleanup + this.startCoordinate_ = null; return true; } return false; @@ -227,8 +252,8 @@ class Translate extends PointerInteraction { this.lastCoordinate_ = newCoordinate; this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATING, features, - newCoordinate)); + TranslateEventType.TRANSLATING, features,this.startCoordinate_, + newCoordinate,event)); } } From 391bae35f2543eba1019a3fcb517225cb5104bb7 Mon Sep 17 00:00:00 2001 From: flexJoly Date: Thu, 26 Sep 2019 19:30:24 +0200 Subject: [PATCH 2/2] minor fixes and keep original parameters in TranslateEvent the same --- src/ol/interaction/Translate.js | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ol/interaction/Translate.js b/src/ol/interaction/Translate.js index 3a6e8996d2..3c4330d1aa 100644 --- a/src/ol/interaction/Translate.js +++ b/src/ol/interaction/Translate.js @@ -70,8 +70,10 @@ export class TranslateEvent extends Event { * @param {TranslateEventType} type Type. * @param {Collection} features The features translated. * @param {import("../coordinate.js").Coordinate} coordinate The event coordinate. + * @param {import("../coordinate.js").Coordinate} startCoordinate The original coordinates before.translation started + * @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event. */ - constructor(type, features,startCoordinate, coordinate,mapBrowserEvent) { + constructor(type, features, coordinate, startCoordinate, mapBrowserEvent) { super(type); @@ -90,7 +92,7 @@ export class TranslateEvent extends Event { */ this.coordinate = coordinate; - /** + /** * The coordinate of the start position before translation started. * @const * @type {import("../coordinate.js").Coordinate} @@ -196,7 +198,7 @@ class Translate extends PointerInteraction { handleDownEvent(event) { this.lastFeature_ = this.featuresAtPixel_(event.pixel, event.map); if (!this.lastCoordinate_ && this.lastFeature_) { - this.startCoordinate_ = + this.startCoordinate_ = this.lastCoordinate_ = event.coordinate; this.handleMoveEvent(event); @@ -204,8 +206,8 @@ class Translate extends PointerInteraction { this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATESTART, features, this.startCoordinate_, - event.coordinate, event)); + TranslateEventType.TRANSLATESTART, features, + event.coordinate, this.startCoordinate_, event)); return true; } return false; @@ -223,9 +225,9 @@ class Translate extends PointerInteraction { this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATEEND, features,this.startCoordinate_, - event.coordinate, event)); - // cleanup + TranslateEventType.TRANSLATEEND, features, + event.coordinate, this.startCoordinate_, event)); + // cleanup this.startCoordinate_ = null; return true; } @@ -252,8 +254,8 @@ class Translate extends PointerInteraction { this.lastCoordinate_ = newCoordinate; this.dispatchEvent( new TranslateEvent( - TranslateEventType.TRANSLATING, features,this.startCoordinate_, - newCoordinate,event)); + TranslateEventType.TRANSLATING, features, + newCoordinate, this.startCoordinate_, event)); } }