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

root/Chameleon/trunk/Chameleon/ZoomFactor/ZoomFactor.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ZoomFactor Widget Class
4  *
5  * @project     CWC2
6  * @revision    $Id: ZoomFactor.widget.php,v 1.6 2005/01/11 12:32:21 pspencer Exp $
7  * @purpose     Display a Zoom Factor to control how far we zoom in/out
8  *              on point zooms.
9  * @author      DM Solutions Group (assefa@dmsolutions.ca)
10  * @copyright
11  * <b>Copyright (c) 2002, DM Solutions Group Inc.</b>
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  */
30
31
32 include_once(dirname(__FILE__)."/../Widget.php");
33 include_once(dirname(__FILE__)."/../Label.php");
34
35 /**
36  * ZoomFactor
37  *
38  * @desc Display a widget that controls the amount to zoom in/out
39  * when performing point zooms.
40  */
41 class ZoomFactor extends CWCWidget
42 {
43     var $mnDefaultFactor = 2;
44     var $moLabel;
45     var $mnCurrentFactor = "";
46     var $mnMinimum = "";
47     var $mnMaximum = "";
48     var $mnDefaultTextFieldSize = 2;
49
50     /**
51      * ZoomFactor
52      *
53      * Constctor method for the ZoomFactor widget.
54      */
55     function ZoomFactor()
56     {
57         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/ZoomFactor.dbf";
58
59         // invoke constructor of parent
60         parent::CWCWidget();
61
62         // set the description for this widget
63         $this->szWidgetDescription = <<<EOT
64 The ZoomFactor widget allows the user to enter a zoom factor that is used
65 when the user zooms in at a point.  This is ignored if the user zooms to
66 a rectangular region.  It contains the ability to restrict the zoom factor
67 to a range of values.
68 EOT;
69
70         $this->moLabel = new CWCLabel( $this );
71         $this->maAttributes["DEFAULTFACTOR"] = new IntegerAttribute( "DEFAULTFACTOR", false, 2 );       
72         $this->maAttributes["MAXIMUMFACTOR"] = new IntegerAttribute( "MAXIMUMFACTOR", false, 2 );
73         $this->maAttributes["MINIMUMFACTOR"] = new IntegerAttribute( "MINIMUMFACTOR", false, 2 );
74         $this->maAttributes["TEXTFIELDSIZE"] = new IntegerAttribute( "TEXTFIELDSIZE", false, 1 );
75         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
76     }
77
78     /**
79      * GetJavascriptFunctions
80      *
81      * Return the Javacriptfunctions needed by the widget.
82      */
83     function GetJavascriptFunctions()
84     {
85         $nMin = $this->mnMinimum;
86         if (isset($this->maParams["MINIMUMFACTOR"]))
87             $nMin = $this->maParams["MINIMUMFACTOR"];
88         $nMax = $this->mnMaximum;
89         if (isset($this->maParams["MAXIMUMFACTOR"]))
90             $nMax = $this->maParams["MAXIMUMFACTOR"];
91
92         $nZoomFactor = $this->mnCurrentFactor;
93         if ($nZoomFactor == "")
94         {
95             $nZoomFactor = $this->GetValue( "DefaultFactor",
96                                             $this->mnDefaultFactor );
97         }
98
99         $szJsMinimum = "";
100         if ($nMin != "")
101         {
102             $szMinMsg = trim($this->moMLT->get("0", "Minimum Zoom Factor is"));
103             $szJsMinimum = <<<EOT
104     // check for Minimum value
105     if (obj.value < {$nMin} )
106     {
107         obj.value = {$nMin};
108         alert( "{$szMinMsg} " + {$nMin} );
109     }
110 EOT;
111         }
112
113         $szJsMaximum = "";
114         if ($nMax != "")
115         {
116             $szMaxMsg = trim($this->moMLT->get("1", "Maximum Zoom Factor is"));
117             $szJsMaximum = <<<EOT
118     // check for Maximum Value
119     if (obj.value > {$nMax} )
120     {
121         obj.value = {$nMax};
122         alert( "{$szMaxMsg} " + {$nMax} );
123     }
124 EOT;
125         }
126
127         $szJsFunctionName = "changeZoomFactor";
128         $szValueMsg = trim($this->moMLT->get("2", "Value entered is not an integer"));
129         $szFunction = <<<EOT
130 function {$szJsFunctionName}(obj)
131 {
132     nDefault = {$nZoomFactor};
133     if (!validateInteger( obj.value ))
134     {
135         alert( "{$szValueMsg}" );
136         obj.value = nDefault;
137     }
138 {$szJsMinimum}
139 {$szJsMaximum}
140 }
141 EOT;
142         $aReturn[$szJsFunctionName] = $szFunction;
143
144         $szJsFunctionName = "validateInteger";
145         $szFunction = <<<EOT
146 function {$szJsFunctionName}( nValue )
147 {
148     return !isNaN( Number(nValue) );
149 }
150 EOT;
151
152         $aReturn[$szJsFunctionName] = $szFunction;
153         return $aReturn;
154     }
155
156     /**
157      * ParseURL
158      *
159      * Look for the ZOOM_IN command and if founddo the zooming
160      * according to the other NAV paramaters.
161      */
162     function  ParseURL()
163     {
164         if ($this->isVarSet( "ZOOMFACTOR" ))
165             $this->mnCurrentFactor = $this->getVar( "ZOOMFACTOR" );
166             
167         // return success
168         return true;
169     }
170
171     /**
172      * DrawPublish
173      *
174      * Return the HTML code using the name in the map file and the
175      * parameters of the CWC tag.
176      */
177     function DrawPublish()
178     {
179         if (!$this->mbVisible)
180             return "<!-- Zoom Factor is hidden -->";
181
182         $nSize = $this->mnDefaultTextFieldSize;
183         if (isset($this->maParams["TEXTFIELDSIZE"]))
184             $nSize = intval($this->maParams["TEXTFIELDSIZE"]);
185
186         $nZoomFactor = $this->mnDefaultFactor;
187         if (isset($this->maParams["DEFAULTFACTOR"]))
188             $nZoomFactor = strtoupper($this->maParams["DEFAULTFACTOR"]);
189         if ($this->isVarSet( "ZOOMFACTOR" ))
190             $nZoomFactor = strtoupper($this->getVar( "ZOOMFACTOR" ));
191
192         $szResult = "<input type=\"text\" name=\"ZOOMFACTOR\"".
193             " size=\"$nSize\" value=\"$nZoomFactor\"".
194             " onChange=\"changeZoomFactor(this)\">";
195         $szResult = $this->moLabel->DrawPublish( $szResult );
196
197         return $szResult;
198     }
199 }
200 ?>
201
Note: See TracBrowser for help on using the browser.