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

root/Chameleon/trunk/Chameleon/Cursorpos/Cursorpos.widget.php_backup

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Cursor postion display widget
4  *
5  * @project     CWC2
6  * @revision    $Id: Cursorpos.widget.php,v 1.8 2005/01/11 12:32:19 pspencer Exp $
7  * @purpose     Base 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 include_once(dirname(__FILE__)."/../Widget.php");
30 include_once(dirname(__FILE__)."/../Label.php");
31
32 /**
33  * CursorPosWidget.
34  *
35  */
36 class CursorPos extends CWCWidget
37 {
38     var $moLabel;
39     var $mnDefaultTextFieldSize = 20;
40     var $mszAxis = "X";
41     var $mszClass = "CWCCursorPositionWidgetClass";
42     var $mszStyle = "";
43
44     function CursorPos()
45     {
46         // invoke constructor of parent
47         parent::CWCWidget();
48
49         // set the description for this widget
50         $this->szWidgetDescription = <<<EOT
51 Display the current cursor position in geographic coordinates.  To assist
52 template developers, this widget can be configured to display one of the
53 two axis of the cursor position.  The cursor position must be displayed in
54 an HTML element that can be updated, so an HTML INPUT box is used.  CSS can
55 be used to modify the appearance of the INPUT box to make it look nicer in
56 more modern browsers.
57 EOT;
58
59         $this->moLabel = new CWCLabel( $this );
60         $this->maAttributes["AXIS"] = new StringAttribute( "AXIS", true, array( "X", "Y" ) );
61         $this->maAttributes["TEXTFIELDSIZE"] = new IntegerAttribute( "TEXTFIELDSIZE", false, 0 );
62         $this->maAttributes["WIDGETCLASS"] = new StringAttribute( "WIDGETCLASS", false );
63         $this->maAttributes["WIDGETSTYLE"] = new StringAttribute( "WIDGETSTYLE", false );
64         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
65
66     }
67
68     function InitDefaults()
69     {
70         parent::InitDefaults();
71         if (isset($this->maParams["AXIS"]))
72             $this->mszAxis = strtoupper($this->maParams["AXIS"]);
73         if (isset($this->maParams["TEXTFIELDSIZE"]))
74             $this->mnDefaultTextFieldSize = strtoupper($this->maParams["TEXTFIELDSIZE"]);
75         if (isset($this->maParams["WIDGETCLASS"]))
76             $this->mszClass = $this->maParams["WIDGETCLASS"];
77         if (isset($this->maParams["WIDGETSTYLE"]))
78             $this->mszStyle = $this->maParams["WIDGETSTYLE"];
79     }
80
81     /**
82      * GetJavascriptFunctions
83      *
84      * Build and return the array of functions needed in the
85      * widget.
86      */
87     function GetJavascriptFunctions()
88     {
89         $aReturn = array();
90         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
91           $bCWCJSAPI = 1;
92         else
93           $bCWCJSAPI = 0;
94
95         $axis = $this->mszAxis;
96
97         $szJsFunctionName = "Cursor".$axis."MouseMoved";
98         $szFunction = <<<EOT
99 /**
100  * {$szJsFunctionName}
101  * called when the cursor moves for Cursor Postion widget.
102  */
103 function {$szJsFunctionName}(e)
104 {
105
106     //make sure that the forms varaibales are initialized.
107     //It seems like that in IE, the mouse move may be called before.
108     if ({$this->mszHTMLForm} == null ||
109       {$this->mszHTMLForm}.MAP_CURSOR_POS_${axis} == null)
110       return true;
111
112     var nPixPos = {$this->mszHTMLForm}.MAP_CURSOR_POS_${axis}.value;
113
114     var dfGeoMinX;
115     var dfGeoMinY;
116     var dfGeoMaxX;
117     var dfGeoMaxY;
118     var nMapWidth;
119     var nMapHeight;
120
121     if ({$bCWCJSAPI})
122     {
123         dfGeoMinX = goCWCJSAPI.oMap.minx;
124         dfGeoMinY = goCWCJSAPI.oMap.miny;
125         dfGeoMaxX = goCWCJSAPI.oMap.maxx;
126         dfGeoMaxY = goCWCJSAPI.oMap.maxy;
127
128         nMapWidth = goCWCJSAPI.oMap.width;
129         nMapHeight = goCWCJSAPI.oMap.height;
130     }
131     else
132     {
133         dfGeoMinX = {$this->mszHTMLForm}.MAP_EXTENTS_MINX.value;
134         dfGeoMinY = {$this->mszHTMLForm}.MAP_EXTENTS_MINY.value;
135         dfGeoMaxX = {$this->mszHTMLForm}.MAP_EXTENTS_MAXX.value;
136         dfGeoMaxY = {$this->mszHTMLForm}.MAP_EXTENTS_MAXY.value;
137
138         nMapWidth = {$this->mszHTMLForm}.MAP_WIDTH.value;
139         nMapHeight = {$this->mszHTMLForm}.MAP_HEIGHT.value;
140     }
141     if (nPixPos >=0)
142     {
143         if ("{$axis}" == "X")
144           var dfGeoPos = WidgetPix2Geo(nPixPos, 0, nMapWidth, dfGeoMinX,
145                                         dfGeoMaxX, 0);
146         else
147           var dfGeoPos = WidgetPix2Geo(nPixPos, 0, nMapHeight, dfGeoMinY,
148                                         dfGeoMaxY, 1); //1 for inverse Y axe
149
150
151       {$this->mszHTMLForm}.CursorPos_{$axis}.value = dfGeoPos;
152     }
153 }
154 EOT;
155         $aReturn[$szJsFunctionName] = $szFunction;
156
157         $szJsFunctionName = "WidgetPix2Geo";
158         $szFunction = <<<EOT
159 /**
160  * {$szJsFunctionName}
161  * Utility function to convert from pixel to georef coordinates.
162  * Used in Cursor Postion widget.
163  */
164
165 function {$szJsFunctionName}(nPixPos, dfPixMin, dfPixMax, dfGeoMin, dfGeoMax, nInversePix)
166 {
167     dfWidthGeo = dfGeoMax - dfGeoMin;
168     dfWidthPix = dfPixMax - dfPixMin;
169
170     dfPixToGeo = dfWidthGeo / dfWidthPix;
171
172     if (Math.abs(dfPixToGeo) < 1)
173         dNbDecimal = Math.abs(Math.log(dfPixToGeo))/Math.log(10)+1;
174     else
175         dNbDecimal = 0;
176
177     if (nInversePix == 0)
178     {
179         dfDeltaPix = nPixPos - dfPixMin;
180     }
181     else
182     {
183         dfDeltaPix = dfPixMax - nPixPos;
184     }
185
186     dfDeltaGeo = dfDeltaPix * dfPixToGeo;
187
188     dfPosGeo = new String(new Number(dfGeoMin) + new Number(dfDeltaGeo));
189     aPosGeo = dfPosGeo.split(".");
190
191     if (dNbDecimal > 0 && aPosGeo.length == 2)
192     {
193         dfPosGeo = aPosGeo[0]+"."+aPosGeo[1].substr(0, dNbDecimal);
194     }
195     else
196     {
197         dfPosGeo = aPosGeo[0];
198     }
199
200     szttt =  ""+"pixelpos = "+nPixPos+" result ="+dfPosGeo;
201     //alert(szttt);
202     return dfPosGeo;
203 }
204 EOT;
205        $aReturn[$szJsFunctionName] = $szFunction;
206
207         return $aReturn;
208     }
209
210     /**
211      * GetJavascriptOnMouseMoveFunctions
212      *
213      * Returns functions to be called on mouse mouve event.
214      */
215     function GetJavascriptOnMouseMoveFunctions()
216     {
217         $aReturn = array();
218         $axis = $this->mszAxis;
219         $szJsFunctionName = "Cursor".$axis."MouseMoved";
220         $szFunction = "$szJsFunctionName(e);\n";
221         $aReturn[$szJsFunctionName] = $szFunction;
222
223         return $aReturn;
224     }
225
226
227     /**
228      * DrawPublish
229      *
230      * Return the HTML code using the name in the map file and the
231      * parameters of the CWC tag.
232      */
233     function DrawPublish()
234     {
235         if (!$this->mbVisible)
236             return "<!-- CursorPosition widget hidden -->";
237
238         $nSize = $this->mnDefaultTextFieldSize;
239         if (isset($this->maParams["TextFieldSize"]))
240             $nSize = strtoupper($this->maParams["TextFieldSize"]);
241
242         $szClass = "";
243         if ( strlen($this->mszClass) > 0 )
244             $szClass = " CLASS=\"$this->mszClass\"";
245         $szStyle = "";
246         if ( strlen($this->mszStyle) > 0 )
247             $szStyle = " STYLE=\"$this->mszStyle\"";
248         $szContents="<input$szClass$szStyle type=\"text\" name=\"CursorPos_".
249                     $this->mszAxis."\" id=\"CursorPos_".
250                     $this->mszAxis."\" value=\"\"  size=\"$nSize\" readonly>";
251
252         return $this->moLabel->DrawPublish( $szContents );
253     }
254 }
255 ?>
Note: See TracBrowser for help on using the browser.