Select to view content in your preferred language

measurment tool

2484
5
01-18-2011 01:31 PM
DrewDowling
Frequent Contributor
Has anybody created a measure tool in Flex? All the sample I can see add the length of the graphic as a label after the draw tool has finished drawing. I need the user to be able to see the length of a polyline as they are moving the mouse to create it. I have looked at the drawing toolbar events but all I can see are start drawing and end drawing, no way to get to the graphic that is actually being created.

Any help or suggestions greatly appreciated.
Tags (2)
0 Kudos
5 Replies
MehulChoksey
Esri Contributor
You can get hold of the graphic being currently drawn by the DrawTool by graphic property of the DrawStart event.
0 Kudos
Drew
by
Frequent Contributor

I need the user to be able to see the length of a polyline as they are moving the mouse to create it.

The draw and measure widget provided with the ESRI Flex Viewer 2.2 uses the Geometry service to calculate the measurements. If you want to calculate the measurements live as the user moves the mouse you will have to come up with all the math required to determine the distance on the client side. This can be done (as it was in the ArcIMS days) but it might be tricky and may not be as accurate.
0 Kudos
DrewDowling
Frequent Contributor
Thanks for your help guys.

I've figured out how to get the coordinates in real time using the mouse move event and I tried to do the calculations to get distance. I was using good old Pythagoras, d= �??(x2 - x1)² + (y2 - y1)² but it doesn't appear to be accurate enough and my distances are always several meters too large.

Does anybody have a more accurate formula? I'm sure it will involve lots of high school trigonometry that I have long since forgotten but if anybody has any pointers please let me know.

Thanks again
0 Kudos
Drew
by
Frequent Contributor
I would dig around ArcScripts for some old ArcIMS code or just search under the JavaScript category for the word "measure" http://arcscripts.esri.com/
Then email the author to see if they don't mind you converting some of their code to Actionscript - they might want some sort of reference or credit mentioned in the code.

Drew
0 Kudos
DrewDowling
Frequent Contributor
Andrew

Just an FYI and for the sake of anybody else coming across this thread.

I figured out why I'm getting inaccurate measurements when I do my calculations and it should have been obvious. It is because the map service I'm measureing against is Web Mercator projection which is horrible for distance distortions, especially at higher latitudes. Continuously reprojecting a polyline as it's drawn is not practical so I'm kind of cheating and using an approximate distortion scale of 20%. It's crude but it seems to work so far.

I'm sure somebody has worked out a formula for my latitude I sure but I can't find it.

Thanks
0 Kudos