Do not return as handled unless a geometry was modified
With this change, it is more straightforward to determine whether an event is considered as handled, which results in the removal of the modifiable_ and lastVertexCoordinate_ states. Instead, we only need to know whether we're on a real vertex or a virtual one. For that a new snappedToVertex_ flag is introduced. To stop a click after vertex deletion from triggering a feature selection, vertex deletion is now triggered by a configurable event condition, which defaults to singleclick (same as in the select interaction) with no modifier keys.
This commit is contained in:
@@ -487,6 +487,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {Object} olx.interaction.ModifyOptions
|
* @typedef {Object} olx.interaction.ModifyOptions
|
||||||
|
* @property {ol.events.ConditionType} deleteCondition Condition that determines
|
||||||
|
* which event results in a vertex deletion. Default is a `singleclick`
|
||||||
|
* event with no modifier keys.
|
||||||
* @property {number|undefined} pixelTolerance Pixel tolerance for considering
|
* @property {number|undefined} pixelTolerance Pixel tolerance for considering
|
||||||
* the pointer close enough to a vertex for editing. Default is 10 pixels.
|
* the pointer close enough to a vertex for editing. Default is 10 pixels.
|
||||||
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style FeatureOverlay style.
|
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style FeatureOverlay style.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ goog.require('ol.FeatureOverlay');
|
|||||||
goog.require('ol.MapBrowserEvent.EventType');
|
goog.require('ol.MapBrowserEvent.EventType');
|
||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
goog.require('ol.coordinate');
|
goog.require('ol.coordinate');
|
||||||
|
goog.require('ol.events.condition');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.feature');
|
goog.require('ol.feature');
|
||||||
goog.require('ol.geom.GeometryType');
|
goog.require('ol.geom.GeometryType');
|
||||||
@@ -44,6 +45,14 @@ ol.interaction.Modify = function(options) {
|
|||||||
goog.base(this);
|
goog.base(this);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {ol.events.ConditionType}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.deleteCondition_ = goog.isDef(options.deleteCondition) ?
|
||||||
|
options.pixelTolerance : goog.functions.and(
|
||||||
|
ol.events.condition.noModifierKeys, ol.events.condition.singleClick);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Editing vertex.
|
* Editing vertex.
|
||||||
* @type {ol.Feature}
|
* @type {ol.Feature}
|
||||||
@@ -58,18 +67,6 @@ ol.interaction.Modify = function(options) {
|
|||||||
*/
|
*/
|
||||||
this.vertexSegments_ = null;
|
this.vertexSegments_ = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {boolean}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.modifiable_ = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @type {ol.Coordinate}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this.lastVertexCoordinate_;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.Pixel}
|
* @type {ol.Pixel}
|
||||||
* @private
|
* @private
|
||||||
@@ -90,6 +87,12 @@ ol.interaction.Modify = function(options) {
|
|||||||
this.pixelTolerance_ = goog.isDef(options.pixelTolerance) ?
|
this.pixelTolerance_ = goog.isDef(options.pixelTolerance) ?
|
||||||
options.pixelTolerance : 10;
|
options.pixelTolerance : 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.snappedToVertex_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array}
|
* @type {Array}
|
||||||
* @private
|
* @private
|
||||||
@@ -404,9 +407,8 @@ ol.interaction.Modify.prototype.handlePointerDown = function(evt) {
|
|||||||
for (i = insertVertices.length - 1; i >= 0; --i) {
|
for (i = insertVertices.length - 1; i >= 0; --i) {
|
||||||
this.insertVertex_.apply(this, insertVertices[i]);
|
this.insertVertex_.apply(this, insertVertices[i]);
|
||||||
}
|
}
|
||||||
this.lastVertexCoordinate_ = goog.array.clone(vertex);
|
|
||||||
}
|
}
|
||||||
return this.modifiable_;
|
return !goog.isNull(this.vertexFeature_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -461,20 +463,12 @@ ol.interaction.Modify.prototype.handlePointerDrag = function(evt) {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
ol.interaction.Modify.prototype.handlePointerUp = function(evt) {
|
ol.interaction.Modify.prototype.handlePointerUp = function(evt) {
|
||||||
var geometry = this.vertexFeature_.getGeometry();
|
var segmentData;
|
||||||
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
for (var i = this.dragSegments_.length - 1; i >= 0; --i) {
|
||||||
if (goog.array.equals(this.lastVertexCoordinate_,
|
segmentData = this.dragSegments_[i][0];
|
||||||
geometry.getCoordinates())) {
|
this.rBush_.update(ol.extent.boundingExtent(segmentData.segment),
|
||||||
this.removeVertex_();
|
segmentData);
|
||||||
} else {
|
|
||||||
var segmentData;
|
|
||||||
for (var i = this.dragSegments_.length - 1; i >= 0; --i) {
|
|
||||||
segmentData = this.dragSegments_[i][0];
|
|
||||||
this.rBush_.update(ol.extent.boundingExtent(segmentData.segment),
|
|
||||||
segmentData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -483,12 +477,18 @@ ol.interaction.Modify.prototype.handlePointerUp = function(evt) {
|
|||||||
*/
|
*/
|
||||||
ol.interaction.Modify.prototype.handleMapBrowserEvent =
|
ol.interaction.Modify.prototype.handleMapBrowserEvent =
|
||||||
function(mapBrowserEvent) {
|
function(mapBrowserEvent) {
|
||||||
|
var handled;
|
||||||
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
|
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
|
||||||
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
|
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
|
||||||
this.handlePointerMove_(mapBrowserEvent);
|
this.handlePointerMove_(mapBrowserEvent);
|
||||||
}
|
}
|
||||||
return (goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent) &&
|
if (!goog.isNull(this.vertexFeature_) && this.snappedToVertex_ &&
|
||||||
!this.modifiable_);
|
this.deleteCondition_(mapBrowserEvent)) {
|
||||||
|
var geometry = this.vertexFeature_.getGeometry();
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
|
||||||
|
handled = this.removeVertex_();
|
||||||
|
}
|
||||||
|
return goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent) && !handled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -520,7 +520,6 @@ ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
|
|||||||
[pixel[0] + this.pixelTolerance_, pixel[1] - this.pixelTolerance_]);
|
[pixel[0] + this.pixelTolerance_, pixel[1] - this.pixelTolerance_]);
|
||||||
var box = ol.extent.boundingExtent([lowerLeft, upperRight]);
|
var box = ol.extent.boundingExtent([lowerLeft, upperRight]);
|
||||||
|
|
||||||
this.modifiable_ = false;
|
|
||||||
var rBush = this.rBush_;
|
var rBush = this.rBush_;
|
||||||
var nodes = rBush.getInExtent(box);
|
var nodes = rBush.getInExtent(box);
|
||||||
if (nodes.length > 0) {
|
if (nodes.length > 0) {
|
||||||
@@ -557,7 +556,6 @@ ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.vertexSegments_ = vertexSegments;
|
this.vertexSegments_ = vertexSegments;
|
||||||
this.modifiable_ = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -638,6 +636,7 @@ ol.interaction.Modify.prototype.insertVertex_ = function(segmentData, vertex) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a vertex from all matching features.
|
* Removes a vertex from all matching features.
|
||||||
|
* @return {boolean} True when a vertex was removed.
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.interaction.Modify.prototype.removeVertex_ = function() {
|
ol.interaction.Modify.prototype.removeVertex_ = function() {
|
||||||
@@ -724,6 +723,15 @@ ol.interaction.Modify.prototype.removeVertex_ = function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return deleted;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.interaction.Modify.prototype.shouldStopEvent = function(handled) {
|
||||||
|
return handled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user