[OpenLayers-Commits] r11745 - in trunk/openlayers:
lib/OpenLayers/Handler tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Tue Mar 29 08:01:01 EDT 2011
Author: erilem
Date: 2011-03-29 05:00:58 -0700 (Tue, 29 Mar 2011)
New Revision: 11745
Modified:
trunk/openlayers/lib/OpenLayers/Handler/Path.js
trunk/openlayers/lib/OpenLayers/Handler/Polygon.js
trunk/openlayers/tests/Handler/Path.html
trunk/openlayers/tests/Handler/Polygon.html
Log:
when zooming out right after drawing a polygon or a line a point appears in the upper left corner, p=jorix, r=me (closes #3196)
Modified: trunk/openlayers/lib/OpenLayers/Handler/Path.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Path.js 2011-03-29 09:54:00 UTC (rev 11744)
+++ trunk/openlayers/lib/OpenLayers/Handler/Path.js 2011-03-29 12:00:58 UTC (rev 11745)
@@ -79,13 +79,14 @@
* feature.
*/
createFeature: function(pixel) {
- if(!pixel) {
- pixel = new OpenLayers.Pixel(-50, -50);
+ 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.control.map.getLonLatFromPixel(pixel);
- this.point = new OpenLayers.Feature.Vector(
- 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])
);
Modified: trunk/openlayers/lib/OpenLayers/Handler/Polygon.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-03-29 09:54:00 UTC (rev 11744)
+++ trunk/openlayers/lib/OpenLayers/Handler/Polygon.js 2011-03-29 12:00:58 UTC (rev 11745)
@@ -75,13 +75,14 @@
* feature.
*/
createFeature: function(pixel) {
- if(!pixel) {
- pixel = new OpenLayers.Pixel(-50, -50);
+ 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.control.map.getLonLatFromPixel(pixel);
- this.point = new OpenLayers.Feature.Vector(
- 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])
);
Modified: trunk/openlayers/tests/Handler/Path.html
===================================================================
--- trunk/openlayers/tests/Handler/Path.html 2011-03-29 09:54:00 UTC (rev 11744)
+++ trunk/openlayers/tests/Handler/Path.html 2011-03-29 12:00:58 UTC (rev 11745)
@@ -67,7 +67,7 @@
"activate adds the line feature to the layer");
t.eq(log.length, 1,
"activate calls \"create\" once");
- t.geom_eq(log[0].geometry, handler.point.geometry,
+ 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");
@@ -78,6 +78,32 @@
map.destroy();
}
+ // See: http://trac.osgeo.org/openlayers/ticket/3179
+ function test_activate_before_map_is_centered(t) {
+ t.plan(1);
+ 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.Path(control, {});
+ control.handler = handler;
+ map.addControl(control);
+
+ var error;
+ try {
+ handler.activate();
+ error = false;
+ } catch(err) {
+ error = true;
+ }
+ t.ok(!error, "no error on activate");
+ }
+
function test_bounds(t) {
t.plan(2);
var geometry;
@@ -159,8 +185,8 @@
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(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
@@ -260,8 +286,8 @@
);
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(isNaN(log.args[0].x) && isNaN(log.args[0].y),
+ "[dblclick] initial point");
t.ok(log.args[1] == handler.line,
"[dblclick] correct feature");
// cancel
@@ -269,16 +295,13 @@
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.LineString([
- new OpenLayers.Geometry.Point(-200, 125)
- ]),
- "[cancel] correct linestring"
+ t.ok(isNaN(log.args[0].components[0].x) && isNaN(log.args[0].components[0].y),
+ "[cancel] initial 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");
+ t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
+ "[cancel] initial point");
map.destroy();
}
Modified: trunk/openlayers/tests/Handler/Polygon.html
===================================================================
--- trunk/openlayers/tests/Handler/Polygon.html 2011-03-29 09:54:00 UTC (rev 11744)
+++ trunk/openlayers/tests/Handler/Polygon.html 2011-03-29 12:00:58 UTC (rev 11745)
@@ -69,7 +69,7 @@
"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,
+ 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");
@@ -80,6 +80,32 @@
map.destroy();
}
+ // See: http://trac.osgeo.org/openlayers/ticket/3179
+ function test_activate_before_map_is_centered(t) {
+ t.plan(1);
+ 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, {});
+ control.handler = handler;
+ map.addControl(control);
+
+ var error;
+ try {
+ handler.activate();
+ error = false;
+ } catch(err) {
+ error = true;
+ }
+ t.ok(!error, "no error on activate");
+ }
+
function test_bounds_stopDown_true(t) {
t.plan(2);
var map = new OpenLayers.Map('map');
@@ -157,8 +183,8 @@
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(isNaN(log.args[0].x) && isNaN(log.args[0].y),
+ "[activate] initial point");
t.ok(log.args[1] == handler.polygon,
"[activate] correct feature");
handler.mousemove(
@@ -279,8 +305,8 @@
);
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(isNaN(log.args[0].x) && isNaN(log.args[0].y),
+ "[dblclick] initial point");
t.ok(log.args[1] == handler.polygon,
"[dblclick] correct feature");
// cancel
@@ -290,8 +316,8 @@
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");
+ t.ok(isNaN(log.args[0].x) && isNaN(log.args[0].y),
+ "[cancel] initial point");
map.destroy();
}
More information about the Commits
mailing list