2013-11-08 05:54:33 +08:00
|
|
|
describe("Map.Drag", function () {
|
2013-08-18 09:18:21 +08:00
|
|
|
describe("#addHook", function () {
|
|
|
|
it("calls the map with dragging enabled", function () {
|
2015-09-25 18:55:37 +08:00
|
|
|
var container = document.createElement('div');
|
|
|
|
var map = new L.Map(container, {
|
|
|
|
dragging: true
|
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
|
|
|
|
expect(map.dragging.enabled()).to.be(true);
|
|
|
|
map.setView([0, 0], 0);
|
|
|
|
expect(map.dragging.enabled()).to.be(true);
|
2013-08-18 09:18:21 +08:00
|
|
|
});
|
|
|
|
it("calls the map with dragging and worldCopyJump enabled", function () {
|
2015-09-25 18:55:37 +08:00
|
|
|
var container = document.createElement('div');
|
|
|
|
var map = new L.Map(container, {
|
|
|
|
dragging: true,
|
|
|
|
worldCopyJump: true
|
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
|
|
|
|
expect(map.dragging.enabled()).to.be(true);
|
|
|
|
map.setView([0, 0], 0);
|
|
|
|
expect(map.dragging.enabled()).to.be(true);
|
2013-08-18 09:18:21 +08:00
|
|
|
});
|
2013-11-08 05:54:33 +08:00
|
|
|
it("calls the map with dragging disabled and worldCopyJump enabled; " +
|
2015-09-25 18:55:37 +08:00
|
|
|
"enables dragging after setting center and zoom", function () {
|
|
|
|
var container = document.createElement('div');
|
|
|
|
var map = new L.Map(container, {
|
|
|
|
dragging: false,
|
|
|
|
worldCopyJump: true
|
|
|
|
});
|
2013-08-18 09:18:21 +08:00
|
|
|
|
2013-11-08 05:54:33 +08:00
|
|
|
expect(map.dragging.enabled()).to.be(false);
|
|
|
|
map.setView([0, 0], 0);
|
|
|
|
map.dragging.enable();
|
|
|
|
expect(map.dragging.enabled()).to.be(true);
|
|
|
|
});
|
2013-08-18 09:18:21 +08:00
|
|
|
});
|
2016-03-17 21:46:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
describe("mouse events", function () {
|
|
|
|
it("change the center of the map", function (done) {
|
|
|
|
var container = document.createElement('div');
|
|
|
|
container.style.width = container.style.height = '600px';
|
|
|
|
container.style.top = container.style.left = 0;
|
|
|
|
container.style.position = 'absolute';
|
|
|
|
// container.style.background = '#808080';
|
|
|
|
|
|
|
|
document.body.appendChild(container);
|
|
|
|
|
|
|
|
var map = new L.Map(container, {
|
|
|
|
dragging: true,
|
|
|
|
inertia: false
|
|
|
|
});
|
|
|
|
map.setView([0, 0], 1);
|
|
|
|
|
|
|
|
var hand = new Hand({timing: 'fastframe'});
|
|
|
|
var mouse = hand.growFinger('mouse');
|
|
|
|
|
|
|
|
// We move 5 pixels first to overcome the 3-pixel threshold of
|
|
|
|
// L.Draggable.
|
|
|
|
mouse.wait(100).moveTo(200, 200, 0)
|
|
|
|
.down().moveBy(5, 0, 20).moveBy(256, 32, 200).up();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
var center = map.getCenter();
|
|
|
|
var zoom = map.getZoom();
|
|
|
|
document.body.removeChild(container);
|
|
|
|
expect(center.lat).to.be.within(21.9430, 21.9431);
|
|
|
|
expect(center.lng).to.be(-180);
|
|
|
|
expect(zoom).to.be(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("touch events", function () {
|
|
|
|
it.skipIfNotTouch("change the center of the map", function (done) {
|
|
|
|
var container = document.createElement('div');
|
|
|
|
container.style.width = container.style.height = '600px';
|
|
|
|
container.style.top = container.style.left = 0;
|
|
|
|
container.style.position = 'absolute';
|
|
|
|
// container.style.background = '#808080';
|
|
|
|
|
|
|
|
document.body.appendChild(container);
|
|
|
|
|
|
|
|
var map = new L.Map(container, {
|
|
|
|
dragging: true,
|
|
|
|
inertia: false
|
|
|
|
});
|
|
|
|
map.setView([0, 0], 1);
|
|
|
|
|
|
|
|
var hand = new Hand({timing: 'fastframe'});
|
|
|
|
var toucher = hand.growFinger('touch');
|
|
|
|
|
|
|
|
// We move 5 pixels first to overcome the 3-pixel threshold of
|
|
|
|
// L.Draggable.
|
|
|
|
toucher.wait(100).moveTo(200, 200, 0)
|
|
|
|
.down().moveBy(5, 0, 20).moveBy(256, 32, 200).up();
|
|
|
|
|
|
|
|
setTimeout(function () {
|
|
|
|
var center = map.getCenter();
|
|
|
|
var zoom = map.getZoom();
|
|
|
|
document.body.removeChild(container);
|
|
|
|
expect(center.lat).to.be.within(21.9430, 21.9431);
|
|
|
|
expect(center.lng).to.be(-180);
|
|
|
|
expect(zoom).to.be(1);
|
|
|
|
|
|
|
|
done();
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-18 09:18:21 +08:00
|
|
|
});
|