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:
@@ -517,6 +517,8 @@ ol.interaction.Draw.prototype.addToDrawing_ = function(event) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Stop drawing and add the sketch feature to the target layer.
|
* Stop drawing and add the sketch feature to the target layer.
|
||||||
|
* The {@link ol.DrawEventType.DRAWEND} event is dispatched before inserting
|
||||||
|
* the feature.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.interaction.Draw.prototype.finishDrawing = function() {
|
ol.interaction.Draw.prototype.finishDrawing = function() {
|
||||||
@@ -557,13 +559,16 @@ ol.interaction.Draw.prototype.finishDrawing = function() {
|
|||||||
sketchFeature.setGeometry(new ol.geom.MultiPolygon([coordinates]));
|
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_)) {
|
if (!goog.isNull(this.features_)) {
|
||||||
this.features_.push(sketchFeature);
|
this.features_.push(sketchFeature);
|
||||||
}
|
}
|
||||||
if (!goog.isNull(this.source_)) {
|
if (!goog.isNull(this.source_)) {
|
||||||
this.source_.addFeature(sketchFeature);
|
this.source_.addFeature(sketchFeature);
|
||||||
}
|
}
|
||||||
this.dispatchEvent(new ol.DrawEvent(ol.DrawEventType.DRAWEND, sketchFeature));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user