diff --git a/src/ol/interaction/drawinteraction.exports b/src/ol/interaction/drawinteraction.exports index 890ae0f515..a79108ff5f 100644 --- a/src/ol/interaction/drawinteraction.exports +++ b/src/ol/interaction/drawinteraction.exports @@ -1 +1,4 @@ @exportSymbol ol.interaction.Draw + +@exportSymbol ol.DrawEvent +@exportProperty ol.DrawEvent.prototype.getFeature diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js index 0dbc050bd9..d8d7b0c426 100644 --- a/src/ol/interaction/drawinteraction.js +++ b/src/ol/interaction/drawinteraction.js @@ -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_)); };