Do not fire modifyend event when nothing was modified

This commit is contained in:
Andreas Hocevar
2022-01-11 12:04:56 +01:00
parent 866c641c87
commit 48ce451f53
2 changed files with 42 additions and 8 deletions

View File

@@ -1360,6 +1360,7 @@ class Modify extends PointerInteraction {
const evt = this.lastPointerEvent_;
this.willModifyFeatures_(evt, this.dragSegments_);
const removed = this.removeVertex_();
if (this.featuresBeingModified_) {
this.dispatchEvent(
new ModifyEvent(
ModifyEventType.MODIFYEND,
@@ -1367,6 +1368,8 @@ class Modify extends PointerInteraction {
evt
)
);
}
this.featuresBeingModified_ = null;
return removed;
}

View File

@@ -20,7 +20,11 @@ import {
clearUserProjection,
setUserProjection,
} from '../../../../../src/ol/proj.js';
import {doubleClick, never} from '../../../../../src/ol/events/condition.js';
import {
click,
doubleClick,
never,
} from '../../../../../src/ol/events/condition.js';
import {getValues} from '../../../../../src/ol/obj.js';
describe('ol.interaction.Modify', function () {
@@ -880,6 +884,33 @@ describe('ol.interaction.Modify', function () {
done();
}, 0);
});
it('does not fire `modifyend` when nothing is modified', function (done) {
const modify = new Modify({
features: new Collection(features),
deleteCondition: click,
insertVertexCondition: never,
});
map.addInteraction(modify);
let modifyend = false;
modify.on('modifyend', function (e) {
modifyend = true;
});
// try to add vertex
simulateEvent('pointermove', 40, -20, null, 0);
simulateEvent('pointerdown', 40, -20, 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(modifyend).to.be(false);
done();
}, 0);
});
});
describe('handle feature change', function () {