[OpenLayers-Commits] r11774 - in sandbox/tschaub/canvas: . examples
lib/OpenLayers/Handler tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Wed Mar 30 07:49:28 EDT 2011
Author: fredj
Date: 2011-03-30 04:49:27 -0700 (Wed, 30 Mar 2011)
New Revision: 11774
Modified:
sandbox/tschaub/canvas/
sandbox/tschaub/canvas/examples/mobile-navigation.html
sandbox/tschaub/canvas/lib/OpenLayers/Handler/Click.js
sandbox/tschaub/canvas/lib/OpenLayers/Handler/Path.js
sandbox/tschaub/canvas/lib/OpenLayers/Handler/Point.js
sandbox/tschaub/canvas/lib/OpenLayers/Handler/RegularPolygon.js
sandbox/tschaub/canvas/tests/Handler/Click.html
sandbox/tschaub/canvas/tests/Handler/Path.html
sandbox/tschaub/canvas/tests/Handler/Polygon.html
Log:
Merge r11765:11773 from trunk.
Property changes on: sandbox/tschaub/canvas
___________________________________________________________________
Modified: svn:mergeinfo
- /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:10737-11416,11422-11762
+ /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:10737-11416,11422-11762,11766-11773
Modified: sandbox/tschaub/canvas/examples/mobile-navigation.html
===================================================================
--- sandbox/tschaub/canvas/examples/mobile-navigation.html 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/examples/mobile-navigation.html 2011-03-30 11:49:27 UTC (rev 11774)
@@ -23,8 +23,8 @@
<div id="docs">
<p>
- This example demonstates what OpenLayers provides for map
- navigation on mobile.
+ This example demonstrates what OpenLayers provides for map
+ navigation on mobile devices.
</p>
<p>
Modified: sandbox/tschaub/canvas/lib/OpenLayers/Handler/Click.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Handler/Click.js 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Handler/Click.js 2011-03-30 11:49:27 UTC (rev 11774)
@@ -191,6 +191,7 @@
evt.xy = this.last.xy;
evt.lastTouches = this.last.touches;
this.handleSingle(evt);
+ this.down = null;
}
return true;
},
Modified: sandbox/tschaub/canvas/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Handler/Path.js 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Handler/Path.js 2011-03-30 11:49:27 UTC (rev 11774)
@@ -45,6 +45,12 @@
freehandToggle: 'shiftKey',
/**
+ * Property: timerId
+ * {Integer} The timer used to test the double touch.
+ */
+ timerId: null,
+
+ /**
* Constructor: OpenLayers.Handler.Path
* Create a new path hander
*
@@ -214,6 +220,38 @@
},
/**
+ * method: touchstart
+ * handle touchstart.
+ *
+ * parameters:
+ * evt - {event} the browser event
+ *
+ * returns:
+ * {boolean} allow event propagation
+ */
+ touchstart: function(evt) {
+ if (this.timerId &&
+ this.passesTolerance(this.lastTouchPx, evt.xy, this.dblclickTolerance)) {
+ // double-tap, finalize the geometry
+ this.lastTouchPx = evt.xy; // for up() to detect dblclick and do nothing
+ this.finishTouchGeometry();
+ window.clearTimeout(this.timerId);
+ this.timerId = null;
+ return false;
+ } else {
+ if (this.timerId) {
+ window.clearTimeout(this.timerId);
+ this.timerId = null;
+ }
+ this.timerId = window.setTimeout(
+ OpenLayers.Function.bind(function() {
+ this.timerId = null;
+ }, this), 300);
+ return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt);
+ }
+ },
+
+ /**
* Method: mousedown
* Handle mouse down. Add a new point to the geometry and
* render it. Return determines whether to propagate the event on the map.
@@ -295,7 +333,7 @@
}
this.stoppedDown = this.stopDown;
this.mouseDown = false;
- return !this.stopUp && !this.isDblclick;
+ return !this.stopUp;
},
/**
Modified: sandbox/tschaub/canvas/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Handler/Point.js 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Handler/Point.js 2011-03-30 11:49:27 UTC (rev 11774)
@@ -120,26 +120,13 @@
touch: false,
/**
- * Property: timerId
- * {Integer} The timer used to test the double touch.
- */
- timerId: null,
-
- /**
- * Property: last
+ * Property: lastTouchPx
* {<OpenLayers.Pixel>} The last pixel used to know the distance between
* two touches (for double touch).
*/
- last: null,
+ lastTouchPx: null,
/**
- * Property: dblclick
- * {Boolean} The current event is a dblclick.
- */
- isDblclick: false,
-
-
- /**
* Constructor: OpenLayers.Handler.Point
* Create a new point handler.
*
@@ -281,6 +268,7 @@
this.mouseDown = false;
this.lastDown = null;
this.lastUp = null;
+ this.lastTouchPx = null;
this.callback(key, [this.geometryClone()]);
if(cancel || !this.persist) {
this.destroyFeature();
@@ -415,32 +403,8 @@
*/
touchstart: function(evt) {
this.touch = true;
-
- var last = this.last;
- this.last = evt.xy;
-
- if (this.timerId &&
- this.passesTolerance(last, evt.xy, this.dblclickTolerance)) {
- this.isDblclick = true;
- // a valid touch immediately adds a component and leaves us with a
- // complete geometry
- this.finishTouchGeometry();
- window.clearTimeout(this.timerId);
- this.timerId = null;
- return false;
- }
- else {
- if (this.timerId) {
- window.clearTimeout(this.timerId);
- this.timerId = null;
- }
- this.isDblclick = false;
- this.timerId = window.setTimeout(
- OpenLayers.Function.bind(function() {
- this.timerId = null;
- }, this), 300);
- return this.down(evt);
- }
+ this.lastTouchPx = evt.xy;
+ return this.down(evt);
},
/**
@@ -471,7 +435,7 @@
* {Boolean} Allow event propagation
*/
touchmove: function(evt) {
- this.last = evt.xy;
+ this.lastTouchPx = evt.xy;
return this.move(evt);
},
@@ -503,7 +467,7 @@
* {Boolean} Allow event propagation
*/
touchend: function(evt) {
- evt.xy = this.last;
+ evt.xy = this.lastTouchPx;
return this.up(evt);
},
Modified: sandbox/tschaub/canvas/lib/OpenLayers/Handler/RegularPolygon.js
===================================================================
--- sandbox/tschaub/canvas/lib/OpenLayers/Handler/RegularPolygon.js 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/lib/OpenLayers/Handler/RegularPolygon.js 2011-03-30 11:49:27 UTC (rev 11774)
@@ -303,7 +303,7 @@
* evt - {Event} The mouse out event
*/
out: function(evt) {
- this.finalize();
+ this.cancel();
},
/**
Modified: sandbox/tschaub/canvas/tests/Handler/Click.html
===================================================================
--- sandbox/tschaub/canvas/tests/Handler/Click.html 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/tests/Handler/Click.html 2011-03-30 11:49:27 UTC (rev 11774)
@@ -489,7 +489,7 @@
}
function test_touch_click(t) {
- t.plan(4);
+ t.plan(5);
// set up
@@ -511,6 +511,7 @@
// test
+ // the common case: a touchstart followed by a touchend
log = null;
handler.touchstart({xy: px(1, 1), touches: ["foo"]});
handler.touchend({touches: ["foo"]});
@@ -522,8 +523,19 @@
t.eq(log.y, 1, "evt.xy.y as expected");
t.ok(log.lastTouches, "evt.lastTouches as expected");
}
- // tear down
- map.destroy();
+
+ // now emulate a touch where touchstart doesn't propagate
+ // to the click handler, i.e. the click handler gets a
+ // touchend only
+ log = null;
+ handler.touchend({touches: ["foo"]});
+
+ t.delay_call(1, function() {
+ t.ok(log == null, "click callback not called");
+
+ // tear down
+ map.destroy();
+ });
});
}
Modified: sandbox/tschaub/canvas/tests/Handler/Path.html
===================================================================
--- sandbox/tschaub/canvas/tests/Handler/Path.html 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/tests/Handler/Path.html 2011-03-30 11:49:27 UTC (rev 11774)
@@ -774,7 +774,6 @@
// a) tap
- // b) tap
// c) doubletap
function test_touch_sequence1(t) {
t.plan(17);
@@ -824,7 +823,7 @@
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75),
"[touchend] correct point");
- // tap on (10, 10)
+ // doubletap on (10, 10)
log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
t.ok(ret, '[touchstart] event propagates');
@@ -837,8 +836,6 @@
t.eq(log.type, 'modify', '[touchend] feature modified');
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
"[touchend] correct point");
-
- // tap on (11, 10) -> doubletap
log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
t.ok(!ret, '[touchstart] event does not propagate');
@@ -856,8 +853,7 @@
// a) tap
// b) tap-move
- // c) tap
- // d) doubletap
+ // c) doubletap
function test_touch_sequence2(t) {
t.plan(23);
@@ -918,7 +914,7 @@
t.ok(ret, '[touchend] event propagates');
t.eq(log, null, '[touchend] feature not finalized or modified');
- // tap on (10, 10)
+ // doubletap on (10, 10)
log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
t.ok(ret, '[touchstart] event propagates');
@@ -931,8 +927,6 @@
t.eq(log.type, 'modify', '[touchend] feature modified');
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
"[touchend] correct point");
-
- // tap on (11, 10) -> doubletap
log = null;
ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
t.ok(!ret, '[touchstart] event does not propagate');
Modified: sandbox/tschaub/canvas/tests/Handler/Polygon.html
===================================================================
--- sandbox/tschaub/canvas/tests/Handler/Polygon.html 2011-03-30 11:30:07 UTC (rev 11773)
+++ sandbox/tschaub/canvas/tests/Handler/Polygon.html 2011-03-30 11:49:27 UTC (rev 11774)
@@ -904,103 +904,209 @@
]), "geometry is correct");
}
+ // a) tap
+ // b) tap
+ // c) doubletap
+ function test_touch_sequence1(t) {
+ t.plan(24);
- function test_sequence_touch_1(t) {
- t.plan(19);
-
- log = [];
- var map = new OpenLayers.Map("map", { // 300 x 150
+ // set up
+
+ var log;
+ var map = new OpenLayers.Map("map", {
resolutions: [1]
});
var layer = new OpenLayers.Layer.Vector("foo", {
- maxExtent: new OpenLayers.Bounds(-100, -100, 100, 100),
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
isBaseLayer: true
});
map.addLayer(layer);
var control = new OpenLayers.Control({});
var handler = new OpenLayers.Handler.Polygon(control, {
- "done": function(g, f) {
- log.push({geometry: g, feature: f});
+ done: function(g, f) {
+ log = {type: 'done', geometry: g, feature: f};
+ },
+ modify: function(g, f) {
+ log = {type: 'modify', geometry: g, feature: f};
}
+ }, {
+ dblclickTolerance: 2
});
control.handler = handler;
- control.layer = layer;
map.addControl(control);
- map.setCenter(new OpenLayers.LonLat(0, 0), 5);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.activate();
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(49, 75)});
- t.eq(log.length, 0, "touch start 1");
- var expectedRing = new OpenLayers.Geometry.LinearRing([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-100, 0)
- ]);
- 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");
- expectedRing.addComponent(new OpenLayers.Geometry.Point(-100,0), 1);
+ // test
- t.geom_eq(handler.polygon.geometry.components[0], expectedRing, "geometry is correct");
+ var ret;
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch start 2");
- var expectedRing = new OpenLayers.Geometry.LinearRing([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-100, 0)
- ]);
+ // tap on (0, 0)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 0)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 0)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-150, 75),
+ "[touchend] correct point");
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 75)});
- t.eq(log.length, 0, "touch move");
+ // tap on (0, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-150, 65),
+ "[touchend] correct point");
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
- expectedRing.addComponent(new OpenLayers.Geometry.Point(-100,0), 1);
-
- t.geom_eq(handler.polygon.geometry.components[0], expectedRing, "geometry is correct");
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch start 3");
+ // doubletap on (10, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(10, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
+ "[touchend] correct point");
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
+ t.ok(!ret, '[touchstart] event does not propagate');
+ t.eq(log.type, 'done', '[touchend] feature finalized');
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ])
+ ]), "[touchstart] geometry is correct");
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(100, 75)});
- t.eq(log.length, 0, "touch move");
+ // tear down
- handler.touchend({type: "touchend"});
- t.eq(log.length, 0, "touch end");
- t.geom_eq(handler.polygon.geometry,
- new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-50, 0),
- new OpenLayers.Geometry.Point(-50, 0),
- new OpenLayers.Geometry.Point(-100, 0)
- ])]), "geometry is correct");
-
- handler.touchstart({type: "touchstart", xy: new OpenLayers.Pixel(252, 100)});
- t.eq(log.length, 0, "touch start 4");
+ map.destroy();
+ }
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(252, 100)});
- t.eq(log.length, 0, "touch move");
+ // a) tap
+ // b) tap-move
+ // c) tap
+ // d) doubletap
+ function test_touch_sequence2(t) {
+ t.plan(30);
- 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");
+ // set up
- handler.touchmove({type: "touchmove", xy: new OpenLayers.Pixel(250, 100)});
- t.eq(log.length, 1, "touch move");
+ var log;
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Polygon(control, {
+ done: function(g, f) {
+ log = {type: 'done', geometry: g, feature: f};
+ },
+ modify: function(g, f) {
+ log = {type: 'modify', geometry: g, feature: f};
+ }
+ }, {
+ dblclickTolerance: 2
+ });
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+ handler.activate();
- handler.touchend({type: "touchend"});
- t.eq(log.length, 1, "touch end");
- t.geom_eq(log[0].geometry,
- new OpenLayers.Geometry.Polygon([new OpenLayers.Geometry.LinearRing([
- new OpenLayers.Geometry.Point(-100, 0),
- new OpenLayers.Geometry.Point(-50, 0),
- new OpenLayers.Geometry.Point(102, -25),
- new OpenLayers.Geometry.Point(-100, 0)
- ])]), "geometry is correct");
+ // test
+
+ var ret;
+
+ // tap on (0, 0)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 0)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 0)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-150, 75),
+ "[touchend] correct point");
+
+ // tap-move
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(20, 20)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log, null, '[touchend] feature not finalized or modified');
+
+ // tap on (0, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(1, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(0, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-150, 65),
+ "[touchend] correct point");
+
+ // doubletap on (10, 10)
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(9, 10)});
+ t.ok(ret, '[touchstart] event propagates');
+ t.eq(log, null, '[touchstart] feature not finalized or modified');
+ ret = handler.touchmove({xy: new OpenLayers.Pixel(10, 10)});
+ t.ok(ret, '[touchmove] event propagates');
+ t.eq(log, null, '[touchmove] feature not finalized or modified');
+ ret = handler.touchend({});
+ t.ok(ret, '[touchend] event propagates');
+ t.eq(log.type, 'modify', '[touchend] feature modified');
+ t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-140, 65),
+ "[touchend] correct point");
+ log = null;
+ ret = handler.touchstart({xy: new OpenLayers.Pixel(11, 10)});
+ t.ok(!ret, '[touchstart] event does not propagate');
+ t.eq(log.type, 'done', '[touchend] feature finalized');
+ t.geom_eq(log.geometry,
+ new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75), // (0, 0)
+ new OpenLayers.Geometry.Point(-150, 65), // (0, 10)
+ new OpenLayers.Geometry.Point(-140, 65) // (10, 10)
+ ])
+ ]), "[touchstart] geometry is correct");
+
+ // tear down
+
+ map.destroy();
}
</script>
More information about the Commits
mailing list