[GIS] Measure the Length of a Line on a Map after a MOUSE_MOVE Event

apiarcgis-flex-apiflexmap-drawingMeasurements

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.

Best Answer

I want to be able to call this function after a MouseEvent.MOUSE_MOVE event in order to measure the line on the fly

First off, some words of caution. I implemented similar functionality in a Flex app awhile back i.e. When user moved mouse around the map, it kept pinging the geometry service for the distance or xy coordinates and displayed it alongside the cursor.

Issue - The Geometry service could not keep up, and often the lag would result in the label showing the geometry service result would be incorrect, as the mouse had moved on. e.g. You moved the mouse quickly one direction and then another, it would show the XY coordinates from the previous location.

So, I got around this, by only firing a request to the geometry service, once the cursor had not moved for longer than 0.2s. This worked a lot better.

Please refer to the Flex3 mouse events reference or add a listener via AS3 with this reference.

Ill see if I can dig out the code, but not sure if I still have it.

Edit

How to grab the geometry that is being drawn when the event fires

Refer to this sample.
- This shows you how to ping the geometry service with the current geometry of the polyline to get the length.
The listener for this is when the graphic has been finished (onDrawEnd). You just need to modify this to fire when your cursor stops moving.

Few Esri forum posts on this topic as well.

Related Question