Chameleon    Home  |  Docs  |  Support  |  Bugs  |  CVS  |  Downloads 

MapTools.org

Query Widget Customizing Results

Chameleon allows users to develop custom querying mechanisms so that you can use the results of a spatial query for virtually any purpose. The basic difference between Chameleon's generic Query tool and and a Custom Query is that the query event is intercepted by the Global Event Manager:

goEventManager.registerForEvent( 'ON_QUERY', 'function_to_call' );

This line of javascript is placed in the onload event of your Chameleon Application. The Global Event Manager will trigger the specified javascript function on a query event. Without this line of code your application will fire the default Query tool and proceed as normal.

In order to use this functionality you should set popupresults to false (ie, popupresults="false") in the widget. If set true then you will receive the results from both the Custom Query and the default Query tool.

In your template, the 'function_to_call' is a function that you create - eg:

function myOnQuery( nX, nY )
{
   var url = 'query.phtml?x=' + nX + '&y=' + nY + '&sid=' + document.forms0.sid.value;
}

Note that this function takes the X and Y pixel coordinates as arguments. These are provided by the Query tool. Your javascript function will pass them to a script which will execute the following function:

executeQuery( object MapSession?, integer X, integer Y );

This function is located in chameleon/htdocs/query_utils.php. The executeQuery function performs the same query as the generic Chameleon Query tool. The main difference is that this function returns the results as an indexed array of results for all visible queryable layers. These results can then be used to generate your own results page.

Here is an example query.phtml file:

<?php
/**
* Chameleon Documentation
*
* @project     Chameleon
* @revision    $Id: twiki_query_widget_customize_result.html,v 1.1 
2008-12-11 20:19:01 nsavard Exp $
* @purpose     This is the query results page.
* @author      Jason Fournier (jfournier@dmsolutions.ca)
* @copyright
* Copyright (c) 2002, DM Solutions Group Inc.
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/

// check for a session
if( !isset( $_GET[ 'sid'] ) )
   die('no session detected');

// define some vars
define("LOAD_MAPSESSION", 1);
define( 'CHAMELEON_PATH', '/ms4w/apps/chameleon/htdocs/');

// include the supporting php functions
include(CHAMELEON_PATH."widgets/session.inc.php");
include(CHAMELEON_PATH."widgets/query_utils.php");

// execute the query based on passed coords and the mapsession
$aResults = executeQuery( $oMapSession, $_GET['x'], $_GET['y'] );

if (count($aResults) > 0)
{
   foreach( $aResults as $nLayerIdx => $aResult )
   {
       $oLayer = $oMapSession->oMap->getLayer($nLayerIdx);
       $szName = $oLayer->name;
       foreach($aResult as $aRow)
       {
               echo 'Layer Name: ' . $szName . '<br>';
               echo '<pre>';
               print_r( $aRow );
               echo '</pre>';
       }
   }
}

?>

The power of a custom query lies in what you can do with the results. For instance, if you have a url field in one of your layers that points to a more descriptive website for a given point location or attribute of a datasource you can based on the result set. Alternatively, you can control the layers and/or attributes which will respond to a query and style appropriately.

Created by: pspencer last modification: Friday 21 of January, 2005 [16:55:06 UTC] by jfournier

Printer Friendly

 
 

Contact Information

Chameleon Users List