making drawing handler work on touch devices. p=sbrunner, r=me (closes #3072)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11563 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2011-02-27 15:00:38 +00:00
parent ba8aed56ef
commit 33eef42075
7 changed files with 535 additions and 48 deletions
+100 -1
View File
@@ -145,6 +145,10 @@
cancel: function() {
logs.push({type: "cancel", args: arguments});
}
},
{
pixelTolerance: 0,
dblclickTolerance: 0
});
control.handler = handler;
map.addControl(control);
@@ -642,7 +646,11 @@
});
map.addLayer(layer);
var control = new OpenLayers.Control({});
var handler = new OpenLayers.Handler.Path(control, {});
var handler = new OpenLayers.Handler.Path(control, {},
{
pixelTolerance: 0,
dblclickTolerance: 0
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
@@ -741,6 +749,97 @@
]), "geometry is correct after mousemove");
}
function test_sequence_touch_1(t) {
t.plan(19);
log = [];
var map = new OpenLayers.Map("map", { // 300 x 150
resolutions: [1]
});
var layer = new OpenLayers.Layer.Vector("foo", {
maxExtent: new OpenLayers.Bounds(-100, -100, 100, 100),
isBaseLayer: true
});
map.addLayer(layer);
var control = new OpenLayers.Control({});
var handler = new OpenLayers.Handler.Path(control, {
"done": function(g, f) {
log.push({geometry: g, feature: f});
}
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 5);
handler.activate();
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(49, 75)});
t.eq(log.length, 0, "touch start 1");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(50, 75)});
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"});
t.eq(log.length, 0, "touch end");
t.geom_eq(handler.line.geometry,
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-100, 0)
]), "geometry is correct");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
t.eq(log.length, 0, "touch start 2");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 75)});
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"});
t.eq(log.length, 0, "touch end");
t.geom_eq(handler.line.geometry,
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-100, 0)
]), "geometry is correct");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
t.eq(log.length, 0, "touch start 3");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(100, 75)});
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"});
t.eq(log.length, 0, "touch end");
t.geom_eq(handler.line.geometry,
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-50, 0),
new OpenLayers.Geometry.Point(-50, 0)
]), "geometry is correct");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(252, 100)});
t.eq(log.length, 0, "touch start 4");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(252, 100)});
t.eq(log.length, 0, "touch move");
handler.touchend({type: "touchend"});
t.eq(log.length, 0, "touch end");
handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(250, 100)});
t.eq(log.length, 1, "touch start");
handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 100)});
t.eq(log.length, 1, "touch move");
handler.touchend({type: "touchend"});
t.eq(log.length, 1, "touch end");
t.geom_eq(log[0].geometry,
new OpenLayers.Geometry.LineString([
new OpenLayers.Geometry.Point(-100, 0),
new OpenLayers.Geometry.Point(-50, 0),
new OpenLayers.Geometry.Point(102, -25)
]), "geometry is correct");
}
</script>
</head>
<body>