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

root/Chameleon/trunk/Chameleon/Cursorpos/Cursorpos.widget.php

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     dec_minutes = ((aPosGeo[1].substring(0,4)) * .006) + "";
201     ddm = aPosGeo[0]+"°  "+dec_minutes.substring(0,4)+"'";
202     szttt =  ""+"pixelpos = "+nPixPos+" result ="+dfPosGeo;
203     // alert(szttt);
204
205     return dfPosGeo+"°"+" | "+ddm;
206     // return ddm;
207 }
208 EOT;
209        $aReturn[$szJsFunctionName] = $szFunction;
210
211         return $aReturn;
212     }
213
214     /**
215      * GetJavascriptOnMouseMoveFunctions
216      *
217      * Returns functions to be called on mouse mouve event.
218      */
219     function GetJavascriptOnMouseMoveFunctions()
220     {
221         $aReturn = array();
222         $axis = $this->mszAxis;
223         $szJsFunctionName = "Cursor".$axis."MouseMoved";
224         $szFunction = "$szJsFunctionName(e);\n";
225         $aReturn[$szJsFunctionName] = $szFunction;
226
227         return $aReturn;
228     }
229
230
231     /**
232      * DrawPublish
233      *
234      * Return the HTML code using the name in the map file and the
235      * parameters of the CWC tag.
236      */
237     function DrawPublish()
238     {
239         if (!$this->mbVisible)
240             return "<!-- CursorPosition widget hidden -->";
241
242         $nSize = $this->mnDefaultTextFieldSize;
243         if (isset($this->maParams["TextFieldSize"]))
244             $nSize = strtoupper($this->maParams["TextFieldSize"]);
245
246         $szClass = "";
247         if ( strlen($this->mszClass) > 0 )
248             $szClass = " CLASS=\"$this->mszClass\"";
249         $szStyle = "";
250         if ( strlen($this->mszStyle) > 0 )
251             $szStyle = " STYLE=\"$this->mszStyle\"";
252         $szContents="<input$szClass$szStyle type=\"text\" name=\"CursorPos_".
253                     $this->mszAxis."\" id=\"CursorPos_".
254                     $this->mszAxis."\" value=\"\"  size=\"$nSize\" readonly>";
255
256         return $this->moLabel->DrawPublish( $szContents );
257     }
258 }
259 ?>
260
Note: See TracBrowser for help on using the browser.