Skip to content

Commit 9ce253b

Browse files
committed
add map touch dragging spec
1 parent 731f7b9 commit 9ce253b

File tree

2 files changed

+53
-6
lines changed

2 files changed

+53
-6
lines changed

src/handler/Drag.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { isNumber } from 'core/util';
22
import Handler from 'handler/Handler';
3-
import Browser from 'core/Browser';
43
import { on, off } from 'core/util/dom';
54
import Point from 'geo/Point';
65

7-
const START_EVENTS = Browser.touch ? 'touchstart mousedown' : 'mousedown';
6+
const START_EVENTS = 'touchstart mousedown';
87
const MOVE_EVENTS = {
98
mousedown: 'mousemove',
109
touchstart: 'touchmove',

test/map/MapDragSpec.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
2-
3-
4-
describe('#MapDrag', function () {
1+
describe('Map.Drag', function () {
52
var container;
63
var map;
74
var center = new maptalks.Coordinate(118.846825, 32.046534);
@@ -135,4 +132,55 @@ describe('#MapDrag', function () {
135132
dragToRotate(0, -1);
136133
expect(map.getPitch()).to.be.eql(pitch);
137134
});
135+
136+
it('drag map by touches', function () {
137+
map.options['panAnimation'] = false;
138+
var center2;
139+
map.setZoom(7);
140+
141+
var domPosition = GET_PAGE_POSITION(container);
142+
var point = map.coordinateToContainerPoint(center).add(domPosition);
143+
144+
var called = false;
145+
146+
map.on('moving', function (e) {
147+
called = true;
148+
expect(e.domEvent.touches.length).to.be.eql(1);
149+
});
150+
151+
happen.once(map._panels.mapWrapper, {
152+
'type' : 'touchstart',
153+
'touches' : [
154+
{
155+
'clientX':point.x,
156+
'clientY':point.y
157+
}
158+
]
159+
});
160+
for (var i = 0; i < 10; i++) {
161+
happen.once(map._panels.mapWrapper, {
162+
'type' : 'touchmove',
163+
'touches' : [
164+
{
165+
'clientX':point.x + i,
166+
'clientY':point.y + i
167+
}
168+
]
169+
})
170+
}
171+
happen.once(map._panels.mapWrapper, {
172+
'type' : 'touchend',
173+
'changedTouches' : [
174+
{
175+
'clientX':point.x + i,
176+
'clientY':point.y + i
177+
}
178+
]
179+
});
180+
181+
center2 = map.getCenter();
182+
expect(called).to.be.ok();
183+
expect(center2.toArray()).not.to.be.eql(center.toArray());
184+
expect(map.isMoving()).not.to.be.ok();
185+
});
138186
});

0 commit comments

Comments
 (0)