High level Modify interaction events

This commit is contained in:
Björn Harrtell
2015-04-02 10:41:43 +02:00
parent c0b6eefd8f
commit f7d62f054c
2 changed files with 65 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ goog.provide('ol.interaction.Modify');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('goog.events');
goog.require('goog.events.Event');
goog.require('goog.functions');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
@@ -26,6 +27,52 @@ goog.require('ol.structs.RBush');
goog.require('ol.style.Style');
/**
* @enum {string}
*/
ol.ModifyEventType = {
/**
* Triggered upon feature modification start
* @event ol.ModifyEvent#modifystart
* @api stable
*/
MODIFYSTART: 'modifystart',
/**
* Triggered upon feature modification end
* @event ol.ModifyEvent#modifyend
* @api stable
*/
MODIFYEND: 'modifyend'
};
/**
* @classdesc
* Events emitted by {@link ol.interaction.Modify} instances are instances of
* this type.
*
* @constructor
* @extends {goog.events.Event}
* @implements {oli.ModifyEvent}
* @param {ol.ModifyEventType} type Type.
* @param {ol.Collection.<ol.Feature>} features The features modified.
*/
ol.ModifyEvent = function(type, features) {
goog.base(this, type);
/**
* The feature being modified.
* @type {ol.Collection.<ol.Feature>}
* @api stable
*/
this.features = features;
};
goog.inherits(ol.ModifyEvent, goog.events.Event);
/**
* @typedef {{depth: (Array.<number>|undefined),
* feature: ol.Feature,
@@ -44,6 +91,7 @@ ol.interaction.SegmentDataType;
* @constructor
* @extends {ol.interaction.Pointer}
* @param {olx.interaction.ModifyOptions} options Options.
* @fires ol.ModifyEvent
* @api stable
*/
ol.interaction.Modify = function(options) {
@@ -466,6 +514,8 @@ ol.interaction.Modify.handleDownEvent_ = function(evt) {
for (i = insertVertices.length - 1; i >= 0; --i) {
this.insertVertex_.apply(this, insertVertices[i]);
}
this.dispatchEvent(new ol.ModifyEvent(ol.ModifyEventType.MODIFYSTART,
this.features_));
}
return !goog.isNull(this.vertexFeature_);
};
@@ -537,6 +587,8 @@ ol.interaction.Modify.handleUpEvent_ = function(evt) {
this.rBush_.update(ol.extent.boundingExtent(segmentData.segment),
segmentData);
}
this.dispatchEvent(new ol.ModifyEvent(ol.ModifyEventType.MODIFYEND,
this.features_));
return false;
};