[OpenLayers-Dev] 2.11 sketchstarted - new event?

Richard Greenwood richard.greenwood at gmail.com
Thu Mar 8 12:51:40 EST 2012

On Thu, Mar 8, 2012 at 10:15 AM, Eric Lemoine
<eric.lemoine at camptocamp.com> wrote:
> On Thu, Mar 8, 2012 at 6:00 PM, Richard Greenwood
> <richard.greenwood at gmail.com> wrote:
>> Earlier this week there was discussion about the 2.11 change in
>> behavior of the of the sketchstarted event.
>> http://osgeo-org.1560.n6.nabble.com/2-11-SketchStarted-td4550864.html
>> Some of us were relying on that event to detect when the first vertex
>> was added to a path or polygon. Eric Lemoine suggested a workaround
>> that is okay with callbacks, but not so good with LAYER.events.on().
>> How about a new event 'firstvertexadded' that does what sketchstarted
>> did before 2.11?
> If someone can do a pull request introducing a sketchcreated event
> type as I described it in the previous thread, I can review it and
> merge it into master (or 2.12 branch). The patch would basically
> involve (a) replacing the current sketchstarted event by
> sketchcreated, and (b) triggering sketchstarted when the first vertex
> is added (and (c) adding tests, and making sure they pass in multiple
> browsers!).
> Thanks.
> --
> Eric Lemoine


1. Your suggested approach:

callbacks: {
        point: function(point, line) {
            if (line.components.length == 2) {
                // user has actually started to draw,
                // and "point" is the first draw point

Would need to be modified for polygons something like:
   polygon.components[0].components.length == 3
and that still doesn't account for multi-polygon objects.

2. I tried to implement your method in an event handler registered to
a vector layer. I used the 'sketchmodified' event as follows:
if (event.type == 'sketchmodified' &&
event.feature.geometry.components[0].components.length == 3 )
but this continues to evaluate true until the next vertex is created.

Best regards,

Richard Greenwood
richard.greenwood at gmail.com

More information about the Dev mailing list