Merge pull request #4161 from jonataswalker/translate-events
Add `translatestart`, `translateend` and `translating` events to `ol.interaction.Translate`
This commit is contained in:
@@ -1,9 +1,72 @@
|
||||
goog.provide('ol.interaction.Translate');
|
||||
goog.provide('ol.interaction.TranslateEvent');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.Event');
|
||||
goog.require('ol.array');
|
||||
goog.require('ol.interaction.Pointer');
|
||||
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
ol.interaction.TranslateEventType = {
|
||||
/**
|
||||
* Triggered upon feature translation start.
|
||||
* @event ol.interaction.TranslateEvent#translatestart
|
||||
* @api
|
||||
*/
|
||||
TRANSLATESTART: 'translatestart',
|
||||
/**
|
||||
* Triggered upon feature translation.
|
||||
* @event ol.interaction.TranslateEvent#translating
|
||||
* @api
|
||||
*/
|
||||
TRANSLATING: 'translating',
|
||||
/**
|
||||
* Triggered upon feature translation end.
|
||||
* @event ol.interaction.TranslateEvent#translateend
|
||||
* @api
|
||||
*/
|
||||
TRANSLATEEND: 'translateend'
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Events emitted by {@link ol.interaction.Translate} instances are instances of
|
||||
* this type.
|
||||
*
|
||||
* @constructor
|
||||
* @extends {goog.events.Event}
|
||||
* @implements {oli.interaction.TranslateEvent}
|
||||
* @param {ol.interaction.TranslateEventType} type Type.
|
||||
* @param {ol.Collection.<ol.Feature>} features The features translated.
|
||||
* @param {ol.Coordinate} coordinate The event coordinate.
|
||||
*/
|
||||
ol.interaction.TranslateEvent = function(type, features, coordinate) {
|
||||
|
||||
goog.base(this, type);
|
||||
|
||||
/**
|
||||
* The features being translated.
|
||||
* @type {ol.Collection.<ol.Feature>}
|
||||
* @api
|
||||
*/
|
||||
this.features = features;
|
||||
|
||||
/**
|
||||
* The coordinate of the drag event.
|
||||
* @const
|
||||
* @type {ol.Coordinate}
|
||||
* @api
|
||||
*/
|
||||
this.coordinate = coordinate;
|
||||
};
|
||||
goog.inherits(ol.interaction.TranslateEvent, goog.events.Event);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
@@ -11,6 +74,7 @@ goog.require('ol.interaction.Pointer');
|
||||
*
|
||||
* @constructor
|
||||
* @extends {ol.interaction.Pointer}
|
||||
* @fires ol.interaction.TranslateEvent
|
||||
* @param {olx.interaction.TranslateOptions} options Options.
|
||||
* @api
|
||||
*/
|
||||
@@ -64,6 +128,10 @@ ol.interaction.Translate.handleDownEvent_ = function(event) {
|
||||
if (!this.lastCoordinate_ && this.lastFeature_) {
|
||||
this.lastCoordinate_ = event.coordinate;
|
||||
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
||||
this.dispatchEvent(
|
||||
new ol.interaction.TranslateEvent(
|
||||
ol.interaction.TranslateEventType.TRANSLATESTART, this.features_,
|
||||
event.coordinate));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -80,6 +148,10 @@ ol.interaction.Translate.handleUpEvent_ = function(event) {
|
||||
if (this.lastCoordinate_) {
|
||||
this.lastCoordinate_ = null;
|
||||
ol.interaction.Translate.handleMoveEvent_.call(this, event);
|
||||
this.dispatchEvent(
|
||||
new ol.interaction.TranslateEvent(
|
||||
ol.interaction.TranslateEventType.TRANSLATEEND, this.features_,
|
||||
event.coordinate));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -110,6 +182,10 @@ ol.interaction.Translate.handleDragEvent_ = function(event) {
|
||||
}
|
||||
|
||||
this.lastCoordinate_ = newCoordinate;
|
||||
this.dispatchEvent(
|
||||
new ol.interaction.TranslateEvent(
|
||||
ol.interaction.TranslateEventType.TRANSLATING, this.features_,
|
||||
newCoordinate));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user