Skip to content

Commit

Permalink
Ignore touch start with multiple points in direct_select
Browse files Browse the repository at this point in the history
When you pinch zoom, onTouchStart will be called with multiple points in
the event. When you do this, you don't want the vertices to be moved, or
vertices created on midpoints. Therefore, these actions should only
happen if the event only contains one point.
  • Loading branch information
trygveaa committed Mar 20, 2020
1 parent 405e3bf commit 09943f9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/modes/direct_select.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ DirectSelect.onMouseOut = function(state) {
};

DirectSelect.onTouchStart = DirectSelect.onMouseDown = function(state, e) {
if (isVertex(e)) return this.onVertex(state, e);
if (isActiveFeature(e)) return this.onFeature(state, e);
if (isMidpoint(e)) return this.onMidpoint(state, e);
if (e.points == null || e.points.length === 1) {
if (isVertex(e)) return this.onVertex(state, e);
if (isActiveFeature(e)) return this.onFeature(state, e);
if (isMidpoint(e)) return this.onMidpoint(state, e);
}
};

DirectSelect.onDrag = function(state, e) {
Expand Down
18 changes: 18 additions & 0 deletions test/direct_select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,24 @@ test('direct_select', (t) => {
});
});

t.test('direct_select - pinch zooming on a vertex does not make it selected', (st) => {
const [lineId] = Draw.add(getGeoJSON('line'));
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
featureId: lineId
});
st.notOk(Draw.getSelectedPoints().features[0], 'no initial selection');

const pointPosition = getGeoJSON('line').geometry.coordinates[0];
const positionSecondFinger = { x: pointPosition[0] + 1, y: pointPosition[1] + 1 };
afterNextRender(() => {
map.fire('touchstart', makeTouchEvent(pointPosition[0], pointPosition[1], {}, [positionSecondFinger]));
afterNextRender(() => {
st.notOk(Draw.getSelectedPoints().features[0], 'no initial selection');
cleanUp(() => st.end());
});
});
});

document.body.removeChild(mapContainer);
t.end();
});
6 changes: 4 additions & 2 deletions test/utils/make_touch_event.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import xtend from 'xtend';

export default function(lng = 0, lat = 0, eventProperties = {}) {
export default function(lng = 0, lat = 0, eventProperties = {}, additionalPoints = []) {
const point = {x: lng, y:lat};
const e = {
originalEvent: xtend({
stopPropagation() {},
Expand All @@ -9,7 +10,8 @@ export default function(lng = 0, lat = 0, eventProperties = {}) {
clientX: lng,
clientY: lat
}, eventProperties),
point: {x: lng, y:lat},
point,
points: [point].concat(additionalPoints),
lngLat: {lng, lat}
};

Expand Down

0 comments on commit 09943f9

Please sign in to comment.