[mapserver-users] passing cgi query params to wms layers

Mr. Puneet Kishor punk.kish at gmail.com
Tue Sep 27 00:22:27 EDT 2011


On Sep 26, 2011, at 11:04 PM, Stephen Woodbridge wrote:

> On 9/26/2011 10:29 PM, Puneet Kishor wrote:
>> I am using OpenLayers as the front-end, requesting a WMS layer from MapServer that is getting data from Pg. My DATA statement is like so
>> 
>> 	DATA "the_geom FROM (SELECT gid, pc, the_geom FROM table) t USING UNIQUE gid USING srid=4326"
>>         FILTER "pc = 'na'"
>> 
>> The above works fine. However, I would like to send the value of "pc" from OpenLayers (that is another problem that I am experiencing; I have asked on OL list on how to send query params to WMS layers, but if any of you know the solution, I would welcome that). In any case, I thought (naively), that I could change my FILTER statement like so
>> 
>> 	FILTER "pc = '[pc]'"
>> 
>> I tried sending a WMS query directly to test the above like so [http://server/cgi-bin/app?.. blah ..&pc=na] but no joy. Forcing a query error showed me that MapServer was executing the following
>> 
>> 	select .. from (..) t where the_geom&&  GeomFromText(..) and (pc = '[pc]')
>> 
>> How can I dynamically supply MapServer a filter value?
> 
> Does this doc answer your question?
>  http://mapserver.org/cgi/runsub.html
> 


Yes it does. I had not seen that doc (hence, I was naively trying [var] kinda sub). Man, this is hairy shiiite. Maybe I should concentrate on trying to get WMS via MapScript working again so I can work within the more familiar and comfy environs of the Perl DBI. MapServer is fast as heck and basically "joy to the world," but its Pg interface is a foreign world to me.


> This should help from the mapserver side of things. In the OpenLayers side of things you will need to propagate the parameter values into the base URL for the WMS request and get OpenLayers to propagate that change into the layer object.

I see. Thanks for answering this, because this too had me stumped. The so called optional JS object that was supposed to pass arbitrary parameters to the OL layer constructor wasn't bringing any success. So, essentially, I should construct the base URL and then make my WMS layer as usual.


> If you expect the existing map to change when you change the values, then you will need to force OpenLayers to redraw the layer to request a new image or tiles based on the updated parameters.
> 

Yeah, of course. The idea is that the user clicks on the map, and based on the location of the click, a new map layer is generated. Hopefully I will have this all working soon and be able to show it to the world.

Many thanks Steve (and you too Jukka).


Puneet.




More information about the mapserver-users mailing list