Ticket #1945 (closed feature: fixed)

Opened 4 years ago

Last modified 4 years ago

Add extra sketch and figure events to classes to increase drawing capabilities

Reported by: openlayers Owned by: tschaub
Priority: minor Milestone: 2.8 Release
Component: Layer.Vector Version: SVN
Keywords: Cc: john.diss@…
State: Complete

Description

These would allow the developer to hook events such as: * sketchstarted - the very first vertex of a new shape or mouse down with the Drag or RegularPolygon handler * sketchbeginfigure - a new shape is being drawn, fired everytime a shape is started either by a Drag/RegularPolygon Handler or by DrawFeature control * sketchfigurecomplete - called when the Drag or RegularPolgon mouse up event occurs or the DrawFeature control creates its target geometry. Impacts the following classes: Layer.Vector, Control.DrawFeature, Handler.Drag, Handler.RegularPolygon.

Possible use case: Only allow one feature at a time to be drawn on a vector layer. When the next figure starts clear the features ready for the new one.

Attached patch targets svn revision 8870 Submitted by John Diss (CCLIA: Newgrove Consultants Limited)

Attachments

OpenLayersExtraSketchAndDrawingEvents.patch Download (40.3 KB) - added by openlayers 4 years ago.
Patches file mentioned in ticket and adds mentioned events
OpenLayersExtraSketchAndDrawingEventsNoWhitespaceChanges.patch Download (7.8 KB) - added by john_diss 4 years ago.
Updated patch - haven't changed sketch started behavior but have reduced the whitespace mashup.. jd
1945.patch Download (15.6 KB) - added by tschaub 4 years ago.
add a sketchstarted event to the vector layer

Change History

Changed 4 years ago by openlayers

Patches file mentioned in ticket and adds mentioned events

Changed 4 years ago by tschaub

Thanks for the patch. It would be great to have a version without all of the whitespace changes.

Can you describe the purpose for sketchbeginfigure and how it is different than sketchstarted?

Changed 4 years ago by john_diss

Hi tschaub, sorry i didnt make it clear originally. Sketchstarted was intended to be fired jsut before the first vertex of the first shape is added to a layer so it will only be fired once per vector layer (though in the patch it is the first vertex of the first shape from each DrawFeature control i.e each tool targeting the same layer will raise the event once). Sketchbeginfigure on the other hand is fired before the first vertex of each new (drawn) shape is added. Hopefully this clarifies things. I will try and get a new patch to you soon minus the whitepace changes and with a correct implementation of sketchstarted. cheers jd

Changed 4 years ago by crschmidt

  • state set to Needs More Work

Changed 4 years ago by crschmidt

  • owner changed from crschmidt to tschaub

Changed 4 years ago by tschaub

  • status changed from new to assigned

Changed 4 years ago by john_diss

Updated patch - haven't changed sketch started behavior but have reduced the whitespace mashup.. jd

Changed 4 years ago by tschaub

Thanks for the patch John. I'm changing things here a fair bit in favor of consistency. I'll explain my new patch below. Hope they meet your needs. First, a few comments on your patch:

The drag handler is used for more than drawing. It doesn't feel appropriate to have sketch related callbacks (beginfigure and figurecompleted) there.

The name sketchstarted is clear to me. It is a nice compliment to sketchmodified and sketch complete. I can imagine that for each feature drawn, the sequence would go: sketchstarted, sketchmodified*, sketchcomplete. For a point, sketchmodified would only be triggered if dragged while down. For other geometry types, sketchmodified could be called many times. For each sketchstarted, there would be one sketchcomplete.

The sketchbeginfigure and sketchfigurecomplete confuse me still. The docs you added don't help resolve that confusion. The sketchstarted event should be triggered when each new sketch feature is started. I don't get the difference between that and sketchbeginfigure. Apologies if I'm being dense. Same for sketchcomplete. It is called when each sketch feature is complete. Not sure how that differs from sketchfigurecomplete.

A really nice way to demonstrate what your change does is to include tests (and example if appropriate). I appreciate that the sketch handler and draw control tests are pretty twisted, but at least the callback and event sections should be pretty easy to crib from.

Hope these comments make sense.

Changed 4 years ago by tschaub

add a sketchstarted event to the vector layer

Changed 4 years ago by tschaub

  • state changed from Needs More Work to Review

I've attached a 1945.patch that adds support for a sketchstarted event on the vector layer.

Here's what the patch does:

  • The DrawFeature.html tests are modified to show that a listener for sketchstarted gets called on mousedown when a sketch is being drawn.
  • The Point.html, Path.html, and Polygon.html tests are modified to show that controls that have a named create callback will get called when the sketch handler detects a mousedown. The Point handler previously called the modify callback on mousedown. To be consistent with other sketch handlers create is called on mousedown, modify is called on mousemove, and done is called on mouseup or dblclick depending.
  • The DrawFeature.js code is modified so the control sends a create callback to the sketch handler that triggers the sketchstarted event on the layer.
  • The new sketchstarted event is added and documented in Vector.js.
  • The Point.js, Path.js, and Polygon.js code is modified to call the create callback on the control with the same signature as the modify callback. The Point.js changes are more significant because previously modify was called on mousedown. As mentioned above, things are more consistent with create being called on mousedown.
  • The RegularPolygon.js code is modified to call the named create callback on the control with the appropriate signature. The effect is that sketchstarted will be triggered on the layer when the sketch is started. The sketchmodified event is not currently triggered when drawing a regular polygon. I don't use the regular polygon handler enough to make time for more modifications and test writing there.
  • Finally, the modify-feature.html example is updated to report the new sketchstarted event (and sketchmodified). By running that example, you can see the sequence of events for each sketch type.

Tests pass and examples work in FF3 and IE6. Thanks for any review.

Changed 4 years ago by ahocevar

  • owner changed from tschaub to ahocevar
  • status changed from assigned to new

Changed 4 years ago by ahocevar

  • state changed from Review to Commit

This looks very consistent and useful to me. It also satisfies the use case mentioned in the ticket description. Please commit.

Changed 4 years ago by ahocevar

  • owner changed from ahocevar to tschaub

Changed 4 years ago by tschaub

  • keywords Vector, Drag, DrawFeature, RegularPolygon, sketch removed
  • status changed from new to closed
  • state changed from Commit to Complete
  • resolution set to fixed

(In [9269]) Adding a 'sketchstarted' event on the vector layer. This event is triggered at the start of each new sketch. r=ahocevar (closes #1945)

Changed 4 years ago by john_diss

Works like a charm. Thanks all. jd

Note: See TracTickets for help on using tickets.