Write modifications back to the original layer

With the feature's getOriginal() and setOriginal() methods, an
undo tree can be maintained now.
This commit is contained in:
ahocevar
2013-11-09 15:14:11 +01:00
parent a3b18bf16e
commit fec638e8be
2 changed files with 34 additions and 2 deletions

View File

@@ -42,6 +42,13 @@ ol.Feature = function(opt_values) {
*/
this.geometryName_;
/**
* Original of this feature when it was modified.
* @type {ol.Feature}
* @private
*/
this.original_ = null;
/**
* The render intent for this feature.
* @type {ol.layer.VectorLayerRenderIntent|string}
@@ -101,6 +108,15 @@ ol.Feature.prototype.getGeometry = function() {
};
/**
* Get the original of this feature when it was modified.
* @return {ol.Feature} Original.
*/
ol.Feature.prototype.getOriginal = function() {
return this.original_;
};
/**
* Get any symbolizers set directly on the feature.
* @return {Array.<ol.style.Symbolizer>} Symbolizers (or null if none).
@@ -176,6 +192,15 @@ ol.Feature.prototype.setGeometry = function(geometry) {
};
/**
* Set the original of this feature when it was modified.
* @param {ol.Feature} original Original.
*/
ol.Feature.prototype.setOriginal = function(original) {
this.original_ = original;
};
/**
* Gets the renderIntent for this feature.
* @return {string} Render intent.

View File

@@ -172,7 +172,8 @@ ol.interaction.Modify.prototype.addSegments_ =
ol.interaction.Modify.prototype.handleDragStart = function(evt) {
this.dragSegments_ = [];
for (var i = 0, ii = this.layers_.length; i < ii; ++i) {
var selectionData = this.layers_[i].getSelectionData();
var layer = this.layers_[i];
var selectionData = layer.getSelectionData();
var selectionLayer = selectionData.layer;
if (!goog.isNull(selectionLayer)) {
var editData = selectionLayer.getEditData();
@@ -186,16 +187,22 @@ ol.interaction.Modify.prototype.handleDragStart = function(evt) {
for (var j = 0, jj = segments.length; j < jj; ++j) {
var segmentData = segments[j];
var segment = segmentData[0];
var feature = segmentData[1];
var featureId = goog.getUid(feature);
var original = selectionData.featuresBySelectedFeatureUid[featureId];
if (vertexFeature.renderIntent ==
ol.layer.VectorLayerRenderIntent.TEMPORARY) {
if (ol.coordinate.equals(segment[0], vertex)) {
this.dragSegments_.push([selectionLayer, segmentData, 0]);
} else {
feature.setOriginal(original);
} else if (ol.coordinate.equals(segment[1], vertex)) {
this.dragSegments_.push([selectionLayer, segmentData, 1]);
feature.setOriginal(original);
}
} else if (
ol.coordinate.squaredDistanceToSegment(vertex, segment) === 0) {
insertVertices.push([selectionLayer, segmentData, vertex]);
feature.setOriginal(original);
}
}
for (j = insertVertices.length - 1; j >= 0; --j) {