Add draw interaction events

This commit is contained in:
oterral
2014-01-10 17:18:04 +01:00
parent 50a322208a
commit 7f12ac90da
2 changed files with 47 additions and 0 deletions

View File

@@ -1 +1,4 @@
@exportSymbol ol.interaction.Draw
@exportSymbol ol.DrawEvent
@exportProperty ol.DrawEvent.prototype.getFeature

View File

@@ -1,6 +1,8 @@
goog.provide('ol.DrawEvent');
goog.provide('ol.interaction.Draw');
goog.require('goog.asserts');
goog.require('goog.events.Event');
goog.require('ol.Collection');
goog.require('ol.Coordinate');
goog.require('ol.Feature');
@@ -23,6 +25,44 @@ goog.require('ol.style.Stroke');
goog.require('ol.style.Style');
/**
* @enum {string}
*/
ol.DrawEventType = {
DRAWSTART: 'drawstart',
DRAWEND: 'drawend'
};
/**
* @constructor
* @extends {goog.events.Event}
* @param {ol.DrawEventType} type Type.
* @param {ol.Feature} feature The feature drawn.
*/
ol.DrawEvent = function(type, feature) {
goog.base(this, type);
/**
* @private
* @type {ol.Feature}
*/
this.feature_ = feature;
};
goog.inherits(ol.DrawEvent, goog.events.Event);
/**
* @return {ol.Feature} The feature drawn to which this event pertains.
*/
ol.DrawEvent.prototype.getFeature = function() {
return this.feature_;
};
/**
* Interaction that allows drawing geometries
@@ -315,6 +355,8 @@ ol.interaction.Draw.prototype.startDrawing_ = function(event) {
goog.asserts.assert(goog.isDef(geometry));
this.sketchFeature_ = new ol.Feature(geometry);
this.updateSketchFeatures_();
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWSTART,
this.sketchFeature_));
};
@@ -430,6 +472,8 @@ ol.interaction.Draw.prototype.finishDrawing_ = function(event) {
goog.asserts.assertInstanceof(vectorSource, ol.source.Vector);
vectorSource.addFeature(sketchFeature);
}
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWEND,
this.sketchFeature_));
};