[Chameleon] retrieving postgis data programmatically

Normand Savard nsavard at mapgears.com
Tue May 22 11:35:59 EDT 2007

Anand Akmanchi wrote:

> Hi friends
> i am trying to develop a widget which displays a popup containing combos
> where one provides inputs for retrieving a layer from postgis database
> so far i have been able  to display the popup with the required combos
> and when i click on OK,
> the popup submits the form to itself
> the combo selections are read and an SQL query is built correctly
> in the mapfile i have a layer which looks like this
> DATA the_geom from (%SQL%) AS foo USING UNIQUE gid USING SRID=32643
> my question is how do i send the built SQL query to the mapfile and
> update the map?
> im stuck here
> please help

I'm not a Chameleon expert but you can modify the map programatically 
with php mapscript within the ParseURL function.  If you look in some 
widgets the map is often modified this way.  For instance in your case 
you can use the Locate widget to create your own one and do the following:

 -Create a button that will open a popup (see onClickLocate in 
GetJavascriptFunctions()) with a callback function that will be executed 
when you click on the "Ok" button in your popup (see the Locate 
constructor in Locate.widget.php on how to create the link to the 
popup,  InitDefaults() and DrawPublish() on how to create the button).

-Create an HTML variable (MY_SQL_VAR)in GetHTMLHiddenVariables()  to 
pass on the SQL query string from your popup.

-Set this HTML variable in your callback function and submit the page 
(see LocateCB).
        $szJsFunctionName = "LocateCB";
        $szFunction = <<<EOF
        function {$szJsFunctionName}(actionID, mysql)
            if (actionID == 1)
                // Here we should handle the load mapcontext
                {$this->mszHTMLForm}.MY_SQL_VAR.value = mysql;

                {$this->mszHTMLForm}.NAV_CMD.value = "";
                {$this->mszHTMLForm}.submit ();
            else if (actionID == 2) // close window
                wh.close ();



-Set the "Data" member of the layer with the set() method.  The code 
will look like this:

        $oMap = $this->moMapObject->oMap;
        $oLayer = @$oMap->getlayerbyname($this->mszLayerName);

        if ($this->isVarSet( "MY_SQL_VAR" ))
            $szSql = trim( $this->getVar( "MY_SQL_VAR" ));

        $oLayer->set("data", $szSql);

That's it.  I hope that'll help a little bit.


More information about the Chameleon mailing list