Mapunits in template

Steven Monai stevem at SPATIALMAPPING.COM
Thu Sep 8 10:44:10 EDT 2005


Berend:

To paraphrase your question: You want to be able to express the mapfile's
UNITS parameter in the body of the HTML page emitted by the CGI, so you can
pick up its value with client-side Javascript. You have probably found that
there is no [units] tag, or any variation thereof, that you can use in your
templates for this purpose. But here's a (less than optimal) workaround:
Put your units in the METADATA section of the mapfile's WEB block, e.g.

WEB
  ...
  METADATA
    ...
    "units"  "meters"
  END # of METADATA
END # of WEB

Of course, now you have UNITS mentioned twice in your mapfile, with all the
perils and pitfalls that can bring. But it is a workaround, because you can
now refer to the METADATA "units" parameter in your template file as
[web_units], e.g.:

<form name="mapform" method="POST" action="/cgi-bin/mapserv">
  ...
  <input type="hidden" name="units" value="[web_units]" />
  ...
</form>

With the above definitions, your Javascript can get the "units" string with
a simple expression, e.g:

var map_units = document.mapform.units.value;

Hope this helps,
-SM
--




On Thu, 8 Sep 2005 09:23:47 +0200, Berend Veldkamp
<berend.veldkamp at ARIS.NL> wrote:

>listuser HH wrote:
>> Berend Veldkamp wrote:
>>
>>> Hi,
>>>
>>> I'm using mapserver as plain CGI and was wondering if there's a way to
>>> use the "units" parameter of a map in the template file? I need this
>>> to perform client side distance measurements.
>>>
>>> Thanks, Berend
>>>
>> Hi,
>>
>> I don't know if and how you can do that with a template. But what I
>> would do is to use JavaScript. You should be able to make a small script
>> where you calculate the measurement form the extent in map coordinates
>> in reagard to the display coordinates. This only a quick thought but I
>> think it should work.
>>
>> Best Regards,
>> Norbert
>>
>
>
>Norbert,
>
>I think I didn't make myself clear enough... I already have a
>(JavaScript) function to measure distance in meters, feet, degrees, etc.
>
>The problem is that I don't know in advance which units I should use. At
>this moment I've hard-coded the correct units in my template file, but
>I'd like the application to be general, so if I change the mapfile, or
>the data, I shouldn't have to change anything else.
>
>Berend
>
>
>
>--
>____________________________
>
>Berend Veldkamp - ARIS
>http://www.aris.nl/
>____________________________



More information about the mapserver-users mailing list