One of the actions a user can perform using the ESRI Flex Viewer application is to draw a shape on a map (e.g. a line). Once the user is finished drawing the line, they will double-click the mouse which fires a DrawEvent.DRAW_END event. When this is fired, the line is measured using a call to an API function geometryService.project([geometryObject], spatialReference);
.
I want to be able to call this function after a MouseEvent.MOUSE_MOVE event in order to measure the line on the fly, instead of only after the DRAW_END event. Unfortunately, the only two DrawEvents that get dispatched are the DrawEvent.DRAW_START and DrawEvent.DRAW_END. These ESRI classes are compiled classes, so I cannot make any changes to them.
Is there a way to add an eventListener to a MOUSE_MOVE event that can grab the current geometry of the line that is being drawn and call my API function to measure on the fly?
Thanks in advance.
I found a solution to this problem by circumventing the geometry service altogether and building a solution of my own. There is a great site that implements the Vincenty algorithm for measuring the distance between two coordinates. This is a very accurate approximation algorithm (within .5mm on Vincenty's earth ellipsoid), and is meant to be very efficient so that it can be used frequently (e.g. after a mouse moves).
Here's the basic steps to implement this: