[mapserver-users] javascript query template examples

Steve Lime Steve.Lime at dnr.state.mn.us
Fri Jun 26 07:55:41 PDT 2009


Responses inline...

>>> On 6/25/2009 at 4:59 PM, in message <20090625215916.GA11253 at q.rho.net>, Wendell
Turner <wendell at enflight.com> wrote:
> On Thu, Jun 25, 2009 at 03:13:21PM -0500, Steve Lime wrote:
> 
>> Here's one example using new-style templating (recommend
>> MapServer 5.4.1). 
> 
> I'm using 5.2.0.  Do I need to upgrade?

Well, I'd recommend 5.2.2 at a minimum simply because of the security upgrades made in the last
few months. 5.4.1 is the latest version and contains a few fixes that fix templates that have
multiple [item ...] or [shpxy ...] tags on a single line.

>> Anyway, please ask questions if you need to.
> 
> Ok!
> 
>> The TEMPLATE:
>> 
>> // MapServer Template
>> function updateCountyList(element) {
>>   var option;
> ...
>> }
> 
> So, where does this template go?

Good question, I guess that wasn't clear in my response. In this case the
template is separate file and is referenced in the OUTPUTFORMAT itself via
the FORMATOPTION/FILE option. In this example the actual template is
the file /templates/demo_county_select_list.js.

> 1) there is a TEMPLATE in the WEB section.  It seems that if
> that line is present, it gets used.  I don't think it is
> that template.

Correct, the web template is for defining a browse interface and really isn't
used all that much anymore.

> 2) There is DRIVER 'TEMPLATE' in the OUTPUTFORMAT section.
> Should the above code be in a file named TEMPLATE?
>
> 3) There is a file in the FORMATOPTION under a /templates/
> directory that looks suspicious.

Bingo...

> 4) There is a TEMPLATE in the LAYER section that is used to
> indicate that the layer is queryable, and how to format that
> layer's data.

The TEMPLATE keyword is still used to make layers queryable. That may change
in the future. Simple using something like TEMPLATE 'dummy' will suffice.

>> The OUTPUTFORMAT:
>> 
>> OUTPUTFORMAT
>>     NAME 'county_select_list'
>>     DRIVER 'TEMPLATE'
>>     MIMETYPE 'text/javascript'
>>     FORMATOPTION 'ATTACHMENT=county_select_list.js'
>>     FORMATOPTION 'FILE=/templates/demo_county_select_list.js'
>> END
> 
> What is the difference in ATTACHMENT and FILE?

FILE is the actual template.

ATTACHMENT sets a HTTP header that essentially names the response from MapServer.
In this case the browser would save the file as county_select_list.js. I'm pretty sure this
is only available in 5.4 but isn't required at all.

>> The call to the CGI to run it is:
>> 
>> <script 
> src="http://maps.dnr.state.mn.us/cgi-bin/mapserv54?map=demo.map&qlayer=count
> ies&qformat=county_select_list&mode=nquery"></script>
> 
> Aha! qformat=name_of_the_output_format

Yup. You now can have a bunch of output formats without having to have a bunch of layers
for each one. A layer's features can be referenced by any number of templates!
 
> Thanks,
> 
> Wendell
> 
> _______________________________________________
> mapserver-users mailing list
> mapserver-users at lists.osgeo.org 
> http://lists.osgeo.org/mailman/listinfo/mapserver-users




More information about the MapServer-users mailing list