Passing Variable to a Map File

Ken Lord kenlord at GMAIL.COM
Mon Dec 5 14:13:25 PST 2005


Hi Damon,

I can't speak for MapScript,  but for MapServer CGI,  this can be
found in the documentation referred to as variable substitution.

Within the mapfile, you could replace part or all of a parameter in
your mapfile with a variable,  MapServer is given the value of the
variable by the form submission or the GET parameters in the web
page's URL,  I've used javascript and ASP to modify hidden form
values, or to alter the URL parameters for this effect with other
parts of my map files ... I don't think I've tried it specificaly with
the DATA parameter of a layer.

Try searching the email archives on this, I'm not sure if the DATA
parameter of a layer is accessible this way.

Hopefully this will give you some clues for the MapScript side of things.

Cheers,
Ken Lord
Vancouver BC




On 12/5/05, Damon Broglie <brog at mail.utexas.edu> wrote:
> I'm having a devil of a time working on this one.
>
> My setup:
> * Linux server ( Fedore Core 3, Apache, etc. )
> * MapServer ( 4.2.5 )
> * MapLab w/ gMap Factory ( 2.2.1 )
> * PHP/MapScript ( 1.194.2.6 )
> * PostGIS-enabled postgreSQL database
>
> Things are running smoothly for simple map creation.  I can edit maps, add
> PostGIS layers, etc. easily.  But I'm just a bit stumped when it comes to
> making the map file's DATA attribute a variable and passing a SQL query
> string to it.
>
> My ultimate goal is to take user input (in the form of dropdown lists - but
> for right now I'm using a simple text box), create a query string from this
> input, and then use it as the DATA attribute.
>
> So far, I have made a form element in the file automatically created by
> gMap Factory ( <project_name>_contents.php ) which adds the string :
>
> sqlstring="the_geom from postgis_table"
>
> to the URL when a submit button is clicked.
>
> How can I get this string to be the DATA attribute in my <project_name>.map
> file?
>
> The "MapServer MapFile Reference" mentions the ability to use variable
> substitution in map files, which seems like the best route to
> take.  However, it also states that "if you are using MapScript, you will
> have to code the substitution logic in your application yourself (By
> writing your own pre-processor)."
>
> I've found a few references here and there that touch on using percent
> signs to create a variable like %DATA% in the map file, but no concrete
> examples on how to actually pass the data to such a variable using
> something like MapScript.
>
> Does anybody have some insight?
>
> Thanks a ton.
>
> --Damon
> brog at mail dot utexas dot edu
>



More information about the MapServer-users mailing list