diff --git a/lib/OpenLayers/Handler/Path.js b/lib/OpenLayers/Handler/Path.js index 4ef5299f26..6b080b4ee2 100644 --- a/lib/OpenLayers/Handler/Path.js +++ b/lib/OpenLayers/Handler/Path.js @@ -48,17 +48,20 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { * Create a new path hander * * Parameters: - * control - {} - * callbacks - {Object} An object with a 'done' property whos value is a - * function to be called when the path drawing is finished. The - * callback should expect to recieve a single argument, the line - * string geometry. If the callbacks object contains a 'point' - * property, this function will be sent each point as they are added. - * If the callbacks object contains a 'cancel' property, this function - * will be called when the handler is deactivated while drawing. The - * cancel should expect to receive a geometry. + * control - {} The control that owns this handler + * callbacks - {Object} An object with a properties whose values are + * functions. Various callbacks described below. * options - {Object} An optional object with properties to be set on the * handler + * + * Named callbacks: + * done - Called when the point drawing is finished. The callback will + * recieve a single argument, the linestring geometry. + * point - Called as each point is added. Receives the new point geometry. + * modify - Called with each move of a vertex with the vertex (point) + * geometry and the sketch feature. + * cancel - Called when the handler is deactivated while drawing. The + * cancel callback will receive a geometry. */ initialize: function(control, callbacks, options) { OpenLayers.Handler.Point.prototype.initialize.apply(this, arguments); @@ -67,12 +70,19 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { /** * Method: createFeature * Add temporary geometries + * + * Parameters: + * pixel - {} The initial pixel location for the new + * feature. */ - createFeature: function() { - this.line = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.LineString()); + createFeature: function(pixel) { + var lonlat = this.control.map.getLonLatFromPixel(pixel); this.point = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point()); + new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) + ); + this.line = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.LineString([this.point.geometry]) + ); this.layer.addFeatures([this.line, this.point], {silent: true}); }, @@ -86,12 +96,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { }, /** - * Method: destroyPoint + * Method: removePoint * Destroy the temporary point. */ - destroyPoint: function() { + removePoint: function() { if(this.point) { - this.layer.destroyFeatures([this.point]); + this.layer.removeFeatures([this.point]); } }, @@ -99,11 +109,22 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { * Method: addPoint * Add point to geometry. Send the point index to override * the behavior of LinearRing that disregards adding duplicate points. + * + * Parameters: + * pixel - {} The pixel location for the new point. */ - addPoint: function() { - this.line.geometry.addComponent(this.point.geometry.clone(), - this.line.geometry.components.length); + addPoint: function(pixel) { + this.layer.removeFeatures([this.point]); + var lonlat = this.control.map.getLonLatFromPixel(pixel); + this.point = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) + ); + this.line.geometry.addComponent( + this.point.geometry, this.line.geometry.components.length + ); this.callback("point", [this.point.geometry, this.getGeometry()]); + this.callback("modify", [this.point.geometry, this.getSketch()]); + this.drawFeature(); }, /** @@ -121,14 +142,20 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { /** * Method: modifyFeature * Modify the existing geometry given the new point + * + * Parameters: + * pixel - {} The updated pixel location for the latest + * point. */ - modifyFeature: function() { - var index = this.line.geometry.components.length - 1; - this.line.geometry.components[index].x = this.point.geometry.x; - this.line.geometry.components[index].y = this.point.geometry.y; - this.line.geometry.components[index].clearBounds(); + modifyFeature: function(pixel) { + var lonlat = this.control.map.getLonLatFromPixel(pixel); + this.point.geometry.x = lonlat.lon; + this.point.geometry.y = lonlat.lat; + this.callback("modify", [this.point.geometry, this.getSketch()]); + this.point.geometry.clearBounds(); + this.drawFeature(); }, - + /** * Method: drawFeature * Render geometries on the temporary layer. @@ -138,6 +165,17 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { this.layer.drawFeature(this.point, this.style); }, + /** + * Method: getSketch + * Return the sketch feature. + * + * Returns: + * {} + */ + getSketch: function() { + return this.line; + }, + /** * Method: getGeometry * Return the sketch geometry. If is true, this will return @@ -174,18 +212,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { if(this.persist) { this.destroyFeature(); } - this.createFeature(); + this.createFeature(evt.xy); + } else if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { + this.addPoint(evt.xy); } this.mouseDown = true; this.lastDown = evt.xy; - var lonlat = this.control.map.getLonLatFromPixel(evt.xy); - this.point.geometry.x = lonlat.lon; - this.point.geometry.y = lonlat.lat; - this.point.geometry.clearBounds(); - if((this.lastUp == null) || !this.lastUp.equals(evt.xy)) { - this.addPoint(); - } - this.drawFeature(); this.drawing = true; return false; }, @@ -203,16 +235,11 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { */ mousemove: function (evt) { if(this.drawing) { - var lonlat = this.map.getLonLatFromPixel(evt.xy); - this.point.geometry.x = lonlat.lon; - this.point.geometry.y = lonlat.lat; - this.point.geometry.clearBounds(); if(this.mouseDown && this.freehandMode(evt)) { - this.addPoint(); + this.addPoint(evt.xy); } else { - this.modifyFeature(); + this.modifyFeature(evt.xy); } - this.drawFeature(); } return true; }, @@ -232,13 +259,11 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { this.mouseDown = false; if(this.drawing) { if(this.freehandMode(evt)) { - if(this.persist) { - this.destroyPoint(); - } + this.removePoint(); this.finalize(); } else { if(this.lastUp == null) { - this.addPoint(); + this.addPoint(evt.xy); } this.lastUp = evt.xy; } @@ -262,9 +287,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { if(!this.freehandMode(evt)) { var index = this.line.geometry.components.length - 1; this.line.geometry.removeComponent(this.line.geometry.components[index]); - if(this.persist) { - this.destroyPoint(); - } + this.removePoint(); this.finalize(); } return false; diff --git a/lib/OpenLayers/Handler/Point.js b/lib/OpenLayers/Handler/Point.js index 995577a50a..c70124abce 100644 --- a/lib/OpenLayers/Handler/Point.js +++ b/lib/OpenLayers/Handler/Point.js @@ -11,9 +11,11 @@ /** * Class: OpenLayers.Handler.Point * Handler to draw a point on the map. Point is displayed on mouse down, - * moves on mouse move, and is finished on mouse up. The handler triggers - * callbacks for 'done' and 'cancel'. Create a new instance with the - * constructor. + * moves on mouse move, and is finished on mouse up. The handler triggers + * callbacks for 'done', 'cancel', and 'modify'. The modify callback is + * called with each change in the sketc and will receive the latest point + * drawn. Create a new instance with the + * constructor. * * Inherits from: * - @@ -84,19 +86,23 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { * * Parameters: * control - {} The control that owns this handler - * callbacks - {Object} An object with a 'done' property whose value is a - * function to be called when the point drawing is finished. - * The callback should expect to recieve a single argument, - * the point geometry. If the callbacks object contains a - * 'cancel' property, this function will be called when the - * handler is deactivated while drawing. The cancel should - * expect to receive a geometry. + * callbacks - {Object} An object with a properties whose values are + * functions. Various callbacks described below. * options - {Object} An optional object with properties to be set on the * handler + * + * Named callbacks: + * done - Called when the point drawing is finished. The callback will + * recieve a single argument, the point geometry. + * modify - Called with each move of a vertex with the vertex (point) + * geometry and the sketch feature. + * cancel - Called when the handler is deactivated while drawing. The + * cancel callback will receive a geometry. */ initialize: function(control, callbacks, options) { - // TBD: deal with style - this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); + if(!(options && options.layerOptions && options.layerOptions.styleMap)) { + this.style = OpenLayers.Util.extend(OpenLayers.Feature.Vector.style['default'], {}); + } OpenLayers.Handler.prototype.initialize.apply(this, arguments); }, @@ -231,6 +237,21 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { return false; }, + /** + * Method: modifyFeature + * Modify the existing geometry given a pixel location. + * + * Parameters: + * pixel - {} A pixel location on the map. + */ + modifyFeature: function(pixel) { + var lonlat = this.map.getLonLatFromPixel(pixel); + this.point.geometry.x = lonlat.lon; + this.point.geometry.y = lonlat.lat; + this.callback("modify", [this.point.geometry, this.point]); + this.point.geometry.clearBounds(); + }, + /** * Method: drawFeature * Render features on the temporary layer. @@ -294,10 +315,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { } this.lastDown = evt.xy; this.drawing = true; - var lonlat = this.map.getLonLatFromPixel(evt.xy); - this.point.geometry.x = lonlat.lon; - this.point.geometry.y = lonlat.lat; - this.point.geometry.clearBounds(); + this.modifyFeature(evt.xy); this.drawFeature(); return false; }, @@ -315,10 +333,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { */ mousemove: function (evt) { if(this.drawing) { - var lonlat = this.map.getLonLatFromPixel(evt.xy); - this.point.geometry.x = lonlat.lon; - this.point.geometry.y = lonlat.lat; - this.point.geometry.clearBounds(); + this.modifyFeature(evt.xy); this.drawFeature(); } return true; diff --git a/lib/OpenLayers/Handler/Polygon.js b/lib/OpenLayers/Handler/Polygon.js index 4691398896..468622e240 100644 --- a/lib/OpenLayers/Handler/Polygon.js +++ b/lib/OpenLayers/Handler/Polygon.js @@ -30,18 +30,20 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { * Create a Polygon Handler. * * Parameters: - * control - {} - * callbacks - {Object} An object with a 'done' property whos value is - * a function to be called when the path drawing is - * finished. The callback should expect to recieve a - * single argument, the polygon geometry. - * If the callbacks object contains a 'point' - * property, this function will be sent each point - * as they are added. If the callbacks object contains - * a 'cancel' property, this function will be called when - * the handler is deactivated while drawing. The cancel - * should expect to receive a geometry. - * options - {Object} + * control - {} The control that owns this handler + * callbacks - {Object} An object with a properties whose values are + * functions. Various callbacks described below. + * options - {Object} An optional object with properties to be set on the + * handler + * + * Named callbacks: + * done - Called when the point drawing is finished. The callback will + * recieve a single argument, the polygon geometry. + * point - Called as each point is added. Receives the new point geometry. + * modify - Called with each move of a vertex with the vertex (point) + * geometry and the sketch feature. + * cancel - Called when the handler is deactivated while drawing. The + * cancel callback will receive a geometry. */ initialize: function(control, callbacks, options) { OpenLayers.Handler.Path.prototype.initialize.apply(this, arguments); @@ -50,15 +52,22 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { /** * Method: createFeature * Add temporary geometries + * + * Parameters: + * pixel - {} The initial pixel location for the new + * feature. */ - createFeature: function() { - this.polygon = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Polygon()); - this.line = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.LinearRing()); - this.polygon.geometry.addComponent(this.line.geometry); + createFeature: function(pixel) { + var lonlat = this.control.map.getLonLatFromPixel(pixel); this.point = new OpenLayers.Feature.Vector( - new OpenLayers.Geometry.Point()); + new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat) + ); + this.line = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.LinearRing([this.point.geometry]) + ); + this.polygon = new OpenLayers.Feature.Vector( + new OpenLayers.Geometry.Polygon([this.line.geometry]) + ); this.layer.addFeatures([this.polygon, this.point], {silent: true}); }, @@ -71,18 +80,6 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { this.polygon = null; }, - /** - * Method: modifyFeature - * Modify the existing geometry given the new point - * - */ - modifyFeature: function() { - var index = this.line.geometry.components.length - 2; - this.line.geometry.components[index].x = this.point.geometry.x; - this.line.geometry.components[index].y = this.point.geometry.y; - this.line.geometry.components[index].clearBounds(); - }, - /** * Method: drawFeature * Render geometries on the temporary layer. @@ -92,6 +89,17 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { this.layer.drawFeature(this.point, this.style); }, + /** + * Method: getSketch + * Return the sketch feature. + * + * Returns: + * {} + */ + getSketch: function() { + return this.polygon; + }, + /** * Method: getGeometry * Return the sketch geometry. If is true, this will return @@ -121,9 +129,7 @@ OpenLayers.Handler.Polygon = OpenLayers.Class(OpenLayers.Handler.Path, { // remove the penultimate point var index = this.line.geometry.components.length - 2; this.line.geometry.removeComponent(this.line.geometry.components[index]); - if(this.persist) { - this.destroyPoint(); - } + this.removePoint(); this.finalize(); } return false; diff --git a/tests/Handler/Path.html b/tests/Handler/Path.html index 408aca933d..b81b7634ce 100644 --- a/tests/Handler/Path.html +++ b/tests/Handler/Path.html @@ -68,7 +68,78 @@ t.ok(!handler.line.geometry.getBounds().equals(new OpenLayers.Bounds(0,-35.15625,35.15625,0)), "Correct bounds after dragging without letting go. (Came out as "+handler.line.geometry.getBounds().toBBOX() + ".)"); map.destroy(); } + + function test_callbacks(t) { + t.plan(12); + 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 log = {}; + var handler = new OpenLayers.Handler.Path(control, { + modify: function() { + log.type = "modify", + log.args = arguments + }, + done: function() { + log.type = "done", + log.args = arguments + }, + cancel: function() { + log.type = "cancel", + log.args = arguments + } + }); + control.handler = handler; + map.addControl(control); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); + // mock up feature drawing + handler.activate(); + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)}); + handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)}); + 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.line, "[mouseup] correct sketch feature"); + handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 1)}); + t.eq(log.type, "modify", "[mousemove] modify called"); + t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 74), "[mousemove] correct vertex"); + t.ok(log.args[1] === handler.line, "[mousemove] correct sketch feature"); + handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(10, 10)}); + 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.line, "[mousemove] correct sketch feature"); + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)}); + handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)}); + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(10, 10)}); + handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(10, 10)}); + handler.dblclick({type: "dblclick", xy: new OpenLayers.Pixel(10, 10)}); + t.eq(log.type, "done", "[dblclick] done called"); + t.geom_eq( + log.args[0], + new OpenLayers.Geometry.LineString([ + new OpenLayers.Geometry.Point(-150, 75), + new OpenLayers.Geometry.Point(-140, 65) + ]), + "[dblclick] correct linestring" + ); + + // 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"); + + map.destroy(); + } + function test_Handler_Path_destroy(t) { t.plan(6); var map = new OpenLayers.Map('map'); diff --git a/tests/Handler/Point.html b/tests/Handler/Point.html index 6c3a7477a4..da72b916c9 100644 --- a/tests/Handler/Point.html +++ b/tests/Handler/Point.html @@ -97,6 +97,60 @@ OpenLayers.Event.stop = oldStop; } + + function test_callbacks(t) { + t.plan(10); + 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 log = {}; + var handler = new OpenLayers.Handler.Point(control, { + modify: function() { + log.type = "modify", + log.args = arguments + }, + done: function() { + log.type = "done", + log.args = arguments + }, + cancel: function() { + log.type = "cancel", + log.args = arguments + } + }); + control.handler = handler; + map.addControl(control); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); + + // mock up feature drawing + handler.activate(); + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)}); + t.eq(log.type, "modify", "[mousedown] modify called"); + t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct point"); + t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-150, 75), "[mousedown] correct sketch feature"); + handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(1, 0)}); + t.eq(log.type, "modify", "[mousemove] modify called"); + t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 75), "[mousemove] correct point"); + t.geom_eq(log.args[1].geometry, new OpenLayers.Geometry.Point(-149, 75), "[mousemove] correct sketch feature"); + handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(1, 0)}); + t.eq(log.type, "done", "[mouseup] done called"); + t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-149, 75), "[mouseup] correct point"); + + // mock up feature drawing with a cancel + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)}); + handler.deactivate(); + t.eq(log.type, "cancel", "[deactivate while drawing] cancel called"); + t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75), "[deactivate while drawing] correct point"); + + map.destroy(); + } function test_Handler_Point_deactivation(t) { @@ -121,7 +175,7 @@ map.zoomToMaxExtent(); var control = new OpenLayers.Control(); map.addControl(control); - var handler = new OpenLayers.Handler.Point(control); + var handler = new OpenLayers.Handler.Point(control, {}); var activated = handler.activate(); var px = new OpenLayers.Pixel(150, 75); var evt = {xy: px, which: 1}; diff --git a/tests/Handler/Polygon.html b/tests/Handler/Polygon.html index 9a6293c223..a78b7406f4 100644 --- a/tests/Handler/Polygon.html +++ b/tests/Handler/Polygon.html @@ -71,6 +71,86 @@ map.destroy(); } + function test_callbacks(t) { + t.plan(12); + 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 log = {}; + var handler = new OpenLayers.Handler.Polygon(control, { + modify: function() { + log.type = "modify", + log.args = arguments + }, + done: function() { + log.type = "done", + log.args = arguments + }, + cancel: function() { + log.type = "cancel", + log.args = arguments + } + }); + control.handler = handler; + map.addControl(control); + map.setCenter(new OpenLayers.LonLat(0, 0), 0); + + // mock up feature drawing + handler.activate(); + // click at 0, 0 + handler.mousedown({type: "mousedown", xy: new OpenLayers.Pixel(0, 0)}); + handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(0, 0)}); + 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.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)}); + // move to 0, 10 and double click + handler.mousemove({type: "mousemove", xy: new OpenLayers.Pixel(0, 10)}); + 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.eq(log.type, "done", "[dblclick] done called"); + t.geom_eq( + log.args[0], + new OpenLayers.Geometry.Polygon([ + new OpenLayers.Geometry.LinearRing([ + new OpenLayers.Geometry.Point(-150, 75), + new OpenLayers.Geometry.Point(-140, 65), + new OpenLayers.Geometry.Point(-150, 65), + new OpenLayers.Geometry.Point(-150, 75) + ]) + ]), + "[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"); + + map.destroy(); + } + function test_Handler_Polygon_destroy(t) { t.plan(8); var map = new OpenLayers.Map('map');