Add snapToPointer option

This commit is contained in:
Andreas Hocevar
2021-02-03 08:56:33 +01:00
parent cb9df36fbc
commit bf90ce2789
2 changed files with 48 additions and 2 deletions
+36
View File
@@ -208,6 +208,11 @@ describe('ol.interaction.Modify', function () {
expect(rbushEntries[0].feature).to.be(feature);
expect(modify.hitDetection_).to.be(layer);
});
it('accepts a snapToPointer option', function () {
const modify = new Modify({source: source, snapToPointer: true});
expect(modify.snapToPointer_).to.be(true);
});
});
describe('vertex deletion', function () {
@@ -1039,6 +1044,37 @@ describe('ol.interaction.Modify', function () {
pointFeature.getGeometry()
);
});
it('snaps to pointer when snapToPointer is true', function () {
const modify = new Modify({
snapToPointer: true,
source: source,
});
map.addInteraction(modify);
source.clear();
const pointFeature = new Feature(new Point([0, 0]));
source.addFeature(pointFeature);
map.renderSync();
simulateEvent('pointerdown', 2, 2, null, 0);
simulateEvent('pointerdrag', 2, 2, null, 0);
simulateEvent('pointerup', 2, 2, null, 0);
expect(pointFeature.getGeometry().getCoordinates()).to.eql([2, -2]);
});
it('does not snap to pointer by default', function () {
const modify = new Modify({
source: source,
});
map.addInteraction(modify);
source.clear();
const pointFeature = new Feature(new Point([0, 0]));
source.addFeature(pointFeature);
map.renderSync();
simulateEvent('pointerdown', 2, 2, null, 0);
simulateEvent('pointerdrag', 2, 2, null, 0);
simulateEvent('pointerup', 2, 2, null, 0);
expect(pointFeature.getGeometry().getCoordinates()).to.eql([0, 0]);
});
});
describe('#getOverlay', function () {