Reset lastDragTime when condition is not met

This commit is contained in:
ahocevar
2018-12-21 22:23:56 +01:00
parent 100e69e286
commit 409c962caf
2 changed files with 43 additions and 1 deletions

View File

@@ -4,7 +4,7 @@ import MapBrowserPointerEvent from '../../../../src/ol/MapBrowserPointerEvent.js
import View from '../../../../src/ol/View.js';
import {equals} from '../../../../src/ol/array.js';
import {listen} from '../../../../src/ol/events.js';
import {always} from '../../../../src/ol/events/condition.js';
import {always, shiftKeyOnly, altKeyOnly} from '../../../../src/ol/events/condition.js';
import Circle from '../../../../src/ol/geom/Circle.js';
import LineString from '../../../../src/ol/geom/LineString.js';
import MultiLineString from '../../../../src/ol/geom/MultiLineString.js';
@@ -492,6 +492,47 @@ describe('ol.interaction.Draw', function() {
});
describe('drawing with a condition', function() {
let draw;
beforeEach(function() {
draw = new Draw({
source: source,
type: 'LineString',
condition: shiftKeyOnly,
freehandCondition: altKeyOnly
});
map.addInteraction(draw);
});
it('finishes draw sequence correctly', function() {
// first point
simulateEvent('pointermove', 10, 20, true);
simulateEvent('pointerdown', 10, 20, true);
simulateEvent('pointerup', 10, 20, true);
// second point
simulateEvent('pointermove', 30, 20, true);
simulateEvent('pointerdown', 30, 20, true);
simulateEvent('pointerup', 30, 20, true);
// finish on second point
simulateEvent('pointerdown', 30, 20, true);
simulateEvent('pointerup', 30, 20, true);
const features = source.getFeatures();
expect(features).to.have.length(1);
const geometry = features[0].getGeometry();
expect(geometry).to.be.a(LineString);
expect(geometry.getCoordinates()).to.eql([[10, -20], [30, -20]]);
// without modifier, to be handled by the map's DragPan interaction
simulateEvent('pointermove', 20, 20);
simulateEvent('pointerdown', 20, 20);
simulateEvent('pointermove', 10, 30);
expect(draw.lastDragTime_).to.be(undefined);
});
});
describe('drawing with a finishCondition', function() {
beforeEach(function() {
const draw = new Draw({