[OpenLayers-Users] Measure Distance? Ruler?

Lance Dyas lancelot at inetnebr.com
Wed Aug 22 22:46:08 EDT 2007


You probably already know it but the standard distance code is only 
accurate in EPSG:4326 (LatLon)
and most CRS whose units are degrees it is pretty close as well.

In many/most other projections a linear distance n whatever units the 
CRS uses (almost always meters)
 is probably pretty useable.

something like this.
distLinear = function(a,b){ return Math.sqrt(Math.pow(a,2)+Math.pow(b,2)) }


Lee Keel wrote:
>
> So is there any reason that the following function won't work?  I have been
> using it in my app and it seems to be accurate...  At least as far as I can
> tell.
> //Add a control,
> 	var c = 
>             new OpenLayers.Control.DrawFeature(vlayer,
> OpenLayers.Handler.Path, {'displayClass' : 'olControlDrawFeaturePath'} ); 
>         c.featureAdded = this.measureLine;
>         this.addControls(c);
>
> //function for doing measure 
>     measureLine: function (feature){
>         if(this.lastFeature)
>             vectorLayer.eraseFeatures(this.lastFeature);
>             
>         feature.state = OpenLayers.State.INSERT;
>         
>         printDistance(feature.geometry.getLength());
>         this.lastFeature = feature;
>     },
>   





More information about the Users mailing list