1

I have been using separate buttons to measure lines and areas in my Openlayers maps (as per the Openlayers examples) but would ideally like to get the output for both length and area at the same time. The ideal solution would be to have a solid line for the line measurements and a dashed line connecting the start and end point to symbolize the polygon. Then simply output the two answers to a div on the website. As a bonus, store each line length in an array that can be output to a menu as well.

My question is two fold, is it possible, and does anyone have / know of an example? I've searched long and hard and can't find an attractive solution to this.

Thanks for your help,

0

This is a really specific demand so I doubt you will find an example that does exactly that. Your safest bet would be to extend OpenLayers.Control.Measure to do exactly what you want. It would take me some time to provide a working example so I'll let you do it, but you could do something like:

  • Use the Measure tool to measure line
  • Extend the class so it creates a polygon when you add a node (see the measurePartial function)
  • Extend the measure function to send the length and area in the event or send 2 events if you prefer

Same thing to return the length of each line segment.

  • Thank you for the answer. I'm not 100% sure how to go about this, but following your bullet points certainly points me in the right direction. If I get something I'll try to update with an example. – Phill Dec 4 '13 at 14:34
  • Following your suggestion, I have managed to draw a line and polygon and get instant measurements by invoking 2 measure controls, but only the last control is finished when double clicking, rendering it all useless. – Phill Dec 6 '13 at 11:46
  • The key will be to have a single extended Measure Class that does both behavior in the same control. You will need to modify the measurePartial function for that. – Julien-Samuel Lacroix Dec 6 '13 at 15:50

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.