[OpenLayers-Users] RE : Measure Control - get distance on mouse move

Josh Rosenthal maric423 at gmail.com
Mon Apr 20 15:37:29 EDT 2009


Hi Ryan,
I realize its a bit late, but I ran into the same need as you've described.
 If you've (or anyone else) has solved it, I'd be curious to see your
solution if you feel like sharing.  My solution is to play with the
handlerOptions to overwrite the modifyFeature method of the path handler.
 For a basic measure demo based off of the example, I'd alter the Control
definition to be roughly as follows:

measurePath = new OpenLayers.Control.Measure(
                      OpenLayers.Handler.Path, {
                        persist: true,
                        handlerOptions: {
modifyFeature: function() {
var index = this.line.geometry.components.length - 1;
this.line.geometry.components[index].x = this.point.geometry.x;
this.line.geometry.components[index].y = this.point.geometry.y;
this.line.geometry.components[index].clearBounds();
this.element.innerHTML=this.line.geometry.getLength().toFixed(2) + "
meters";
},
element: document.getElementById('measureOutput'),
                            layerOptions: {styleMap: styleMap}
                        }
                    }
                );

Similar logic should work for Polygon areas (haven't tried it yet).  I also
want to do it for Circle (Regular poly, ~ 40 sides) radius, which is a bit
trickier, as there is no getRadius function, but calculating that should be
tolerable.  In theory, one should probably include some sort of granularity
check (as per mouseposition) to slow down the obsessive overwriting of
measureOutput, but this does appear to work.  Note that because there is
always a modifyFeature before a click (addPoint), or doubleClick, there is
no need to overwrite the other methods.

As I said, I'm curious to hear any feedback or suggestions on better
solutions.

Thanks,
Josh

On Thu, Mar 19, 2009 at 12:47 PM, RFeagin <
ryan.feagin at peachtreegeographics.com> wrote:

>
> Unless I'm missing something, that looks exactly like what I'm already
> doing
> and gets me an updated distance each time the user clicks to add another
> point to the polyline.  What I'm looking for is to get the distance to the
> current mouse location (without having to click to add the current
> location).  The drawing of the polyline already tracks the cursor location
> because it is drawing the line as you move the mouse.
>
> So the user will click to create the starting point and as they move their
> mouse, the distance will update.  Clicking again will still add another
> point to the polyline.  The only difference is using the current cursor
> location as a 'moving' point at the end of the polyline to give a 'real
> time' distance.
> --
> View this message in context:
> http://n2.nabble.com/Measure-Control---get-distance-on-mouse-move-tp2503580p2504004.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20090420/34071d7c/attachment.html


More information about the Users mailing list