diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 82df1c7604..f348b20b93 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -435,14 +435,17 @@ class Modify extends PointerInteraction { } } } - - this.dispatchEvent( - new ModifyEvent( - ModifyEventType.MODIFYSTART, - this.featuresBeingModified_, - evt - ) - ); + if (this.featuresBeingModified_.getLength() === 0) { + this.featuresBeingModified_ = null; + } else { + this.dispatchEvent( + new ModifyEvent( + ModifyEventType.MODIFYSTART, + this.featuresBeingModified_, + evt + ) + ); + } } } diff --git a/test/browser/spec/ol/interaction/modify.test.js b/test/browser/spec/ol/interaction/modify.test.js index 875f44b05e..a888e254dd 100644 --- a/test/browser/spec/ol/interaction/modify.test.js +++ b/test/browser/spec/ol/interaction/modify.test.js @@ -20,7 +20,7 @@ import { clearUserProjection, setUserProjection, } from '../../../../../src/ol/proj.js'; -import {doubleClick} from '../../../../../src/ol/events/condition.js'; +import {doubleClick, never} from '../../../../../src/ol/events/condition.js'; import {getValues} from '../../../../../src/ol/obj.js'; describe('ol.interaction.Modify', function () { @@ -853,6 +853,33 @@ describe('ol.interaction.Modify', function () { expect(listenerSpy.callCount).to.be(1); expect(feature.getGeometry().getCoordinates()[0]).to.have.length(5); }); + + it('does not fire `modifystart` when nothing is modified', function (done) { + const modify = new Modify({ + features: new Collection(features), + insertVertexCondition: never, + }); + map.addInteraction(modify); + + let modifystart = false; + modify.on('modifystart', function () { + modifystart = true; + }); + + // try to add vertex + simulateEvent('pointermove', 40, -20, null, 0); + simulateEvent('pointerdown', 40, -20, null, 0); + simulateEvent('pointermove', 42, -30, null, 0); + simulateEvent('pointerdrag', 42, -30, null, 0); + simulateEvent('pointerup', 42, -30, null, 0); + simulateEvent('click', 42, -30, null, 0); + simulateEvent('singleclick', 42, -30, null, 0); + + setTimeout(function () { + expect(modifystart).to.be(false); + done(); + }, 0); + }); }); describe('handle feature change', function () {