I am using openlayers and able to draw lines using DrawFeature and OpenLayers.Handler.Path. Now I need to provide an option to be able to draw horizontal/vertical lines. Which means when the user starts drawing line and moves the mouse to an angle, if the angle is less than 45 degrees to the x axis it will draw only horizontal and if the angle is more than 45 degrees it will start drawing vertical lines.
Any ideas on how to do this?
Thats a tricky one. I guess you should somehow combine multiple controls
I would try to draw two hidden vectors at the moment you want to start drawing. One vector for the horizontal axis and one for the vertical. Ofcourse they intersect at your starting point
The actual line you want to draw should snap to one of these vectors. http://dev.openlayers.org/docs/files/OpenLayers/Control/Snapping-js.html
You can take a look at the snapping examples: http://www.openlayers.org/dev/examples/snap-grid.html, http://www.openlayers.org/dev/examples/wfs-snap-split.html
the only difference is that you can only draw 'the grid' if you know the origin. I would start with an example that assumes you do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With