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

root/Chameleon/trunk/Chameleon/NavTool.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Nav tool base class
4  *
5  * @project     CWC2
6  * @revision    $Id: NavTool.php,v 1.43 2005/03/23 03:33:32 wbronsema Exp $
7  * @purpose     LegendPopup 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 /*
31  * javascript events:
32  *
33  * NAV_TOOL_CHANGED
34  * useage:
35  *
36  * function myOnLoad()
37  * {
38  *    CWC2OnLoadFunction();
39  *    goEventManager.registerForEvent( 'NAV_TOOL_CHANGED', 'myNavToolChanged' );
40  * }
41  *
42  * function myNavToolChanged( sTool )
43  * {
44  *     alert( 'nav tool selected: ' + sTool );
45  * }
46  */
47 include_once("Widget.php");
48 include_once("Button.php");
49 include_once( COMMON."wrapper/map_navigator.php" );
50
51 /**
52  * class NavTool is a common base class for widgets that want to navigate
53  * and might be part of a toolset
54  */
55 class NavTool extends CWCWidget
56 {
57     var $moButton;
58     var $mszCmd = "";
59     var $moMapNavigator;
60     var $mnAllowRectangle = 0;
61     var $mbSubmitOnClick = 0;
62     /* control submission of the page after navigation.  By default,
63      * this is true.  Only widgets that need to override this should
64      * do so (for instance QUERY).
65      */
66     var $mbNavSubmit = true;
67     var $mszMapId = "DEFAULT_MAP";
68     var $mszCursorType = "AUTO";
69
70     /**
71      * construct a new navtool
72      */
73     function NavTool()
74     {
75         if($this->mszLanguageResource == "")
76             $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/NavTool.dbf";
77
78         // invoke constructor of parent
79         parent::CWCWidget();
80         
81         // set the description for this widget
82         $this->szWidgetDescription = "No description available.  Please set ".
83                         "this description in the constructor of this class.";
84
85         $this->moButton =& new CWCButton($this);
86         $this->maAttributes["WIDGETSTYLE"] = new StringAttribute( "WIDGETSTYLE", false );
87         $this->maAttributes["MAPID"] = new StringAttribute( "MAPID", false );
88         $this->maAttributes["CURSORTYPE"] = new StringAttribute( "CURSORTYPE", false );
89         $this->maAttributes['SUBMITONCLICK'] = new BooleanAttribute( 'SUBMITONCLICK', false );
90
91         $this->mnPriority = PRIORITY_LOW;
92     }
93
94     /**
95      * initialize default values from tag
96      */
97     function InitDefaults()
98     {
99         parent::InitDefaults();
100
101         if ($this->mbVisible)
102         {
103             $this->moButton->InitDefaults();
104         }
105         else
106             $this->maParams["IMAGE"] = "DUMMY";
107
108         if (isset($this->maParams["MAPID"]))
109             $this->maszMapId = $this->maParams["MAPID"];
110
111         if (isset($this->maParams["CURSORTYPE"]))
112             $this->mszCursorType = $this->maParams["CURSORTYPE"];
113         
114         if (isset($this->maParams['SUBMITONCLICK']))
115         {
116             $this->mbSubmitOnClick = strcasecmp($this->maParams['SUBMITONCLICK'], 'true') == 0?true:false;
117         }
118         
119         if ($this->mbSubmitOnClick)
120             $this->moButton->mszToolset = '';
121     }
122
123
124     /**
125      * set the command this tool uses to navigate
126      */
127     function SetNavCommand($szNavCmd)
128     {
129         $this->mszCmd = $szNavCmd;
130     }
131
132
133     /**
134      * set the map navigator for this nav tool
135      */
136     function SetMap(&$oMapSession)
137     {
138         $this->moMapObject =& $oMapSession;
139
140         $this->moMapNavigator = new MapNavigator( $oMapSession );
141     }
142
143
144     /**
145      * return javascript functions required for this tool
146      */
147     function GetJavascriptFunctions()
148     {
149         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
150           $bCWCJSAPI = 1;
151         else
152           $bCWCJSAPI = 0;
153
154         if ($this->mbVisible)
155             $aReturn = $this->moButton->GetJavascriptFunctions();
156         else
157             $aReturn = array();
158
159         $szJsFunctionName = "NavSetActiveTool";
160         $szFunction = <<<EOT
161 /**
162  * set the active navigation tool
163  */
164 function {$szJsFunctionName}( oButton, aVals )
165 {
166     var nTool = aVals[0];
167     var sTool = aVals[1];
168     var bAllowRectangle = (aVals[2] == 0 || aVals[2] == "0") ? false : true;
169     var bAutoSubmit = (aVals[3] == 0 || aVals[3] == "0") ? false : true;
170     var szCursorType = aVals[4];
171     var nNavSubmit = (aVals[5] != undefined) ? aVals[5] : 1;
172
173     {$this->mszHTMLForm}.NAV_CMD.value = sTool;
174     {$this->mszHTMLForm}.NAV_ALLOW_RECTANGLE.value=bAllowRectangle;
175     {$this->mszHTMLForm}.NAV_SUBMIT.value=nNavSubmit;
176
177     if ({$bCWCJSAPI})
178     {
179         goCWCJSAPI.NAV_CMD = sTool;
180     }
181
182     if (bAutoSubmit)
183     {
184         if ({$bCWCJSAPI})
185         {
186             goCWCJSAPI.UpdateNavTools();
187         }
188         else
189         {
190             {$this->mszHTMLForm}.submit();
191         }   
192     }
193
194     if ({$this->mszHTMLForm}.CURSOR_TYPE != null)
195     {
196       {$this->mszHTMLForm}.CURSOR_TYPE.value = szCursorType;
197     }
198     
199     goEventManager.triggerEvent( 'NAV_TOOL_CHANGED', sTool );
200 }
201 EOT;
202
203         $aReturn[$szJsFunctionName] = $szFunction;
204
205         return $aReturn;
206     }
207
208     function GetJavascriptVariables()
209     {
210         if ($this->mbVisible)
211             return $this->moButton->GetJavascriptVariables();
212         else return array();
213     }
214
215     function GetJavascriptInitFunctions()
216     {
217         $aResult = array();
218         if ($this->mbVisible)
219         {       
220             $aResult = $this->moButton->GetJavascriptInitFunctions();
221         }
222         
223         $aResult['NavToolRegisterEvent'] = "goEventManager.registerEventID( 'NAV_TOOL_CHANGED' );\n";
224         
225         return $aResult;
226     }
227
228     function GetJavascriptOnLoadFunctions()
229     {
230         if ($this->mbVisible)
231             $aReturn = $this->moButton->GetJavascriptOnLoadFunctions();
232         else
233             $aReturn = array();
234         
235         return $aReturn;
236     }
237     
238     function GetJavascriptIncludeFunctions()
239     {
240         $aReturn = $this->moButton->GetJavascriptIncludeFunctions();
241         
242         $szVar = "cwc_events.js";
243         $aReturn[$szVar] = '<script src="'.$_SESSION['gszCoreWebPath'].
244                             '/widgets/js/cwc_events.js" type="text/javascript"></script>';
245         
246         return $aReturn;
247     }
248
249     /**
250      * handle the user using this tool as part of a toolset
251      */
252     function  ParseURL()
253     {
254         $aVals = array();
255         array_push( $aVals, $this->mnId );
256         array_push( $aVals, $this->mszCmd );
257         array_push( $aVals, $this->mnAllowRectangle );
258         array_push( $aVals, $this->mbSubmitOnClick ? 1 : 0);
259         array_push( $aVals, $this->mszCursorType );
260         array_push( $aVals, $this->mbNavSubmit ? 1 : 0 );
261
262         $this->moButton->SetOnClick('NavSetActiveTool', $aVals);
263
264
265         if ($this->isVarSet( strtoupper($this->mszMapId)."_X" ) &&
266             $this->isVarSet( strtoupper($this->mszMapId)."_Y" ))
267         {
268             $this->setVar( "NAV_INPUT_COORDINATES" ,
269                            $this->getVar( strtoupper($this->mszMapId)."_X" ).",".
270                            $this->getVar( strtoupper($this->mszMapId)."_Y" ) );
271         }
272         
273         $this->moButton->ParseURL();
274
275         return true;
276     }
277
278     /**
279      * return hidden variables required for this tool
280      */
281     function GetHTMLHiddenVariables()
282     {
283         $aReturn = $this->moButton->GetHTMLHiddenVariables();
284         
285         $szVariable = "NAV_CMD";
286         $szTool = '';
287         if ($this->isVarSet( 'NAV_CMD' ))
288             $szTool = $this->getVar( 'NAV_CMD' );
289
290         $szValue = "<INPUT TYPE='HIDDEN' NAME='$szVariable' VALUE='$szTool'>";
291         $aReturn[$szVariable] = $szValue;
292
293         $szAllowRect = "";
294          if ($this->isVarSet( "NAV_ALLOW_RECTANGLE" ))
295           $szAllowRect = $this->getVar( "NAV_ALLOW_RECTANGLE" );
296
297         $szVariable = "NAV_ALLOW_RECTANGLE";
298         $szValue = "<INPUT TYPE='HIDDEN' NAME='$szVariable' VALUE='$szAllowRect'>";
299         $aReturn[$szVariable] = $szValue;
300
301         $szNavSubmit = "1";
302         if ($this->isVarSet( "NAV_SUBMIT" ))
303           $szNavSubmit = $this->getVar( "NAV_SUBMIT" );
304           
305         $szVariable = "NAV_SUBMIT";
306         $szValue = "<INPUT TYPE='HIDDEN' NAME='$szVariable' VALUE='$szNavSubmit'>";
307         $aReturn[$szVariable] = $szValue;
308         
309         return $aReturn;
310     }
311
312
313     /**
314      * draw this widget on the page
315      */
316     function DrawPublish()
317     {
318         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
319           $bCWCJSAPI = 1;
320         else
321           $bCWCJSAPI = 0;
322
323         if (!$this->mbVisible)
324             return "<!-- NavTool hidden -->";
325
326         $szReturn = $this->moButton->DrawPublish();
327
328         return $szReturn;
329     }
330 }
331
Note: See TracBrowser for help on using the browser.