[Chameleon] Filtering (Postgis) layers using user input

Normand Savard nsavard at mapgears.com
Tue Aug 28 11:23:55 EDT 2007


Jos Bol wrote:

>Sorry if this mail reaches the list twice, the first mail seems to have bounced. To be sure it arrives, I'm sending it again and also with some changes.
>
>Hi,
>
>I have been playing around with chameleon for some time now and everything seems to work perfectly. Great work!  
>
>My only doubt so far is about postgis layers. I have a postgis layer with several lines, a lot of them actually, and
>would only like to display a selection of lines based on user input. I would like to make a dropdown/combobox
>with some predefined values and a button. When selecting the value from the combobox and then pressing the
>button it should use the selected value of the combox in a heavy* query and display the result (a bunch of lines) on the map. I have been able to get this to work in a normal mapscript application, but don't know how to aproach this, using chameleon.
>
>I´ve read on the mailing list it's possible to manipulate the map in the initializer file. What would be the best way the do this? I assume I have to create a widget for this as well to allow user input. Does anyone have any examples for this or some hints on where to start?  
>
>I already successfully managed to filter a layer based on parameters in the URL and then zoom in to the results of the filter, by messing around in the initializer file. I imagine that there must be a cleaner way to do it, right?
>
>  
>
Jos,

I think the best way is to create your own widget.  For this you can 
look to  
http://chameleon-tiki.maptools.org/tiki-index.php?page=Developing+a+new+Chameleon+Widget

For example in your case your widget could look like this:

    function DrawPublish()
    {
        ...
        $szResult = "<SELECT NAME=\"yourselectname\" 
onchange=\"performQuery(this)\">\n";
        fill in the options by parsing the widget 
attributes                  //See the DrawPublish function in the 
QuickZoom widget
    }
     function GetJavascriptFunctions()
    {
        parent::GetJavascriptFunctions();

        $aReturn = array();
        $szJsFunctionName = "performQuery";
        $szFunction = <<<EOT
/**
 * {$szJsFunctionName}
 *  Execute this function when a user select a query
*/
function {$szJsFunctionName}(obj)
{
    query=obj.options[obj.selectedIndex].value;
    if (query != "")
    {
        {$this->mszHTMLForm}.PATHQUERY.value = query;   set some HTML 
variables
        {$this->mszHTMLForm}.submit();
    }
    return;
}
EOT;
        $aReturn[$szJsFunctionName] = $szFunction;
        return $aReturn;
    }

//Define your HTML variables
    function GetHTMLHiddenVariables()
    {
        parent::GetHTMLHiddenVariables();

        $szVariable = "PATHQUERY";
        $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
        $aReturn[$szVariable] = $szValue;

        return $aReturn;
    }

     * process the url looking for pathquery requests
     * you should do all your processing on the postgis layer here
     */
    function  ParseURL()
    {
        parent::ParseURL();

        if ($this->isVarSet( "PATHQUERY" ) &&
            $this->getVar( "PATHQUERY" ) != "")
        {

            $szPathQuery = $this->getVar( "PATHQUERY" );

             ...

    }

Define your widget in your template like this:

                    <cwc2 type="PathQuery" ENABLED="TRUE" 
labelclass="label" widgetclass="inputBox1">
                      <query name="name1"/>
                      <query name="name2"/>
                    </cwc2></td>
 
The query attribute values will be stored in $this->maszContents.  This 
is this variable you have to parse in DrawPublish() function.

I hope this help a little bit.

Norm

>Thanks in advance!
>
>Jos
>
>* The query contains a pathfinding algorithm, so it would be nice if I would only have to execute the query when the user changes the selection
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Chameleon mailing list
>Chameleon at lists.maptools.org
>http://lists.maptools.org/mailman/listinfo/chameleon
>  
>



More information about the Chameleon mailing list