Ticket #3199 (new feature)

Opened 2 years ago

Last modified 20 months ago

Handler.RegularPolygon: Strange behavior

Reported by: jorix Owned by: fredj
Priority: minor Milestone: 2.13 Release
Component: Handler.RegularPolygon Version: SVN
Keywords: Cc:
State: Review

Description

Using http://openlayers.org/dev/examples/regular-polygons.html select "draw polygon" and:

1 Try:

  • keep left mousedown.
  • move
  • right mousedown.
  • release the left mouse button and then the right.
  • Oops!: The blue polygon remains.
  • move and click. Oops! The blue polygon is converted to a final polygon but centered on the click.

2 Try:

  • keep left mousedown.
  • move cursor out the map
  • Oops! the polygon is definitive.

Attachments

3199.patch Download (409 bytes) - added by jorix 2 years ago.
3199.2.patch Download (5.0 KB) - added by jorix 2 years ago.
3199.3.patch Download (5.9 KB) - added by jorix 20 months ago.
Merged with current trunk and changes in tests after [12346]

Change History

Changed 2 years ago by jorix

Changed 2 years ago by jorix

  • state set to Review

attachment:3199.patch Download solves "Try 2". This patch together with patch #3193 also solves the "Try 1".

Please review.

Changed 2 years ago by erilem

  • owner changed from tschaub to sbrunner

Changed 2 years ago by erilem

  • state changed from Review to Commit

Instead of finalizing or canceling the drawing I think we should allow the user to continue drawing when the mouse re-enters the map, and this is the behavior we have with the Point, Path and Polygons handlers. But I agree that canceling leads to a better behavior than finalizing.

I'm confirming that the RegularPolygon tests pass in IE8, and FF4.

Changed 2 years ago by erilem

  • status changed from new to closed
  • resolution set to fixed

(In [11770]) when drawing a regular polygon cancel drawing instead of finalizing when the mouse leaves the map, p=jorix, r=me,sbrunner (closes #3199)

Changed 2 years ago by fredj

  • status changed from closed to reopened
  • resolution fixed deleted

"Try 2" case: when the mouse out of the map, I have the following error:

Uncaught TypeError: Cannot call method 'clone' of null

Changed 2 years ago by fredj

  • owner changed from sbrunner to fredj
  • status changed from reopened to new
  • state changed from Commit to Needs More Work

Changed 2 years ago by fredj

  • state changed from Needs More Work to Review

proposed patch:

Index: lib/OpenLayers/Handler/RegularPolygon.js
===================================================================
--- lib/OpenLayers/Handler/RegularPolygon.js	(revision 11785)
+++ lib/OpenLayers/Handler/RegularPolygon.js	(working copy)
@@ -407,8 +407,11 @@
     callback: function (name, args) {
         // override the callback method to always send the polygon geometry
         if (this.callbacks[name]) {
-            this.callbacks[name].apply(this.control,
-                                       [this.feature.geometry.clone()]);
+            var geom = null;
+            if (this.feature && this.feature.geometry) {
+                geom = this.feature.geometry.clone();
+            }
+            this.callbacks[name].apply(this.control, [geom]);
         }
         // since sketch features are added to the temporary layer
         // they must be cleared here if done or cancel

Changed 2 years ago by erilem

Ok, this patch actually creates new problems, so I'll revert it and set the milestone to 2.12.

Changed 2 years ago by erilem

  • state changed from Review to Needs More Work
  • milestone changed from 2.11 Release to 2.12 Release

Please set it back to 2.11 if you can come with a working patch.

Changed 2 years ago by jorix

Changed 2 years ago by jorix

  • state changed from Needs More Work to Review
  • type changed from bug to feature

NOTE: This ticket only analyzes the problem "2 Try" to a solution of "1 Try" see #3193

This issue is more complex than it seemed to me. For example when the handler is used by SLDSelect control this behavior is acceptable, even preferable (see examples/SLDSelect.html) So this is not strictly a bug.

This would lead to consider two behaviors when "mouseout", to call "done" or "cancel" callbacks. In the patch attachment/3199.2.patch I have incorporated these two behaviors and the proposed code by fredj changed to avoid a call to "done" callback after "cancel" (Handler.Drag can to call "done" callback on "mouseout").

The patch also includes tests and a adjustment in the example.

Changed 20 months ago by jorix

Merged with current trunk and changes in tests after [12346]

Changed 20 months ago by jorix

The introduction of the dummy layer in the  test_callbacks by [12346] forced to change the tests proposed.

Please review 3199.3.patch Download, thanks

Note: See TracTickets for help on using tickets.