[OpenLayers-Commits] r11085 -
sandbox/elemoine/draw-feature/tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Feb 10 05:46:23 EST 2011
Author: erilem
Date: 2011-02-10 02:46:23 -0800 (Thu, 10 Feb 2011)
New Revision: 11085
Modified:
sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
Log:
polygon handler tests, test_rings still requires adapatations
Modified: sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Polygon.html 2011-02-10 10:46:17 UTC (rev 11084)
+++ sandbox/elemoine/draw-feature/tests/Handler/Polygon.html 2011-02-10 10:46:23 UTC (rev 11085)
@@ -25,12 +25,27 @@
}
function test_Handler_Polygon_activation(t) {
- t.plan(3);
- var map = new OpenLayers.Map('map');
+ t.plan(13);
+ 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, {
+ "create": function(g, f) {
+ log.push({geometry: g, feature: f});
+ }
+ });
+ control.handler = handler;
map.addControl(control);
- var handler = new OpenLayers.Handler.Polygon(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.active = true;
+
var activated = handler.activate();
t.ok(!activated,
"activate returns false if the handler was already active");
@@ -38,10 +53,31 @@
activated = handler.activate();
t.ok(activated,
"activate returns true if the handler was not already active");
+ t.ok(handler.layer instanceof OpenLayers.Layer.Vector,
+ "activate creates a vector layer");
+ t.ok(handler.layer.map == map,
+ "activate adds the vector layer to the map");
+ t.ok(handler.point instanceof OpenLayers.Feature.Vector,
+ "activate creates a point feature");
+ t.ok(handler.point.layer == handler.layer,
+ "activate adds the point feature to the layer");
+ t.ok(handler.line instanceof OpenLayers.Feature.Vector,
+ "activates creates a line feature");
+ t.ok(handler.polygon instanceof OpenLayers.Feature.Vector,
+ "acttivates creates a polygon feature");
+ t.ok(handler.polygon.layer == handler.layer,
+ "activate adds the polygin feature to the layer");
+ t.eq(log.length, 1,
+ "activate calls \"create\" once");
+ t.geom_eq(log[0].geometry, handler.point.geometry,
+ "\"create\" called with expected geometry");
+ t.ok(log[0].feature == handler.polygon,
+ "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
- map.destroy();
+
+ map.destroy();
}
function test_Handler_Polygon_bounds(t) {
@@ -72,7 +108,7 @@
}
function test_callbacks(t) {
- t.plan(15);
+ t.plan(35);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -83,57 +119,126 @@
map.addLayer(layer);
var control = new OpenLayers.Control({
});
- var log = {};
+ var logs = [], log;
var handler = new OpenLayers.Handler.Polygon(control, {
create: function() {
- log.type = "create",
- log.args = arguments
+ logs.push({type: "create", args: arguments});
},
+ point: function() {
+ logs.push({type: "point", args: arguments});
+ },
modify: function() {
- log.type = "modify",
- log.args = arguments
+ logs.push({type: "modify", args: arguments});
},
done: function() {
- log.type = "done",
- log.args = arguments
+ logs.push({type: "done", args: arguments});
},
cancel: function() {
- log.type = "cancel",
- log.args = arguments
+ logs.push({type: "cancel", args: arguments});
}
});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // mock up feature drawing
+ // create polygon
handler.activate();
- // click at 0, 0
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(log.type, "create", "[mousedown] create called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mousedown] correct sketch feature");
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ handler.activate();
+ t.eq(logs.length, 1, "[activate] called back");
+ log = logs.shift();
+ t.eq(log.type, "create", "[activate] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[activate] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[activate] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ t.eq(log.type, "modify", "[mousedown] modify called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousedown] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[mousedown] correct feature");
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 2, "[mouseup] called back twice");
+ log = logs.shift();
+ t.eq(log.type, "point", "[mouseup] point called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ var geom = new OpenLayers.Geometry.Polygon([
+ new OpenLayers.Geometry.LinearRing([
+ new OpenLayers.Geometry.Point(-150, 75)
+ ])
+ ]);
+ geom.components[0].addComponent(
+ new OpenLayers.Geometry.Point(-150, 75),
+ geom.components[0].components.length
+ );
+ t.geom_eq(log.args[1], geom, "[mouseup] correct polygon");
+ log = logs.shift();
t.eq(log.type, "modify", "[mouseup] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mouseup] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- // move to 10, 10 and click
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mouseup] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[mouseup] correct feature");
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(10, 10)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-140, 65),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(10, 10)});
+ log = logs.shift();
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(10, 10)});
+ log = logs.shift();
+ log = logs.shift();
// move to 0, 10 and double click
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ // mouse move
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 1, "[mousemove] called back");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
- t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 65), "[mousemove] correct vertex");
- t.ok(log.args[1] === handler.polygon, "[mouseup] correct sketch feature");
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
- handler.dblclick({type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 65),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.polygon,
+ "[mousemove] correct feature");
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 1, "[mousedown] called back");
+ log = logs.shift();
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 2, "[mouseup] called back");
+ log = logs.shift();
+ log = logs.shift();
+ // mouse down
+ handler.mousedown(
+ {type: "mousedown", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 0, "[mousedown] not called back");
+ // mouse up
+ handler.mouseup(
+ {type: "mouseup", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 0, "[mouseup] not called back");
+ // dblclick
+ handler.dblclick(
+ {type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
+ t.eq(logs.length, 2, "[dblclick] called back twice");
+ log = logs.shift();
t.eq(log.type, "done", "[dblclick] done called");
t.geom_eq(
log.args[0],
@@ -147,18 +252,22 @@
]),
"[dblclick] correct polygon"
);
-
- // mock up sketch cancel
- handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
- handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)});
- handler.deactivate();
- t.eq(log.type, "cancel", "[deactivate while drawing] cancel called");
-
+ log = logs.shift();
+ t.eq(log.type, "create", "[dblclick] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[dblclick] correct point");
+ t.ok(log.args[1] == handler.polygon,
+ "[dblclick] correct feature");
+ // cancel
+ handler.cancel();
+ t.eq(logs.length, 1, "[cancel] called back");
+ log = logs.shift();
+ t.eq(log.type, "cancel", "[cancel] canced called");
+
map.destroy();
}
- function test_rings(t) {
+ function _test_rings(t) {
t.plan(12);
var log = [];
More information about the Commits
mailing list