[OpenLayers-Users] Create feature from sketch by imitating a bouble-click event

Andreas Hocevar ahocevar at opengeo.org
Tue Sep 1 17:56:44 EDT 2009


Hi Amit,

why don't you just use a DrawFeature control with a Path handler on a
vector layer and listen to the layer's sketchmodified event, checking
for feature.geometry.components.length?

var layer = new OpenLayers.Layer.Vector("result");
var control = new OpenLayers.Control.DrawFeature(layer,
OpenLayers.Handler.Path);
layer.events.on({
    sketchmodified: function(evt) {
        if(evt.feature.geometry.component.length == 2) {
            control.handler.finalize();
        }
    }
);

You will then have the feature on your layer. Nothing else to do.

Regards,
Andreas.

Amit Andersen wrote:
> Hi All
>
> I wonder if there is a good reason why my post is being ignored.
> Is it to hard or is the problem posted not clear enough?
>
> Mails with different problems have been streaming to my mailbox, and got an
> answer quite fast. Kan someone write back if my post is not answerable in
> some way.. :-)
>
> Thanks
> Amit
>
>
> Amit Andersen wrote:
>   
>> Hi
>>
>> This should be a simple question.
>> I'm working on limiting a path to one single line. What I did was to fire
>> a function on "Point" event. A global var is counting the points created.
>> In this function when the global var is 2, I have an alert which pops up
>> fine.
>>
>> What I want to do instead of the alert, is create the feature from the
>> line sketch on second single-click. Basically imitate a double-click event
>> on the second single-click.
>>
>> This is my DrawFeature control:
>>
>> ...
>> line: new OpenLayers.Control.DrawFeature(vectors, OpenLayers.Handler.Path,
>> {callbacks: { "point": this.TwoClickPath.bind(this) }}),
>> ...
>>
>> And this is the function that is being fired:
>>
>> TwoClickPath: function(e) {
>>     this.TwoClickPathCount++;
>>     if (this.TwoClickPathCount == 2) {
>>         /*
>>             Here I want to create the a feature out of the sketch (which
>> is a single line)
>>         */  
>>         // alert("");  fires ok
>>         controls.line.deactivate();
>>         this.TwoClickPathCount = 0;
>>     }
>> },
>>
>> Thanks in advance for any reply.
>> Amit
>>
>>     
>
>   


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list