Skip to content

Commit 98bcb11

Browse files
committed
Ignore touch start with multiple points in direct_select
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.
1 parent 405e3bf commit 98bcb11

4 files changed

Lines changed: 30 additions & 6 deletions

File tree

src/modes/direct_select.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,11 @@ DirectSelect.onMouseOut = function(state) {
202202
};
203203

204204
DirectSelect.onTouchStart = DirectSelect.onMouseDown = function(state, e) {
205-
if (isVertex(e)) return this.onVertex(state, e);
206-
if (isActiveFeature(e)) return this.onFeature(state, e);
207-
if (isMidpoint(e)) return this.onMidpoint(state, e);
205+
if (e.points.length === 1) {
206+
if (isVertex(e)) return this.onVertex(state, e);
207+
if (isActiveFeature(e)) return this.onFeature(state, e);
208+
if (isMidpoint(e)) return this.onMidpoint(state, e);
209+
}
208210
};
209211

210212
DirectSelect.onDrag = function(state, e) {

test/direct_select.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,24 @@ test('direct_select', (t) => {
273273
});
274274
});
275275

276+
t.test('direct_select - pinch zooming on a vertex does not make it selected', (st) => {
277+
const [lineId] = Draw.add(getGeoJSON('line'));
278+
Draw.changeMode(Constants.modes.DIRECT_SELECT, {
279+
featureId: lineId
280+
});
281+
st.notOk(Draw.getSelectedPoints().features[0], 'no initial selection');
282+
283+
const pointPosition = getGeoJSON('line').geometry.coordinates[0];
284+
const positionSecondFinger = { x: pointPosition[0] + 1, y: pointPosition[1] + 1 };
285+
afterNextRender(() => {
286+
map.fire('touchstart', makeTouchEvent(pointPosition[0], pointPosition[1], {}, [positionSecondFinger]));
287+
afterNextRender(() => {
288+
st.notOk(Draw.getSelectedPoints().features[0], 'no initial selection');
289+
cleanUp(() => st.end());
290+
});
291+
});
292+
});
293+
276294
document.body.removeChild(mapContainer);
277295
t.end();
278296
});

test/utils/make_mouse_event.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import xtend from 'xtend';
22

33
export default function(lng = 0, lat = 0, eventProperties = {}) {
4+
const point = {x: lng, y:lat};
45
const e = {
56
originalEvent: xtend({
67
stopPropagation() {},
78
button: 0,
89
clientX: lng,
910
clientY: lat
1011
}, eventProperties),
11-
point: {x: lng, y:lat},
12+
point: point,
13+
points: [point],
1214
lngLat: {lng, lat}
1315
};
1416

test/utils/make_touch_event.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import xtend from 'xtend';
22

3-
export default function(lng = 0, lat = 0, eventProperties = {}) {
3+
export default function(lng = 0, lat = 0, eventProperties = {}, additionalPoints = []) {
4+
const point = {x: lng, y:lat};
45
const e = {
56
originalEvent: xtend({
67
stopPropagation() {},
@@ -9,7 +10,8 @@ export default function(lng = 0, lat = 0, eventProperties = {}) {
910
clientX: lng,
1011
clientY: lat
1112
}, eventProperties),
12-
point: {x: lng, y:lat},
13+
point: point,
14+
points: [point].concat(additionalPoints),
1315
lngLat: {lng, lat}
1416
};
1517

0 commit comments

Comments
 (0)