Modify draw interaction dispatch order

When finishing drawing, this PR dispatches the `drawend` event before adding
the feature to the source or collection.

This change allows user code to finish configuring the feature (setting style,
properties, ...).

It is useful since inserting a feature, or later on modifying it, may trigger
processing which only makes sense if the feature is ready. For example,
ol3-cesium will recreate a 3D counterpart.
This commit is contained in:
Guillaume Beraudo
2015-04-16 15:46:29 +02:00
parent c7bd5a7521
commit a468e8025a

View File

@@ -517,6 +517,8 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
/**
* Stop drawing and add the sketch feature to the target layer.
* The {@link ol.DrawEventType.DRAWEND} event is dispatched before inserting
* the feature.
* @api
*/
ol.interaction.Draw.prototype.finishDrawing = function() {
@@ -557,13 +559,16 @@ ol.interaction.Draw.prototype.finishDrawing = function() {
sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
}
// First dispatch event to allow full set up of feature
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWEND, sketchFeature));
// Then insert feature
if (!goog.isNull(this.features_)) {
this.features_.push(sketchFeature);
}
if (!goog.isNull(this.source_)) {
this.source_.addFeature(sketchFeature);
}
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWEND, sketchFeature));
};