[OpenLayers-Commits] r12046 - in trunk/openlayers: examples
lib/OpenLayers/Handler tests/Control tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Jun 6 03:12:53 EDT 2011
Author: erilem
Date: 2011-06-06 00:12:52 -0700 (Mon, 06 Jun 2011)
New Revision: 12046
Modified:
trunk/openlayers/examples/measure.html
trunk/openlayers/lib/OpenLayers/Handler/Path.js
trunk/openlayers/lib/OpenLayers/Handler/Point.js
trunk/openlayers/lib/OpenLayers/Handler/Polygon.js
trunk/openlayers/tests/Control/DrawFeature.html
trunk/openlayers/tests/Control/Measure.html
trunk/openlayers/tests/Handler/Path.html
trunk/openlayers/tests/Handler/Point.html
trunk/openlayers/tests/Handler/Polygon.html
Log:
make the drawing handlers create the sketch feature at an appropriate time, when we can actually derive geographic coordinates from a pixel, r=ahocevar (References #3327)
Modified: trunk/openlayers/examples/measure.html
===================================================================
--- trunk/openlayers/examples/measure.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/examples/measure.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -29,6 +29,7 @@
<script src="../lib/OpenLayers.js"></script>
<script type="text/javascript">
var map, measureControls;
+ OpenLayers.Layer.Vector.prototype.renderers = ["SVG2", "VML", "Canvas"];
function init(){
map = new OpenLayers.Map('map');
Modified: trunk/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Path.js 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/lib/OpenLayers/Handler/Path.js 2011-06-06 07:12:52 UTC (rev 12046)
@@ -102,13 +102,10 @@
* feature.
*/
createFeature: function(pixel) {
- var geometry;
- if(pixel) {
- var lonlat = this.map.getLonLatFromPixel(pixel);
- geometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
- } else {
- geometry = new OpenLayers.Geometry.Point();
- }
+ var lonlat = this.map.getLonLatFromPixel(pixel);
+ var geometry = new OpenLayers.Geometry.Point(
+ lonlat.lon, lonlat.lat
+ );
this.point = new OpenLayers.Feature.Vector(geometry);
this.line = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LineString([this.point.geometry])
@@ -121,9 +118,13 @@
/**
* Method: destroyFeature
* Destroy temporary geometries
+ *
+ * Parameters:
+ * force - {Boolean} Destroy even if persist is true.
*/
- destroyFeature: function() {
- OpenLayers.Handler.Point.prototype.destroyFeature.apply(this);
+ destroyFeature: function(force) {
+ OpenLayers.Handler.Point.prototype.destroyFeature.call(
+ this, force);
this.line = null;
},
@@ -193,6 +194,9 @@
* drawing - {Boolean} Indicate if we're currently drawing.
*/
modifyFeature: function(pixel, drawing) {
+ if(!this.line) {
+ this.createFeature(pixel);
+ }
var lonlat = this.control.map.getLonLatFromPixel(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
Modified: trunk/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Point.js 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/lib/OpenLayers/Handler/Point.js 2011-06-06 07:12:52 UTC (rev 12046)
@@ -168,7 +168,6 @@
}, this.layerOptions);
this.layer = new OpenLayers.Layer.Vector(this.CLASS_NAME, options);
this.map.addLayer(this.layer);
- this.createFeature();
return true;
},
@@ -180,13 +179,10 @@
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
*/
createFeature: function(pixel) {
- var geometry;
- if(pixel) {
- var lonlat = this.map.getLonLatFromPixel(pixel);
- geometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
- } else {
- geometry = new OpenLayers.Geometry.Point();
- }
+ var lonlat = this.map.getLonLatFromPixel(pixel);
+ var geometry = new OpenLayers.Geometry.Point(
+ lonlat.lon, lonlat.lat
+ );
this.point = new OpenLayers.Feature.Vector(geometry);
this.callback("create", [this.point.geometry, this.point]);
this.point.geometry.clearBounds();
@@ -201,14 +197,14 @@
if(!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
return false;
}
- this.cancel(true);
+ this.cancel();
// If a layer's map property is set to null, it means that that layer
// isn't added to the map. Since we ourself added the layer to the map
// in activate(), we can assume that if this.layer.map is null it means
// that the layer has been destroyed (as a result of map.destroy() for
// example.
if (this.layer.map != null) {
- this.destroyFeature();
+ this.destroyFeature(true);
this.layer.destroy(false);
}
this.layer = null;
@@ -219,9 +215,12 @@
/**
* Method: destroyFeature
* Destroy the temporary geometries
+ *
+ * Parameters:
+ * force - {Boolean} Destroy even if persist is true.
*/
- destroyFeature: function() {
- if(this.layer) {
+ destroyFeature: function(force) {
+ if(this.layer && (force || !this.persist)) {
this.layer.destroyFeatures();
}
this.point = null;
@@ -243,12 +242,10 @@
* Finish the geometry and call the "done" callback.
*
* Parameters:
- * cancel - {Boolean} Call cancel instead of done callback. Default is
- * false.
- * noNew - {Boolean} Do not create a new feature after
- * finalization. Default is false.
+ * cancel - {Boolean} Call cancel instead of done callback. Default
+ * is false.
*/
- finalize: function(cancel, noNew) {
+ finalize: function(cancel) {
var key = cancel ? "cancel" : "done";
this.drawing = false;
this.mouseDown = false;
@@ -256,24 +253,15 @@
this.lastUp = null;
this.lastTouchPx = null;
this.callback(key, [this.geometryClone()]);
- if(cancel || !this.persist) {
- this.destroyFeature();
- }
- if(!noNew && this.active) {
- this.createFeature();
- }
+ this.destroyFeature(cancel);
},
/**
* APIMethod: cancel
* Finish the geometry and call the "cancel" callback.
- *
- * Parameters:
- * noNew - {Boolean} Do not create a new feature after
- * cancelation. Default is false.
*/
- cancel: function(noNew) {
- this.finalize(true, noNew);
+ cancel: function() {
+ this.finalize(true);
},
/**
@@ -316,6 +304,9 @@
* pixel - {<OpenLayers.Pixel>} A pixel location on the map.
*/
modifyFeature: function(pixel) {
+ if(!this.point) {
+ this.createFeature(pixel);
+ }
var lonlat = this.map.getLonLatFromPixel(pixel);
this.point.geometry.x = lonlat.lon;
this.point.geometry.y = lonlat.lat;
Modified: trunk/openlayers/lib/OpenLayers/Handler/Polygon.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-06-06 07:12:52 UTC (rev 12046)
@@ -75,13 +75,10 @@
* feature.
*/
createFeature: function(pixel) {
- var geometry;
- if(pixel) {
- var lonlat = this.map.getLonLatFromPixel(pixel);
- geometry = new OpenLayers.Geometry.Point(lonlat.lon, lonlat.lat);
- } else {
- geometry = new OpenLayers.Geometry.Point();
- }
+ var lonlat = this.map.getLonLatFromPixel(pixel);
+ var geometry = new OpenLayers.Geometry.Point(
+ lonlat.lon, lonlat.lat
+ );
this.point = new OpenLayers.Feature.Vector(geometry);
this.line = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.LinearRing([this.point.geometry])
@@ -251,9 +248,13 @@
/**
* Method: destroyFeature
* Destroy temporary geometries
+ *
+ * Parameters:
+ * force - {Boolean} Destroy even if persist is true.
*/
- destroyFeature: function() {
- OpenLayers.Handler.Path.prototype.destroyFeature.apply(this);
+ destroyFeature: function(force) {
+ OpenLayers.Handler.Path.prototype.destroyFeature.call(
+ this, force);
this.polygon = null;
},
Modified: trunk/openlayers/tests/Control/DrawFeature.html
===================================================================
--- trunk/openlayers/tests/Control/DrawFeature.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/tests/Control/DrawFeature.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -60,7 +60,7 @@
}
function test_sketch_events(t) {
- t.plan(12);
+ t.plan(11);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -93,12 +93,12 @@
// mock up draw/modify of a point
log = {};
control.activate();
- t.eq(log.sketchstarted.type, "sketchstarted", "[activate] sketchstarted triggered");
- t.ok(isNaN(log.sketchstarted.vertex.x) && isNaN(log.sketchstarted.vertex.y),
- "[activate] correct vertex (NaN)");
+ t.eq(log, {}, "[activate] no event triggered");
log = {};
map.events.triggerEvent("mousemove", {xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(log.sketchstarted.type, "sketchstarted", "[mousemove] sketchstarted triggered");
+ t.geom_eq(log.sketchstarted.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousemove] correct vertex");
t.eq(log.sketchmodified.type, "sketchmodified", "[mousemove] sketchmodified triggered");
t.geom_eq(log.sketchmodified.vertex, new OpenLayers.Geometry.Point(-200, 125), "[mousemove] correct vertex");
@@ -123,9 +123,6 @@
new OpenLayers.Geometry.Point(-190, 115)
]),
"[dblclick] correct geometry");
- t.eq(log.sketchstarted.type, "sketchstarted", "[dblclick] sketchstarted triggered");
- t.ok(isNaN(log.sketchstarted.vertex.x) && isNaN(log.sketchstarted.vertex.y),
- "[dblclick] correct vertex (NaN)");
map.destroy();
}
Modified: trunk/openlayers/tests/Control/Measure.html
===================================================================
--- trunk/openlayers/tests/Control/Measure.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/tests/Control/Measure.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -52,10 +52,9 @@
})
};
+ trigger("mousemove", 0, 0);
// keep a reference to the line being drawn
var line = control.handler.line;
-
- trigger("mousemove", 0, 0);
trigger("mousedown", 0, 0);
trigger("mouseup", 0, 0);
trigger("mousemove", 10, 10);
Modified: trunk/openlayers/tests/Handler/Path.html
===================================================================
--- trunk/openlayers/tests/Handler/Path.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/tests/Handler/Path.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -25,7 +25,7 @@
}
function test_Handler_Path_activation(t) {
- t.plan(12);
+ t.plan(5);
var log = [];
var map = new OpenLayers.Map("map", {
resolutions: [1]
@@ -36,11 +36,7 @@
});
map.addLayer(layer);
var control = new OpenLayers.Control();
- var handler = new OpenLayers.Handler.Path(control, {
- "create": function(g, f) {
- log.push({geometry: g, feature: f});
- }
- });
+ var handler = new OpenLayers.Handler.Path(control, {});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
@@ -57,20 +53,6 @@
"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,
- "acttivates creates a line feature");
- t.ok(handler.line.layer == handler.layer,
- "activate adds the line feature to the layer");
- t.eq(log.length, 1,
- "activate calls \"create\" once");
- t.ok(log[0].geometry == handler.point.geometry,
- "\"create\" called with expected geometry");
- t.ok(log[0].feature == handler.line,
- "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
@@ -105,7 +87,7 @@
}
function test_bounds(t) {
- t.plan(5);
+ t.plan(4);
var geometry;
var map = new OpenLayers.Map('map');
map.addLayer(new OpenLayers.Layer.WMS("", "", {}));
@@ -115,8 +97,6 @@
var handler = new OpenLayers.Handler.Path(control, {},
{stopDown: true, stopUp: true});
var activated = handler.activate();
- t.eq(handler.layer.features.length, 2,
- "There are two features in the layer after activation.");
// click on (150, 75)
var evt = {xy: new OpenLayers.Pixel(150, 75), which: 1};
handler.mousemove(evt);
@@ -150,7 +130,7 @@
}
function test_callbacks(t) {
- t.plan(45);
+ t.plan(39);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -185,20 +165,19 @@
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // create line
handler.activate();
- t.eq(logs.length, 1, "[activate] called back");
- log = logs.shift();
- t.eq(log.type, "create", "[activate] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[activate] initial point");
- t.ok(log.args[1] == handler.line,
- "[activate] correct feature");
+
// mouse move
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(logs.length, 1, "[mousemove] called back");
+ t.eq(logs.length, 2, "[mousemove] called back twice");
log = logs.shift();
+ t.eq(log.type, "create", "[mousemove] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousemove] correct point");
+ t.ok(log.args[1] === handler.line,
+ "[mousemove] correct feature");
+ log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
"[mousemove] correct point");
@@ -279,7 +258,7 @@
// double click
handler.dblclick({type: "dblclick",
xy: new OpenLayers.Pixel(10, 10)});
- t.eq(logs.length, 2, "[dblclick] called back twice");
+ t.eq(logs.length, 1, "[dblclick] called back");
log = logs.shift();
t.eq(log.type, "done", "[dblclick] done called");
t.geom_eq(log.args[0],
@@ -289,24 +268,13 @@
]),
"[dblclick] correct linestring"
);
- log = logs.shift();
- t.eq(log.type, "create", "[dblclick] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[dblclick] initial point");
- t.ok(log.args[1] == handler.line,
- "[dblclick] correct feature");
// cancel
handler.cancel();
- t.eq(logs.length, 2, "[cancel] called back");
+ t.eq(logs.length, 1, "[cancel] called back");
log = logs.shift();
t.eq(log.type, "cancel", "[cancel] canced called");
- t.ok(isNaN(log.args[0].components[0].x) && isNaN(log.args[0].components[0].y),
- "[cancel] initial linestring"
+ t.eq(log.args[0], null, "[cancel] got null"
);
- log = logs.shift();
- t.eq(log.type, "create", "[cancel] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[cancel] initial point");
map.destroy();
}
@@ -379,9 +347,9 @@
handler.activate();
handler.persist = false;
- var feature1 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature1 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -393,9 +361,9 @@
t.ok(feature1.layer == null, "a) feature1 destroyed");
handler.persist = true;
- var feature2 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature2 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -406,9 +374,9 @@
{type: "dblclick", xy: new OpenLayers.Pixel(1, 1)});
t.ok(feature2.layer != null, "b) feature2 not destroyed");
- var feature3 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature3 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -442,9 +410,9 @@
handler.activate();
handler.persist = false;
- var feature1 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature1 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -456,9 +424,9 @@
t.ok(feature1.layer == null, "a) feature1 destroyed");
handler.persist = true;
- feature2 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ feature2 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -469,9 +437,9 @@
{type: "mouseup", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
t.ok(feature2.layer != null, "b) feature2 not destroyed");
- feature3 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ feature3 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -483,9 +451,9 @@
t.ok(feature3.layer != null, "c) feature3 not destroyed");
t.ok(feature2.layer == null, "c) feature2 destroyed");
- feature4 = handler.line;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ feature4 = handler.line;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
handler.mousemove(
Modified: trunk/openlayers/tests/Handler/Point.html
===================================================================
--- trunk/openlayers/tests/Handler/Point.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/tests/Handler/Point.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -25,8 +25,7 @@
}
function test_Handler_Point_activation(t) {
- t.plan(11);
- var log = [];
+ t.plan(6);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -36,11 +35,7 @@
});
map.addLayer(layer);
var control = new OpenLayers.Control();
- var handler = new OpenLayers.Handler.Point(control, {
- "create": function(g, f) {
- log.push({geometry: g, feature: f});
- }
- });
+ var handler = new OpenLayers.Handler.Point(control, {});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
@@ -57,16 +52,6 @@
"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 feature");
- t.ok(handler.point.layer == handler.layer,
- "activate adds the feature to the layer");
- t.eq(log.length, 1,
- "activate calls \"create\" once");
- t.ok(log[0].geometry == handler.point.geometry,
- "\"create\" called with expected geometry");
- t.ok(log[0].feature == handler.point,
- "\"create\" called with expected feature");
activated = handler.deactivate();
t.ok(activated,
"deactivate returns true if the handler was active already");
@@ -176,7 +161,7 @@
}
function test_callbacks(t) {
- t.plan(28);
+ t.plan(24);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -209,18 +194,20 @@
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
- // create point
handler.activate();
- t.eq(logs.length, 1, "[activate] called back");
- log = logs.shift();
- t.eq(log.type, "create", "[activate] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[activate] initial point");
+
// mouse down
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(logs.length, 1, "[mousedown] called back");
+ t.eq(logs.length, 2, "[mousedown] called back twice");
log = logs.shift();
+ t.eq(log.type, "create", "[mousedown] create 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 feature");
+ 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");
@@ -258,29 +245,20 @@
"[mousedown] correct feature");
// mouse up
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
- t.eq(logs.length, 2, "[mouseup] called back twice");
+ t.eq(logs.length, 1, "[mouseup] called back");
log = logs.shift();
t.eq(log.type, "done", "[mouseup] done called");
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-148, 75),
"[mouseup] correct point");
- log = logs.shift();
- t.eq(log.type, "create", "[mouseup] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[mouseup] initial point");
// mouse up on same pixel
handler.mouseup({type: "mouseup", xy: new OpenLayers.Pixel(2, 0)});
t.eq(logs.length, 0, "[mouseup] not called back");
// cancel
handler.cancel();
- t.eq(logs.length, 2, "[cancel] called back");
+ t.eq(logs.length, 1, "[cancel] called back");
log = logs.shift();
- t.eq(log.type, "cancel", "[cancel] canced called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[cancel] initial point");
- log = logs.shift();
- t.eq(log.type, "create", "[cancel] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[] initial point");
+ t.eq(log.type, "cancel", "[cancel] cancel called");
+ t.eq(log.args[0], null, "[cancel] got null");
map.destroy();
}
@@ -308,7 +286,7 @@
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
{type: "mouseup", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(handler.layer.features.length, 1,
+ t.eq(handler.layer.features.length, 0,
"feature destroyed on mouseup when persist is false");
handler.persist = true;
@@ -316,7 +294,7 @@
{type: "mousedown", xy: new OpenLayers.Pixel(1, 0)});
handler.mouseup(
{type: "mouseup", xy: new OpenLayers.Pixel(1, 0)});
- t.eq(handler.layer.features.length, 2,
+ t.eq(handler.layer.features.length, 1,
"feature not destroyed on mouseup when persist is true");
var feature = handler.layer.features[0];
handler.mousedown(
@@ -352,6 +330,7 @@
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
handler.activate();
+ handler.mousemove({xy: new OpenLayers.Pixel(0, 0)});
var _layer = handler.layer;
var _geometry = handler.point.geometry;
handler.deactivate();
@@ -405,6 +384,7 @@
var handler = new OpenLayers.Handler.Point(control, {foo: 'bar'});
handler.activate();
+ handler.mousemove({xy: new OpenLayers.Pixel(150, 75)});
t.ok(handler.layer,
"handler has a layer prior to destroy");
@@ -544,13 +524,11 @@
ret = handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] no finalization');
- t.ok(isNaN(handler.point.geometry.x) && isNaN(handler.point.geometry.y),
- '[touchstart] feature not modified');
+ t.eq(handler.point, null, '[touchstart] feature not modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(1, 0)});
t.ok(ret, '[touchmove] event propagates');
t.eq(log, null, '[touchmove] no finalization');
- t.ok(isNaN(handler.point.geometry.x) && isNaN(handler.point.geometry.y),
- '[touchmove] feature not modified');
+ t.eq(handler.point, null, '[touchmove] feature not modified');
ret = handler.touchend({});
t.ok(ret, '[touchend] event propagates');
t.geom_eq(log.geometry, new OpenLayers.Geometry.Point(-149, 75),
@@ -595,17 +573,17 @@
ret = handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
t.ok(ret, '[touchstart] event propagates');
t.eq(log, null, '[touchstart] no finalization');
- t.ok(isNaN(handler.point.geometry.x) && isNaN(handler.point.geometry.y),
+ t.eq(handler.point, null, null,
'[touchstart] feature not modified');
ret = handler.touchmove({xy: new OpenLayers.Pixel(9, 0)});
t.ok(ret, '[touchmove] event propagates');
t.eq(log, null, '[touchmove] no finalization');
- t.ok(isNaN(handler.point.geometry.x) && isNaN(handler.point.geometry.y),
+ t.eq(handler.point, null,
'[touchmove] feature not modified');
ret = handler.touchend({});
t.ok(ret, '[touchend] event propagates');
t.eq(log, null, '[touchend] no finalization');
- t.ok(isNaN(handler.point.geometry.x) && isNaN(handler.point.geometry.y),
+ t.eq(handler.point, null,
'[touchend] feature not modified');
// tear down
Modified: trunk/openlayers/tests/Handler/Polygon.html
===================================================================
--- trunk/openlayers/tests/Handler/Polygon.html 2011-06-06 06:47:46 UTC (rev 12045)
+++ trunk/openlayers/tests/Handler/Polygon.html 2011-06-06 07:12:52 UTC (rev 12046)
@@ -25,7 +25,7 @@
}
function test_Handler_Polygon_activation(t) {
- t.plan(13);
+ t.plan(5);
var log = [];
var map = new OpenLayers.Map("map", {
resolutions: [1]
@@ -36,11 +36,7 @@
});
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});
- }
- });
+ var handler = new OpenLayers.Handler.Polygon(control, {});
control.handler = handler;
map.addControl(control);
map.setCenter(new OpenLayers.LonLat(0, 0), 0);
@@ -57,22 +53,6 @@
"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.ok(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");
@@ -140,7 +120,7 @@
}
function test_callbacks(t) {
- t.plan(45);
+ t.plan(39);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -178,17 +158,16 @@
// create polygon
handler.activate();
- handler.activate();
- t.eq(logs.length, 1, "[activate] called back");
+
+ handler.mousemove(
+ {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ t.eq(logs.length, 2, "[mousemove] called back");
log = logs.shift();
t.eq(log.type, "create", "[activate] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[activate] initial point");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
+ "[mousemove] correct point");
t.ok(log.args[1] == handler.polygon,
- "[activate] correct feature");
- handler.mousemove(
- {type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
- t.eq(logs.length, 1, "[mousemove] called back");
+ "[mousemove] correct feature");
log = logs.shift();
t.eq(log.type, "modify", "[mousemove] modify called");
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-150, 75),
@@ -287,7 +266,7 @@
// dblclick
handler.dblclick(
{type: "dblclick", xy: new OpenLayers.Pixel(0, 10)});
- t.eq(logs.length, 2, "[dblclick] called back twice");
+ t.eq(logs.length, 1, "[dblclick] called back");
log = logs.shift();
t.eq(log.type, "done", "[dblclick] done called");
t.geom_eq(
@@ -302,21 +281,11 @@
]),
"[dblclick] correct polygon"
);
- log = logs.shift();
- t.eq(log.type, "create", "[dblclick] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[dblclick] initial point");
- t.ok(log.args[1] == handler.polygon,
- "[dblclick] correct feature");
// cancel
handler.cancel();
- t.eq(logs.length, 2, "[cancel] called back");
+ t.eq(logs.length, 1, "[cancel] called back");
log = logs.shift();
t.eq(log.type, "cancel", "[cancel] canced called");
- log = logs.shift();
- t.eq(log.type, "create", "[cancel] create called");
- t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
- "[cancel] initial point");
map.destroy();
}
@@ -389,9 +358,9 @@
handler.activate();
handler.persist = false;
- var feature1 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature1 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -409,9 +378,9 @@
t.ok(feature1.layer == null, "a) feature1 destroyed");
handler.persist = true;
- var feature2 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature2 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -428,9 +397,9 @@
{type: "dblclick", xy: new OpenLayers.Pixel(2, 2)});
t.ok(feature2.layer != null, "b) feature2 not destroyed");
- var feature3 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature3 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0)});
handler.mouseup(
@@ -470,9 +439,9 @@
handler.activate();
handler.persist = false;
- var feature1 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature1 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -484,9 +453,9 @@
t.ok(feature1.layer == null, "a) feature1 destroyed");
handler.persist = true;
- var feature2 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature2 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -497,9 +466,9 @@
{type: "mouseup", xy: new OpenLayers.Pixel(2, 2), shiftKey: true});
t.ok(feature2.layer != null, "b) feature2 not destroyed");
- var feature3 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ var feature3 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: true});
handler.mousemove(
@@ -511,9 +480,9 @@
t.ok(feature3.layer != null, "c) feature3 not destroyed");
t.ok(feature2.layer == null, "c) feature2 destroyed");
- feature4 = handler.polygon;
handler.mousemove(
{type: "mousemove", xy: new OpenLayers.Pixel(0, 0)});
+ feature4 = handler.polygon;
handler.mousedown(
{type: "mousedown", xy: new OpenLayers.Pixel(0, 0), shiftKey: false});
handler.mousemove(
More information about the Commits
mailing list