[OpenLayers-Commits] r11097 - in sandbox/elemoine/draw-feature:
lib/OpenLayers/Handler tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Feb 10 14:59:31 EST 2011
Author: erilem
Date: 2011-02-10 11:59:31 -0800 (Thu, 10 Feb 2011)
New Revision: 11097
Modified:
sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js
sandbox/elemoine/draw-feature/tests/Handler/Path.html
sandbox/elemoine/draw-feature/tests/Handler/Point.html
sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
Log:
drawing handlers - in deactivate handle the where the layer is already destroyed
Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js 2011-02-10 19:28:39 UTC (rev 11096)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Path.js 2011-02-10 19:59:31 UTC (rev 11097)
@@ -165,12 +165,13 @@
* Parameters:
* pixel - {<OpenLayers.Pixel>} The updated pixel location for the latest
* point.
+ * drawing - {Boolean} Indicate if we're currently drawing.
*/
- modifyFeature: function(pixel) {
+ modifyFeature: function(pixel, drawing) {
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.callback("modify", [this.point.geometry, this.getSketch(), drawing]);
this.point.geometry.clearBounds();
this.drawFeature();
},
@@ -254,7 +255,7 @@
this.addPoint(evt.xy);
return false;
}
- this.modifyFeature(evt.xy);
+ this.modifyFeature(evt.xy, !!this.lastUp);
return true;
},
Modified: sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js 2011-02-10 19:28:39 UTC (rev 11096)
+++ sandbox/elemoine/draw-feature/lib/OpenLayers/Handler/Point.js 2011-02-10 19:59:31 UTC (rev 11097)
@@ -170,13 +170,14 @@
if(!OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) {
return false;
}
- this.cancel();
+ this.cancel(true);
// 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.layer.destroy(false);
}
this.layer = null;
@@ -212,8 +213,10 @@
* 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.
*/
- finalize: function(cancel) {
+ finalize: function(cancel, noNew) {
var key = cancel ? "cancel" : "done";
this.drawing = false;
this.mouseDown = false;
@@ -223,7 +226,7 @@
if(cancel || !this.persist) {
this.destroyFeature();
}
- if(!cancel) {
+ if(!noNew) {
this.createFeature();
}
},
@@ -231,9 +234,13 @@
/**
* 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() {
- this.finalize(true);
+ cancel: function(noNew) {
+ this.finalize(true, noNew);
},
/**
@@ -279,7 +286,7 @@
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.callback("modify", [this.point.geometry, this.point, false]);
this.point.geometry.clearBounds();
this.drawFeature();
},
Modified: sandbox/elemoine/draw-feature/tests/Handler/Path.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Path.html 2011-02-10 19:28:39 UTC (rev 11096)
+++ sandbox/elemoine/draw-feature/tests/Handler/Path.html 2011-02-10 19:59:31 UTC (rev 11097)
@@ -116,7 +116,7 @@
}
function test_callbacks(t) {
- t.plan(37);
+ t.plan(39);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -248,7 +248,7 @@
"[dblclick] correct feature");
// cancel
handler.cancel();
- t.eq(logs.length, 1, "[cancel] called back");
+ t.eq(logs.length, 2, "[cancel] called back");
log = logs.shift();
t.eq(log.type, "cancel", "[cancel] canced called");
t.geom_eq(log.args[0],
@@ -257,7 +257,11 @@
]),
"[cancel] correct linestring"
);
-
+ log = logs.shift();
+ t.eq(log.type, "create", "[cancel] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
+
map.destroy();
}
Modified: sandbox/elemoine/draw-feature/tests/Handler/Point.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Point.html 2011-02-10 19:28:39 UTC (rev 11096)
+++ sandbox/elemoine/draw-feature/tests/Handler/Point.html 2011-02-10 19:59:31 UTC (rev 11097)
@@ -142,7 +142,7 @@
}
function test_callbacks(t) {
- t.plan(23);
+ t.plan(25);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -227,11 +227,15 @@
t.eq(logs.length, 0, "[mouseup] not called back");
// cancel
handler.cancel();
- t.eq(logs.length, 1, "[cancel] called back");
+ t.eq(logs.length, 2, "[cancel] called back");
log = logs.shift();
t.eq(log.type, "cancel", "[cancel] canced called");
t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
"[cancel] correct point");
+ log = logs.shift();
+ t.eq(log.type, "create", "[cancel] create called");
+ t.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
map.destroy();
}
Modified: sandbox/elemoine/draw-feature/tests/Handler/Polygon.html
===================================================================
--- sandbox/elemoine/draw-feature/tests/Handler/Polygon.html 2011-02-10 19:28:39 UTC (rev 11096)
+++ sandbox/elemoine/draw-feature/tests/Handler/Polygon.html 2011-02-10 19:59:31 UTC (rev 11097)
@@ -109,7 +109,7 @@
}
function test_callbacks(t) {
- t.plan(36);
+ t.plan(38);
var map = new OpenLayers.Map("map", {
resolutions: [1]
});
@@ -262,9 +262,13 @@
"[dblclick] correct feature");
// cancel
handler.cancel();
- t.eq(logs.length, 1, "[cancel] called back");
+ t.eq(logs.length, 2, "[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.geom_eq(log.args[0], new OpenLayers.Geometry.Point(-200, 125),
+ "[cancel] correct point");
map.destroy();
}
More information about the Commits
mailing list