diff --git a/externs/oli.js b/externs/oli.js index 7d1631024d..16498949ee 100644 --- a/externs/oli.js +++ b/externs/oli.js @@ -211,6 +211,25 @@ oli.interaction.DragAndDropEvent.prototype.projection; oli.interaction.DragAndDropEvent.prototype.file; + +/** + * @interface + */ +oli.interaction.TranslateEvent = function() {}; + + +/** + * @type {ol.Collection.} + */ +oli.interaction.TranslateEvent.prototype.features; + + +/** + * @type {ol.Coordinate} + */ +oli.interaction.TranslateEvent.prototype.coordinate; + + /** * @type {Object} */ diff --git a/src/ol/interaction/translateinteraction.js b/src/ol/interaction/translateinteraction.js index d95fc0adc5..3e9a38f0dd 100644 --- a/src/ol/interaction/translateinteraction.js +++ b/src/ol/interaction/translateinteraction.js @@ -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.} 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.} + * @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)); } };