interaction/modify: Replace lastNewVertexPixel with ignoreNextSingleClick
The previous approach did not work on mobile devices where no `pointermove` event is sent except from dragging. Logic now is: Upon vertex creation due to `pointerdown` we will ignore the next `singleclick` event unless there is a `pointerdrag` event, which will not lead to a `singleclick` event following the vertex creation. Resolves #3935
This commit is contained in:
@@ -142,12 +142,12 @@ ol.interaction.Modify = function(options) {
|
|||||||
this.lastPixel_ = [0, 0];
|
this.lastPixel_ = [0, 0];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of the last inserted pixel location to avoid
|
* Tracks if the next `singleclick` event should be ignored to prevent
|
||||||
* unintentional deletion.
|
* accidental deletion right after vertex creation.
|
||||||
* @type {ol.Pixel}
|
* @type {boolean}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.lastNewVertexPixel_ = [NaN, NaN];
|
this.ignoreNextSingleClick_ = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Segment RTree for each layer
|
* Segment RTree for each layer
|
||||||
@@ -543,6 +543,8 @@ ol.interaction.Modify.handleDownEvent_ = function(evt) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Modify.handleDragEvent_ = function(evt) {
|
ol.interaction.Modify.handleDragEvent_ = function(evt) {
|
||||||
|
this.ignoreNextSingleClick_ = false;
|
||||||
|
|
||||||
var vertex = evt.coordinate;
|
var vertex = evt.coordinate;
|
||||||
for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
|
for (var i = 0, ii = this.dragSegments_.length; i < ii; ++i) {
|
||||||
var dragSegment = this.dragSegments_[i];
|
var dragSegment = this.dragSegments_[i];
|
||||||
@@ -626,8 +628,8 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
|
|||||||
}
|
}
|
||||||
if (!goog.isNull(this.vertexFeature_) &&
|
if (!goog.isNull(this.vertexFeature_) &&
|
||||||
this.deleteCondition_(mapBrowserEvent)) {
|
this.deleteCondition_(mapBrowserEvent)) {
|
||||||
if (this.lastNewVertexPixel_[0] !== this.lastPixel_[0] ||
|
if (mapBrowserEvent.type != ol.MapBrowserEvent.EventType.SINGLECLICK ||
|
||||||
this.lastNewVertexPixel_[1] !== this.lastPixel_[1]) {
|
!this.ignoreNextSingleClick_) {
|
||||||
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');
|
||||||
@@ -636,6 +638,11 @@ ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
|
|||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.SINGLECLICK) {
|
||||||
|
this.ignoreNextSingleClick_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
|
return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
|
||||||
!handled;
|
!handled;
|
||||||
};
|
};
|
||||||
@@ -789,7 +796,7 @@ ol.interaction.Modify.prototype.insertVertex_ = function(segmentData, vertex) {
|
|||||||
rTree.insert(ol.extent.boundingExtent(newSegmentData2.segment),
|
rTree.insert(ol.extent.boundingExtent(newSegmentData2.segment),
|
||||||
newSegmentData2);
|
newSegmentData2);
|
||||||
this.dragSegments_.push([newSegmentData2, 0]);
|
this.dragSegments_.push([newSegmentData2, 0]);
|
||||||
this.lastNewVertexPixel_ = this.lastPixel_;
|
this.ignoreNextSingleClick_ = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -135,6 +135,34 @@ describe('ol.interaction.Modify', function() {
|
|||||||
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(6);
|
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(6);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('single clicking on created vertex should delete it again', function() {
|
||||||
|
var modify = new ol.interaction.Modify({
|
||||||
|
features: new ol.Collection(features)
|
||||||
|
});
|
||||||
|
map.addInteraction(modify);
|
||||||
|
|
||||||
|
var feature = features[0];
|
||||||
|
|
||||||
|
expect(feature.getGeometry().getRevision()).to.equal(1);
|
||||||
|
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
|
||||||
|
|
||||||
|
simulateEvent('pointerdown', 40, -20, false, 0);
|
||||||
|
simulateEvent('pointerup', 40, -20, false, 0);
|
||||||
|
simulateEvent('click', 40, -20, false, 0);
|
||||||
|
simulateEvent('singleclick', 40, -20, false, 0);
|
||||||
|
|
||||||
|
expect(feature.getGeometry().getRevision()).to.equal(2);
|
||||||
|
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(6);
|
||||||
|
|
||||||
|
simulateEvent('pointerdown', 40, -20, false, 0);
|
||||||
|
simulateEvent('pointerup', 40, -20, false, 0);
|
||||||
|
simulateEvent('click', 40, -20, false, 0);
|
||||||
|
simulateEvent('singleclick', 40, -20, false, 0);
|
||||||
|
|
||||||
|
expect(feature.getGeometry().getRevision()).to.equal(3);
|
||||||
|
expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5);
|
||||||
|
});
|
||||||
|
|
||||||
it('clicking with drag should add vertex and +r3', function() {
|
it('clicking with drag should add vertex and +r3', function() {
|
||||||
var modify = new ol.interaction.Modify({
|
var modify = new ol.interaction.Modify({
|
||||||
features: new ol.Collection(features)
|
features: new ol.Collection(features)
|
||||||
|
|||||||
Reference in New Issue
Block a user