From d31abd2f77324390a790a495ec6dc88c5714f749 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Sat, 6 Feb 2021 12:04:31 +0100 Subject: [PATCH] Sensible defaults --- examples/modify-icon.html | 2 +- src/ol/interaction/Modify.js | 10 ++++++---- test/spec/ol/interaction/modify.test.js | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/modify-icon.html b/examples/modify-icon.html index 37d936c61c..b8e42193bc 100644 --- a/examples/modify-icon.html +++ b/examples/modify-icon.html @@ -4,7 +4,7 @@ title: Icon modification shortdesc: Example using a Modify interaction to edit an icon. docs: > The icon on this map can be dragged to modify its location. -

The Modify interaction can be configured with a `layer` option. With this option, hit detection will be used to determine the modification candidate.

+

The Modify interaction can be configured with a `hitDetection` option. With this option, the modification candidate will not be determined by the `pixelTolerance`, but match the visual appearance of the geometry.

tags: "vector, modify, icon, marker" ---
diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 4a20d3665f..049ba94c5d 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -128,9 +128,8 @@ const ModifyEventType = { * provided, a vector source must be provided with the `source` option. * @property {boolean} [wrapX=false] Wrap the world horizontally on the sketch * overlay. - * @property {boolean} [snapToPointer=false] The vertex, point or segment being modified snaps to the - * pointer coordinate when clicked within the `pixelTolerance`. Setting this to `true` is recommended - * when the `Snap` interaction is used and the source geometry is not a snap target. + * @property {boolean} [snapToPointer=!hitDetection] The vertex, point or segment being modified snaps to the + * pointer coordinate when clicked within the `pixelTolerance`. */ /** @@ -393,7 +392,10 @@ class Modify extends PointerInteraction { /** * @private */ - this.snapToPointer_ = options.snapToPointer || false; + this.snapToPointer_ = + options.snapToPointer === undefined + ? !this.hitDetection_ + : options.snapToPointer; } /** diff --git a/test/spec/ol/interaction/modify.test.js b/test/spec/ol/interaction/modify.test.js index e25e8b5c67..ae41a018a2 100644 --- a/test/spec/ol/interaction/modify.test.js +++ b/test/spec/ol/interaction/modify.test.js @@ -1045,9 +1045,8 @@ describe('ol.interaction.Modify', function () { ); }); - it('snaps to pointer when snapToPointer is true', function () { + it('snaps to pointer by default', function () { const modify = new Modify({ - snapToPointer: true, source: source, }); map.addInteraction(modify); @@ -1061,9 +1060,10 @@ describe('ol.interaction.Modify', function () { expect(pointFeature.getGeometry().getCoordinates()).to.eql([2, -2]); }); - it('does not snap to pointer by default', function () { + it('does not snap to pointer when snapToPointer is false', function () { const modify = new Modify({ source: source, + snapToPointer: false, }); map.addInteraction(modify); source.clear();