2

I have a DrawFeature control that I want use to draw a line between two features (on a separate layer from the lines). I use a Snapping control to snap the cursor to the features.

Any ideas on how can the drawing be limited so that it only allows to end the line on a feature?

Illustration (O represents a feature):

O---O allowed
O---  not allowed
 ---  not allowed
0
1

When drawing of the line is completed (or on end of every segment) check to see if it intersects with a feature, and in your case it should intersect with 2 features. Unless it can loop back onto the same feature and touch it twice. And you can do additional checks to make sure the intersecting feature is a Polygon and not another line...or whatever other rules you have to suffice.

1

A poor man's way of doing this could be to turn the resolution up quite high, larger than the on screen pixels in the map, and play with the greedy flag, so that it always snaps to something.

Otherwise you just leave it as is, but have a function triggered after each new line is draw which checks if it is good and removes it if it isn't touching two features.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.