[OpenLayers-Users] Measure Control - get distance on mouse move - part 2

Andreas Hocevar ahocevar at opengeo.org
Wed Apr 22 08:22:40 EDT 2009


Hi,

the solution (if you're using trunk or 2.8) is quite simple. The snippet 
below replaces the definition of measureControls in the measure example 
(starting around L65)

            measureControls = {
                line: new OpenLayers.Control.Measure(
                    OpenLayers.Handler.Path, {
                        callbacks: {
                            modify: function(point, feature) {
                                measureControls.line.measurePartial(point,
                                        feature.geometry);
                            }
                        },
                        persist: true,
                        handlerOptions: {
                            layerOptions: {styleMap: styleMap}
                        }
                    }
                ),
                polygon: new OpenLayers.Control.Measure(
                    OpenLayers.Handler.Polygon, {
                        callbacks: {
                            modify: function(point, feature) {
                                
measureControls.polygon.measurePartial(point,
                                        feature.geometry);
                            }
                        },
                        persist: true,
                        handlerOptions: {
                            layerOptions: {styleMap: styleMap}
                        }
                    }
                )
            };

As you can see, the trick is to add a modify callback to the handler, 
calling the control's measurePartial method.

Regards,
Andreas.

pribram pribram wrote:
> Hi,
> Is there anything new about measuring + getting distance on mousemove?
> http://n2.nabble.com/Measure-Control---get-distance-on-mouse-move-td2503580.html
> If there is a solution, please publish it.
>
> Thanks,
> Pribram
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.




More information about the Users mailing list