Use the pixelTolerance to determine whether to snap to a vertex

This commit is contained in:
ahocevar
2014-03-30 14:11:31 +02:00
parent 8fc9b23ab8
commit f2acbd332c
2 changed files with 4 additions and 2 deletions

View File

@@ -491,7 +491,8 @@
* which event results in a vertex deletion. Default is a `singleclick`
* event with no modifier keys.
* @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 segment or vertex for editing. Default is
* 10 pixels.
* @property {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined} style FeatureOverlay style.
* @property {ol.Collection} features The features the interaction works on.
*/

View File

@@ -536,7 +536,8 @@ ol.interaction.Modify.prototype.handlePointerAtPixel_ = function(pixel, map) {
var squaredDist1 = ol.coordinate.squaredDistance(vertexPixel, pixel1);
var squaredDist2 = ol.coordinate.squaredDistance(vertexPixel, pixel2);
var dist = Math.sqrt(Math.min(squaredDist1, squaredDist2));
if (dist <= 10) {
this.snappedToVertex_ = dist <= this.pixelTolerance_;
if (this.snappedToVertex_) {
vertex = squaredDist1 > squaredDist2 ?
closestSegment[1] : closestSegment[0];
}