[OpenLayers-Dev] lines with only two vertexs
toni hernández
tonidelacalle at gmail.com
Thu Mar 26 04:08:38 EDT 2009
hi Tim,
Thanks for the answer.
An error still keeps appearing. I think there are some events still going on
that throw this error. (mousedown?)
any ideas?
This is what I get from firebug.
this.layer is null
drawFeature()()Path.js (línea 164)
addPoint()(x=429,y=223 x=429 y=223 CLASS_NAME=OpenLayers.Pixel)Path.js
(línea 127)
mousedown()(mousedown clientX=448, clientY=293)Path.js (línea 217)
triggerEvent()("mousedown", mousedown clientX=448, clientY=293)Events.js
(línea 714)
handleBrowserEvent()(mousedown clientX=448, clientY=293)Events.js (línea
742)
bindAsEventListener()(mousedown clientX=448, clientY=293)BaseTypes.js (línea
432)
this.layer.drawFeature(this.line, this.style);
On Wed, Mar 25, 2009 at 9:16 PM, Tim Schaub <tschaub at opengeo.org> wrote:
> Hey-
>
> toni hernández wrote:
> > Hi all,
> >
> > I need to draw lines with only two vertexs so when the second vertex is
> > added the draing must end.
> >
>
> If you want to use the existing code, your application could do
> something like this (assuming you had a vector layer named "layer" and a
> drawing control named "draw" with a path handler configured to draw on
> that layer):
>
> // using API properties and methods only
>
> layer.events.on({
> sketchmodified: function(event) {
> var feature = event.feature;
> if(feature.geometry.components.length > 2) {
> feature = feature.clone();
> var geom = feature.geometry;
> geom.removeComponent(geom.component[2]);
> draw.deactivate();
> layer.addFeatures([feature]);
> }
> }
> });
>
> Untested, but something like that should work.
>
> Tim
>
> >
> > 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();
> > }
> > }
> >
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Dev mailing list
> > Dev at openlayers.org
> > http://openlayers.org/mailman/listinfo/dev
>
>
> --
> Tim Schaub
> OpenGeo - http://opengeo.org
> Expert service straight from the developers.
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20090326/8ad0b2ac/attachment.html
More information about the Dev
mailing list