NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/LinkQuery/LinkQuery.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Query Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: LinkQuery.widget.php,v 1.1 2005/04/08 20:07:46 jlacroix Exp $
7  * @purpose     Query Widget class
8  * @author      DM Solutions Group (assefa@dmsolutions.ca)
9  * @copyright
10  * <b>Copyright (c) 2002, DM Solutions Group Inc.</b>
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */
29  
30 include_once(CHAMELEON_PATH."/widgets/NavTool.php");
31 include_once(COMMON."wrapper/map_query.php" );
32 include_once(CHAMELEON_PATH."/widgets/Popup.php");
33
34 /**
35  * a navtool that open a popup at with the query result information in the URL
36  */
37 class LinkQuery extends NavTool
38 {
39     var $moPopup;
40     var $mszImagePath = "images/tool_query_off.gif";
41     var $mszSelectedImagePath = "images/tool_query_on.gif";
42     var $mszHoverImagePath = "images/tool_query_hover.gif";
43     var $mszImageTip = "Zoom In";
44     var $mszResultScript = '';
45     var $mszEmptyResultScript = '';
46     var $mszLinkQueryLayer = '';
47     var $mbCallPopup = false;
48     
49     /**
50      * construct a new query widget
51      */
52     function LinkQuery()
53     {
54         // invoke constructor of parent
55         parent::NavTool();
56
57         $this->SetNavCommand("LINKQUERY");
58         $this->moPopup = new CWCPopup($this);
59
60         $this->maAttributes["RESULTSCRIPT"] = new StringAttribute("RESULTSCRIPT", true);
61         $this->maAttributes["EMPTYRESULTSCRIPT"] = new StringAttribute( "EMPTYRESULTSCRIPT", false );
62         $this->maAttributes["LINKQUERYLAYER"] = new StringAttribute("LINKQUERYLAYER", true);
63
64         
65         // set the description for this widget
66         $this->szWidgetDescription = <<<EOT
67 The Query widget displays a GetFeatureInfo query result for each visible layer
68 at the point the user clicks.
69 EOT;
70
71         $this->mnMaturityLevel = MATURITY_BETA;
72     }
73
74     /**
75      * initialize default values for this widget
76      */
77     function InitDefaults()
78     {
79         parent::InitDefaults();
80         if (isset($this->maParams["RESULTSCRIPT"]))
81             $this->mszResultScript = $this->maParams["RESULTSCRIPT"];
82         if (isset($this->maParams["EMPTYRESULTSCRIPT"]))
83             $this->mszEmptyResultScript = $this->maParams["EMPTYRESULTSCRIPT"];
84         if (isset($this->maParams["LINKQUERYLAYER"]))
85             $this->mszLinkQueryLayer = $this->maParams["LINKQUERYLAYER"];
86     }
87
88     /**
89      * handle changes coming from the URL.  In this case, we only want
90      * to do a query and then change the url of the popup with the info from
91      * the query
92      */
93     function ParseURL()
94     {
95         $szCmd = "";
96         $szNavInputCoord = "";
97
98         if ($this->isVarSet( "NAV_CMD" ))
99             $szCmd = $this->getVar( "NAV_CMD" );
100         if ($this->isVarSet( "NAV_INPUT_COORDINATES" ))
101             $szNavInputCoord = $this->getVar( "NAV_INPUT_COORDINATES" );
102
103
104         if($szCmd == "LINKQUERY")
105         {
106             $aszMinMax = explode(";", $szNavInputCoord );
107             $adMin = explode(",", $aszMinMax[0]);
108             $aszLayers = array();
109             $oMap = $this->moMapObject->oMap;
110             $bQueryable = false;
111
112             // get layer name
113             $oLayer = $oMap->getLayerByName( $this->mszLinkQueryLayer );
114             if($oLayer)
115             {
116                 if ($oLayer->status == MS_ON || $oLayer->status == MS_DEFAULT)
117                 {
118                     if ($oLayer->template != "")
119                     {
120                         $bQueryable = true;
121                     }
122                     else
123                     {
124                         for( $j=0; $j < $oLayer->numclasses; $j++)
125                         {
126                             $oClass = $oLayer->getClass($j);
127                             if ($oClass->template != "")
128                             {
129                                 $bQueryable = true;
130                                 break;
131                             }
132                         }
133                     }
134                 }
135             }
136
137             // only add if on
138             if ( $bQueryable )
139             {
140                 array_push( $aszLayers, $oLayer->name );
141                 $szName = $oLayer->name;
142             }
143
144             // Check if there's any queryable layers
145             if(count($aszLayers) >= 1)
146             {
147                 $oMapQuery = new MapQuery( $this->moMapObject );
148
149                 // commit
150                 $oMapQuery->setQueryLayersByName( $aszLayers );
151
152                 // execute query
153                 if ( is_numeric($adMin[0]) )
154                     $oResultSet = $oMapQuery->executePointQuery( $adMin[0],
155                                                                  $adMin[1] );
156                 // Check if there's any result
157                 if($oResultSet)
158                 {
159                     $nCount = $oResultSet->nNumResults;
160
161                     // process each result set
162                     for($i=0; $i<$nCount; $i++)
163                     {
164                         $aRows = $oResultSet->getResultSet( $i );
165                         if(is_array($aRows))
166                         {
167                             foreach ($aRows[0] as $key => $value)
168                             {
169                                 $this->mszResultScript = str_replace(
170                                     "%$key%", $value, $this->mszResultScript);
171                             }
172
173                             $this->mbCallPopup = true;
174                             break;
175                         }
176                     }
177                 }
178                 if(!$this->mbCallPopup && $this->mszEmptyResultScript)
179                 {
180                     $this->mszResultScript = $this->mszEmptyResultScript;
181                     $this->mbCallPopup = true;
182                 }
183             }
184         }
185
186         return parent::ParseURL();
187     }
188
189     /**
190      * get javascript mousemove functions
191      */
192     function GetJavascriptOnMouseMoveFunctions()
193     {
194         $aReturn = array();
195         $szJsFunctionName = "QueryWMouseMove";
196         $szFunction = "$szJsFunctionName(e);\n";
197         $aReturn[$szJsFunctionName] = $szFunction;
198
199         return $aReturn;
200     }
201     
202     function GetJavascriptInitFunctions()
203     {
204         $aResult = parent::GetJavascriptInitFunctions();
205         
206         $aResult['QueryRegisterEvent'] = "goEventManager.registerEventID( 'ON_QUERY' );\n";
207
208         if($this->mbCallPopup)
209             $aResult['LinkQueryCallPopup'] = "LinkQueryCallPopup();";
210         
211         return $aResult;
212     }
213     
214     /**
215      * get general javascript functions
216      */
217     function GetJavascriptFunctions()
218     {
219         $aReturn = parent::GetJavascriptFunctions();
220     
221         $this->moPopup->mszLink = $this->mszResultScript;
222         $szPopupName = $this->moPopup->GetPopupName();
223         $szPopupURL = $this->moPopup->GetPopupURL();
224         $szPopupOptions = $this->moPopup->GetPopupOptions();
225                 
226         $szJsFunctionName = "LinkQueryCallPopup";
227         $szFunction = <<<EOT
228 /**
229  * {$szJsFunctionName}
230  * called when the CallPopup is true.
231  */
232 function {$szJsFunctionName}(e)
233 {
234     szPopupURL = "{$szPopupURL}";
235     szPopupName = "{$szPopupName}";
236     szPopupOptions = "{$szPopupOptions}";
237
238     window.open( szPopupURL, szPopupName, szPopupOptions );
239 }
240 EOT;
241
242         $aReturn[$szJsFunctionName] = $szFunction;
243         
244         $szJsFunctionName = "QueryWMouseClick";
245         $szFunction = <<<EOT
246 /**
247  * {$szJsFunctionName}
248  * called when the mouse moves for the Query widget.
249  */
250 function {$szJsFunctionName}()
251 {
252     if ({$this->mszHTMLForm}.NAV_CMD.value != "{$this->mszCmd}")
253         return true;
254
255     MapWgetMouse(e);
256     if ( !MapWinsideMap() )
257         return true;
258
259     nX = {$this->mszHTMLForm}.MAP_CURSOR_POS_X.value;
260     nY = {$this->mszHTMLForm}.MAP_CURSOR_POS_Y.value;
261     szNav = "NAV_INPUT_COORDINATES=" + nX + "," + nY;
262     
263     {$this->mszHTMLForm}.submit();
264
265     goEventManager.triggerEvent( 'ON_QUERY', nX, nY );
266     return true;
267 }
268 EOT;
269
270         $aReturn[$szJsFunctionName] = $szFunction;
271
272         $szJsFunctionName = "QueryWMouseMove";
273         $szFunction = <<<EOT
274 /**
275  * {$szJsFunctionName}
276  * called when the mouse moves for the Query widget.
277  */
278 function {$szJsFunctionName}(e)
279 {
280
281     //make sure that the forms varaibales are initialized.
282     //It seems like that in IE, the mouse move may be called before.
283     if({$this->mszHTMLForm} == null ||
284       {$this->mszHTMLForm}.NAV_CMD == null ||
285       {$this->mszHTMLForm}.NAV_CMD.value != "QUERY")
286       return true;
287
288     //document.onmousedown = QueryWMouseClick;
289     document.onmouseup = QueryWMouseClick;
290
291     var x = (navigator.appName == "Netscape")? e.pageX : event.x+document.body.scrollLeft;
292     var y = (navigator.appName == "Netscape")? e.pageY : event.y+document.body.scrollTop;
293     if ((navigator.appName == "Netscape") && e.target!=document)
294       routeEvent(e);
295
296     return true;
297
298 }
299 EOT;
300
301         $aReturn[$szJsFunctionName] = $szFunction;
302
303
304         return $aReturn;
305     }
306
307 }
308 ?>
309
310
Note: See TracBrowser for help on using the browser.