Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw horizontal lines in openLayers?

Tags:

openlayers

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?

like image 991
user731918 Avatar asked Nov 21 '11 20:11

user731918


1 Answers

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.

like image 172
Jeroen Avatar answered Sep 29 '22 18:09

Jeroen