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

root/Chameleon/trunk/Chameleon/Scale/Scale.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Scale Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: Scale.widget.php,v 1.14 2005/06/06 18:12:48 bartvde Exp $
7  * @purpose     Scale 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 include_once(dirname(__FILE__)."/../Widget.php");
32 include_once(dirname(__FILE__)."/../Label.php");
33
34 /**
35  * Scale
36  *
37  * @desc Display scale in an input box and process if the page is submitted.
38  */
39 class Scale extends CWCWidget
40 {
41     var $moLabel;
42     var $mszSize = "8";
43     var $mszClass = "CWCScaleWidgetClass";
44     var $mbSubmitOnKeyPress = "true";
45     var $mszStyle = "";
46     var $oMapNavigator;
47
48     /**
49      * Scale
50      *
51      * Constructor for the Scale
52      */
53     function Scale( )
54     {
55         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/Scale.dbf";
56
57         // invoke constructor of parent
58         parent::CWCWidget();
59
60         // set the description for this widget
61         $this->szWidgetDescription = <<<EOT
62 The Scale widget displays an HTML INPUT box that the user can view the
63 current map scale and enter a scale to zoom to.  The Scale widget needs
64 to be combined with another widget that actually causes the map to refresh,
65 such as an UpdateMap widget.
66 EOT;
67
68         $this->moLabel = new CWCLabel($this);
69         $this->maAttributes["SIZE"] = new IntegerAttribute( "SIZE", false, 1 );
70         $this->maAttributes["SUBMITONKEYPRESS"] = new BooleanAttribute( "SUBMITONKEYPRESS", false );
71         $this->maAttributes["WIDGETCLASS"] = new StringAttribute( "WIDGETCLASS", false );
72         $this->maAttributes["WIDGETSTYLE"] = new StringAttribute( "WIDGETSTYLE", false );
73
74         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
75     }
76
77     /**
78      * Initialize default values from tag
79      */
80     function InitDefaults()
81     {
82         parent::InitDefaults();
83         if (isset($this->maParams["WIDGETCLASS"]))
84             $this->mszClass = $this->maParams["WIDGETCLASS"];
85         if (isset($this->maParams["WIDGETSTYLE"]))
86             $this->mszStyle = $this->maParams["WIDGETSTYLE"];
87         if (isset($this->maParams["SUBMITONKEYPRESS"]))
88             $this->mbSubmitOnKeyPress = $this->maParams["SUBMITONKEYPRESS"];
89
90     }
91
92     /**
93      * SetMap
94      *
95      * Set the map session and create a navigation tool.
96      *
97      * @param oMapSession
98      */
99     function SetMap($oMapSession)
100     {
101         $this->moMapObject = $oMapSession;
102
103         $this->moMapNavigator = new MapNavigator( $oMapSession );
104     }
105
106     /**
107      * ParseURL
108      *
109      * Compare NAV_SCALE to SCALE and zoomscale if they are different
110      */
111     function  ParseURL()
112     {
113         $szUpdate = "";
114         if ($this->isVarSet( "UPDATE_MAP" ))
115             $szUpdate = $this->getVar( "UPDATE_MAP" );
116
117         if ($szUpdate != "1")
118             return true;
119
120         $szNewScale = "";
121         if ($this->isVarSet( "SCALE" ))
122             $szNewScale = $this->getVar( "SCALE" );
123
124         if ($szNewScale > 0 && is_numeric($szNewScale))
125             $this->moMapNavigator->zoomScale( $szNewScale );
126         else
127             $_SESSION['gErrorManager']->setError(ERR_WARNING, trim($this->moMLT->get("0", "ERROR: Invalid specified scale.")));
128
129         return true;
130     }
131
132
133     /**
134      * GetHTMLHiddenVariables
135      *
136      * Return HTML hidden variables.
137      */
138     function GetHTMLHiddenVariables()
139     {
140         $szVariable = "UPDATE_MAP";
141         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"0\">";
142         $aReturn[$szVariable] = $szValue;
143         return $aReturn;
144     }
145
146     /**
147      * return an array of javascript functions needed by Scalebar widget
148      * @return array of name = function values
149      */
150     function GetJavascriptFunctions()
151     {
152         $aReturn = array();
153
154         $poMap = $this->moMapObject->oMap;
155
156         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
157           $bCWCJSAPI = 1;
158         else
159           $bCWCJSAPI = 0;
160
161         if ($bCWCJSAPI)
162         {
163                         $szJsFunctionName = "ScaleWRegisterForEvent";
164             $szFunction = <<<EOT
165 /**
166  * {$szJsFunctionName}
167  * called to register and even when the map extents chnages (JSAPI)
168  */
169 function {$szJsFunctionName}()
170 {
171     goCWCJSAPI.RegisterEvent(MAP_EXTENT_CHANGED, "ScaleWMapExtentsChanged");
172 }
173 EOT;
174
175        $aReturn[$szJsFunctionName] = $szFunction;
176
177               $szJsFunctionName = "ScaleWMapExtentsChanged";
178        $szFunction = <<<EOT
179 /**
180  * {$szJsFunctionName}
181  * called when the mapextents are changed to update the scalebar images(JSAPI)
182  */
183 function {$szJsFunctionName}()
184 {
185     {$this->mszHTMLForm}.SCALE.value = goCWCJSAPI.oMap.scale;
186 }
187 EOT;
188
189     $aReturn[$szJsFunctionName] = $szFunction;
190
191     }
192                         $szJsFunctionName = "KeyPressed";
193             $szFunction = <<<EOT
194 /**
195  * {$szJsFunctionName}
196  * submits the form on enter
197  */
198 function {$szJsFunctionName}(e)
199 {
200     if (!e) var e = window.event;
201     var code = e.keyCode;
202     if (code == 13)
203     {
204         if( e.preventDefault )
205             e.preventDefault();
206         else
207             e.returnValue = false;
208
209         if( e.stopPropagation )
210             e.stopPropagation();
211         else
212             e.cancelBubble = true;
213
214         if ($bCWCJSAPI)
215         {
216           goCWCJSAPI.oMap.oApplication.ZoomToScale({$this->mszHTMLForm}.SCALE.value);
217         }
218         else
219         {
220           // clear the navigation form
221           {$this->mszHTMLForm}.NAV_CMD.value = '';
222
223           {$this->mszHTMLForm}.UPDATE_MAP.value = "1";
224           {$this->mszHTMLForm}.submit();
225         }
226         return true;
227     }
228     return true;
229 }
230 EOT;
231 $aReturn[$szJsFunctionName] = $szFunction;
232
233
234      return $aReturn;
235 }
236
237     /**
238      * return an array of javascript functions needed by Scalebar widget
239      * and called when the page is loaded.
240      * @return array of name = function values
241      */
242      function GetJavascriptOnLoadFunctions()
243      {
244          $aReturn = array();
245
246          $aReturn = parent::GetJavascriptOnLoadFunctions();
247
248          if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
249          {
250              $szJsFunctionName = "ScaleWRegisterForEvent";
251              $szFunction = "$szJsFunctionName();\n";
252              $aReturn[$szJsFunctionName] = $szFunction;
253          }
254
255          return $aReturn;
256      }
257
258     /**
259      * DrawPublish
260      *
261      * Return the HTML code using the name in the map file and the
262      * parameters of the CWC tag.
263      */
264     function DrawPublish()
265     {
266         if (!$this->mbVisible)
267             return "<!-- Scale widget hidden -->";
268
269         $this->moMapObject->oMap->setExtent(
270                                 $this->moMapObject->oMap->extent->minx,
271                                 $this->moMapObject->oMap->extent->miny,
272                                 $this->moMapObject->oMap->extent->maxx,
273                                 $this->moMapObject->oMap->extent->maxy);
274
275         $szScale = $this->moMapObject->oMap->scale;
276
277         // If scale is > than 1 don't round the scale
278         if ($szScale > 1)
279             $szScale = round($szScale);
280
281         $szSize = $this->mszSize;
282         if (isset($this->maParams["SIZE"]))
283             $szSize = strtoupper($this->maParams["SIZE"]);
284
285         $szClass = "";
286         if ( strlen($this->mszClass) > 0 )
287           $szClass = " CLASS=\"$this->mszClass\"";
288         $szStyle = "";
289         if ( strlen($this->mszStyle) > 0 )
290           $szStyle = " STYLE=\"$this->mszStyle\"";
291
292         $szSubmitOnKeyPress = "";
293         if ($this->mbSubmitOnKeyPress == "true")
294           $szSubmitOnKeyPress = " OnKeyPress=\"KeyPressed(arguments[0])\"";
295         $szValue = "<INPUT".$szClass.$szStyle.$szSubmitOnKeyPress." NAME=\"SCALE\" TYPE=\"TEXT\" VALUE=\"$szScale\" size=\"$szSize\">";
296
297         //and put a label next to it if necessary
298         return $this->moLabel->DrawPublish( $szValue );
299     }
300 }
301 ?>
Note: See TracBrowser for help on using the browser.