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

root/Chameleon/trunk/Chameleon/ProjectionLabel/ProjectionLabel.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ProjectionLabel Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: ProjectionLabel.widget.php,v 1.8 2005/03/15 13:05:37 pspencer Exp $
7  * @purpose     ProjectionLabel Widget class
8  * @author      DM Solutions Group (spencer@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  * ProjectionLabel
36  *
37  * @desc Displays a label for the current projection
38  */
39 class ProjectionLabel extends CWCWidget
40 {
41     var $moLabel;
42     var $mszClass = "CWCProjectionLabelWidgetClass";
43     var $mszStyle = "";
44     var $mnDefaultTextFieldSize = 50;
45
46     /**
47      * construct a new ProjectionLabel widget
48      */
49     function ProjectionLabel( )
50     {
51         // invoke constructor of parent
52         parent::CWCWidget();
53
54         // set the description for this widget
55         $this->szWidgetDescription = <<<EOT
56 The ProjectionLabel widget displays the name of the current projection
57 from those defined in a common resource called "projection".
58 The structure of the common resource is: &ltprojection name="human name"
59 srs="epsg code"/&gt;.  This structure is shared with the
60 projection selector widget if used.
61 EOT;
62
63         $this->moLabel = new CWCLabel($this);
64         $this->maAttributes["WIDGETCLASS"] = new StringAttribute( "WIDGETCLASS", false );
65         $this->maAttributes["WIDGETSTYLE"] = new StringAttribute( "WIDGETSTYLE", false );
66         $this->maAttributes["TEXTFIELDSIZE"] = new IntegerAttribute( "TEXTFIELDSIZE", false, 0 );
67         $this->mnMaturityLevel = MATURITY_TECHNICALRELEASE;
68
69     }
70
71     /**
72      * initialize default values
73      */
74     function InitDefaults()
75     {
76         parent::InitDefaults();
77         if (isset($this->maParams["WIDGETCLASS"]))
78             $this->mszClass = $this->maParams["WIDGETCLASS"];
79         if (isset($this->maParams["WIDGETSTYLE"]))
80             $this->mszStyle = $this->maParams["WIDGETSTYLE"];
81         if (isset($this->maParams["TEXTFIELDSIZE"]))
82             $this->mnDefaultTextFieldSize = strtoupper($this->maParams["TEXTFIELDSIZE"]);
83            
84     }
85    
86     /**
87      * return an array of javascript functions needed by ProjectionLabel widget
88      * @return array of name = function values
89      */
90     function GetJavascriptFunctions()
91     {
92         $aReturn = array();
93        
94         $poMap = $this->moMapObject->oMap;
95
96         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
97           $bCWCJSAPI = 1;
98         else
99           $bCWCJSAPI = 0;
100
101         if ($bCWCJSAPI)
102         {
103             $szJsFunctionName = "ProjectionLabelWRegisterForEvent";
104             $szFunction = <<<EOT
105 /**
106  * {$szJsFunctionName}
107  * called to register and even when the map extents changes (JSAPI)
108  */
109 function {$szJsFunctionName}()
110 {
111     goCWCJSAPI.RegisterEvent(MAP_PROJECTION_CHANGED, "ProjectionLabelWMapProjectionChanged");
112 }
113 EOT;
114    
115        $aReturn[$szJsFunctionName] = $szFunction;
116
117        $szJsFunctionName = "ProjectionLabelWMapProjectionChanged";
118        $szFunction = <<<EOT
119 /**
120  * {$szJsFunctionName}
121  * called when the projection is changed to update the projection label(JSAPI)
122  */
123 function {$szJsFunctionName}()
124 {
125     // loop through the array of valid projections and match to current
126     for (i=0; i<goCWCJSAPI.oMap.validprojections.length; i++)
127     {
128         if ( goCWCJSAPI.oMap.validprojections[i] == goCWCJSAPI.oMap.projection )
129         {
130             // match was found so get the text/name associated with it
131             {$this->mszHTMLForm}.txtProjectionLabel.value = goCWCJSAPI.oMap.validprojectionNames[i];
132             return;
133         }
134     }
135    
136     // if function gets here then error
137     {$this->mszHTMLForm}.txtProjectionLabel.value = 'Error: Projection Label not found.';
138 }
139 EOT;
140        $aReturn[$szJsFunctionName] = $szFunction;
141
142        }
143
144        return $aReturn;
145     }
146
147
148     /**
149      * return an array of javascript functions needed by Extent widget
150      * and called when the page is loaded.
151      * @return array of name = function values
152      */
153     function GetJavascriptOnLoadFunctions()
154     {
155         $aReturn = array();
156        
157         $aReturn = parent::GetJavascriptOnLoadFunctions();
158
159         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
160         {
161              $szJsFunctionName = "ProjectionLabelWRegisterForEvent";
162              $szFunction = "$szJsFunctionName();\n";
163              $aReturn[$szJsFunctionName] = $szFunction;
164         }
165
166         return $aReturn;
167     }   
168
169     /**
170      * draw this widget
171      */
172     function DrawPublish()
173     {
174
175         if (!$this->mbVisible)
176             return "<!-- ProjectionLabel is hidden -->";
177
178         $szValue = "";
179         $szClass = "";
180         $szStyle = "";
181
182         $szMapProj = $this->moMapObject->oMap->getprojection();
183         if (strncasecmp($szMapProj, "AUTO", 4) == 0) //assuming AUTO:42002,90001,45,75
184         {
185             $aProjElem = split(",", $szMapProj);
186             $szValue = $aProjElem[0];
187         }
188         else //assuming init:epsg....
189         {
190             $pos = strpos( $this->moMapObject->oMap->getprojection(), "epsg" );
191             if ($pos !== false)
192             {
193                 $szValue = substr($this->moMapObject->oMap->getprojection(), $pos );
194             }   
195         }
196
197         if (isset( $this->maSharedResourceWidgets["projection"]->maszContents["PROJECTION"]))
198         {
199             foreach( $this->maSharedResourceWidgets["projection"]->maszContents["PROJECTION"] as $aProj )
200             {
201                 if (strcasecmp($aProj["SRS"],$szValue) == 0)
202                 {
203                     $szValue = $aProj["NAME"];
204                     break;
205                 }
206             }
207         }
208
209         $nSize = $this->mnDefaultTextFieldSize;
210         if (isset($this->maParams["TextFieldSize"]))
211             $nSize = strtoupper($this->maParams["TextFieldSize"]);           
212            
213         $szClass = "";
214         if ( strlen($this->mszClass) > 0 )
215             $szClass = " CLASS=\"$this->mszClass\"";
216         $szStyle = "";
217         if ( strlen($this->mszStyle) > 0 )
218             $szStyle = " STYLE=\"$this->mszStyle\"";
219
220         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
221             $szContents="<input".$szClass.$szStyle." type=\"text\" name=\"txtProjectionLabel\" value=\"".$szValue."\" size=\"".strlen($szValue)."\" readonly>";
222         else
223             $szContents="<div".$szClass.$szStyle." name=\"txtProjectionLabel\">".$szValue."</div>";
224
225         return $this->moLabel->DrawPublish( $szContents );
226     }
227 }
228 ?>
Note: See TracBrowser for help on using the browser.