Expose removeVertex_ as removePoint
This commit is contained in:
@@ -240,6 +240,12 @@ ol.interaction.Modify = function(options) {
|
|||||||
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
|
ol.events.listen(this.features_, ol.CollectionEventType.REMOVE,
|
||||||
this.handleFeatureRemove_, this);
|
this.handleFeatureRemove_, this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.MapBrowserPointerEvent}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.lastPointerEvent_ = null;
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.interaction.Modify, ol.interaction.Pointer);
|
goog.inherits(ol.interaction.Modify, ol.interaction.Pointer);
|
||||||
|
|
||||||
@@ -696,6 +702,7 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
|
|||||||
if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
|
if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
this.lastPointerEvent_ = mapBrowserEvent;
|
||||||
|
|
||||||
var handled;
|
var handled;
|
||||||
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
|
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
|
||||||
@@ -709,11 +716,7 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
|
|||||||
var geometry = this.vertexFeature_.getGeometry();
|
var geometry = this.vertexFeature_.getGeometry();
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point,
|
goog.asserts.assertInstanceof(geometry, ol.geom.Point,
|
||||||
'geometry should be an ol.geom.Point');
|
'geometry should be an ol.geom.Point');
|
||||||
this.willModifyFeatures_(mapBrowserEvent);
|
handled = this.removePoint();
|
||||||
handled = this.removeVertex_();
|
|
||||||
this.dispatchEvent(new ol.interaction.ModifyEvent(
|
|
||||||
ol.ModifyEventType.MODIFYEND, this.features_, mapBrowserEvent));
|
|
||||||
this.modified_ = false;
|
|
||||||
} else {
|
} else {
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
@@ -879,6 +882,23 @@ ol.interaction.Modify.prototype.insertVertex_ = function(segmentData, vertex) {
|
|||||||
this.ignoreNextSingleClick_ = true;
|
this.ignoreNextSingleClick_ = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the vertex currently being pointed.
|
||||||
|
* @return {boolean} True when a vertex was removed.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.interaction.Modify.prototype.removePoint = function() {
|
||||||
|
var handled = false;
|
||||||
|
if (this.lastPointerEvent_) {
|
||||||
|
var evt = this.lastPointerEvent_;
|
||||||
|
this.willModifyFeatures_(evt);
|
||||||
|
handled = this.removeVertex_();
|
||||||
|
this.dispatchEvent(new ol.interaction.ModifyEvent(
|
||||||
|
ol.ModifyEventType.MODIFYEND, this.features_, evt));
|
||||||
|
this.modified_ = false;
|
||||||
|
}
|
||||||
|
return handled;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a vertex from all matching features.
|
* Removes a vertex from all matching features.
|
||||||
|
|||||||
@@ -252,6 +252,43 @@ describe('ol.interaction.Modify', function() {
|
|||||||
validateEvents(events, features);
|
validateEvents(events, features);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('deletes vertex of a LineString programmatically', function() {
|
||||||
|
var lineFeature = new ol.Feature({
|
||||||
|
geometry: new ol.geom.LineString(
|
||||||
|
[[0, 0], [10, 20], [0, 40], [40, 40], [40, 0]]
|
||||||
|
)
|
||||||
|
});
|
||||||
|
features.length = 0;
|
||||||
|
features.push(lineFeature);
|
||||||
|
features.push(lineFeature.clone());
|
||||||
|
|
||||||
|
var first = features[0];
|
||||||
|
var firstRevision = first.getGeometry().getRevision();
|
||||||
|
|
||||||
|
var modify = new ol.interaction.Modify({
|
||||||
|
features: new ol.Collection(features)
|
||||||
|
});
|
||||||
|
map.addInteraction(modify);
|
||||||
|
|
||||||
|
var events = trackEvents(first, modify);
|
||||||
|
|
||||||
|
expect(first.getGeometry().getRevision()).to.equal(firstRevision);
|
||||||
|
expect(first.getGeometry().getCoordinates()).to.have.length(5);
|
||||||
|
|
||||||
|
simulateEvent('pointerdown', 40, 0, false, 0);
|
||||||
|
simulateEvent('pointerup', 40, 0, false, 0);
|
||||||
|
|
||||||
|
modify.removePoint();
|
||||||
|
|
||||||
|
expect(first.getGeometry().getRevision()).to.equal(firstRevision + 1);
|
||||||
|
expect(first.getGeometry().getCoordinates()).to.have.length(4);
|
||||||
|
expect(first.getGeometry().getCoordinates()[3][0]).to.equal(40);
|
||||||
|
expect(first.getGeometry().getCoordinates()[3][1]).to.equal(40);
|
||||||
|
|
||||||
|
validateEvents(events, features);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('boundary modification', function() {
|
describe('boundary modification', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user