[OpenLayers-Dev] lines with only two vertexs

toni hernández tonidelacalle at gmail.com
Wed Mar 25 04:23:53 EDT 2009


Hi all,

I need to draw lines with only two vertexs so when the second vertex is
added the draing must end.


I've done it so far creating a new handler.path where I control the length
of the geometry components. When is bigger than 2 I run the finalize
function so it ends.
That works fine but I think there must be a better way of doing it?

I have also tried registering the sketchmodified event of the control from
the main html page.

The issue here is that I do not know how to deactivate the drawing control
without throwing and error. (feature is null, on Vector.js (line 617, in
drawFeature function)

any ideas?

the code.

//DRAWING CONTROLS
drawControls = {
    point: new OpenLayers.Control.DrawFeature(pointLayer,
        OpenLayers.Handler.Point),
    line: new OpenLayers.Control.DrawFeature(lineLayer,
        OpenLayers.Handler.Path, options),
    polygon: new OpenLayers.Control.DrawFeature(polygonLayer,
        OpenLayers.Handler.Polygon, options)
};

for(var key in drawControls) {
    map.addControl(drawControls[key]);
}

//REGISTERING
drawControls.line.layer.events.on({
    'sketchmodified': report
});


function report(param)
{
    if (param.feature.components.length>2)
    {
        drawControls.line.handler.finalize();
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20090325/2ad0535b/attachment.html


More information about the Dev mailing list