[Mapserver-users] Re: distance measuring with jbox

Richard Greenwood rich at greenwoodmap.com
Wed Jul 14 16:40:55 EDT 2004


Chris Helm wrote:

> Hello Rich,
> 
> My name is Chris Helm and currently I am working for the University of 
> Colorado at Boulder, and more importantly for the National Snow and Ice Data 
> Center within CU's research center.  
> 
> I am using mapserver to create an application that to display the warehouse of 
> information we have here regarding the world's glaciers.  
> 
> The reason for this email is to inquire about how exactly to display the 
> distance my line segments represent in my application.  Everything so far has 
> worked without any problems with this one exception. 
> 
> I have been able to at least get the cursor coords to diplay in my application 
> but need help with converting pixels to real world decimal degrees as well.
> 
> I understand your busy but any help would be very appreciated.
> 
> Thank you 
> 
> Chris Helm
> National Snow and Ice Data Center
> 

You need to calculate the screen pixel size and then multiply the 
distance returned by jBox, which is in screen pixels. So if:
   f = size of screen pixel in real world units
   s = segment length from jBox in screen pixels
real world length = f * s

Mapserver can return the scale in the [SCALE] replaceable parameter. 
This is a ration e.g. 1:24000 based on an assumed screen resolution of 
72 pixels/inch. So if you are in meters:
   1/72/39.97 = 0.0004 meters per screen pixel
and
   f = 0.0004 * [SCALE]

My functions are a little fancy because I round to an appropriate 
resolution and report feet and/or miles based on the length:

var currScale = [scale];
var fpp = ([maxx] - [minx]) / [mapwidth]; // resolution (feet per pixel)

function roundFeet(x) {
    if (fpp < 4)  return (Math.round(x));
    if (fpp < 8)  return (Math.round(x/5)*5);
    if (fpp < 17) return (Math.round(x/10)*10);
    if (fpp < 40) return (Math.round(x/25)*25);
    if (fpp < 80) return (Math.round(x/50)*50);
    return (Math.round(x/100)*100);
}

function distFormat(x) {
    var d;
    if (x > 7920) return ((Math.round(x/5280*10)/10) + " miles");
    d = roundFeet(x);
    if (d > 2640) return (d + " ft (" + (Math.round(x/5280*10)/10) + ") 
mile");
    return (d + " ft");
}

function measure_handler(name, s, t, n) {
    // 1 / 72dpi / 12inches_per_foot * 1.0003state_plane_scale_factor
    var f = currScale * 0.0011577546296296;
    if ((s>0) || (t>0)) {
       document.form1.help.value = "This segment = " + distFormat(s*f) + 
",  Total = " + distFormat(t*f);
    }
}


-- 
Richard Greenwood
www.greenwoodmap.com



More information about the mapserver-users mailing list