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

root/Chameleon/trunk/Chameleon/ROIManager/ROIManager.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ROIManager Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: ROIManager.widget.php,v 1.5 2004/12/03 03:31:56 pspencer Exp $
7  * @purpose     ROI Manager Widget class.  Allows the user to manage multiple ROIs
8  * a rectangular region of interest on the map. 
9  * @author      DM Solutions Group (spencer@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 include_once( dirname(__FILE__)."/../Widget.php");
32
33 /**
34  * ROIManager
35  *
36  * @desc A widget to manage multiple ROIs
37  */
38 class ROIManager extends CWCWidget
39 {
40     var $mnMode = 1;
41    
42     /* marquee color is the color that the rectangle is drawn in, default is blue */
43     var $mszEdgeColor = "0000FF";
44    
45     /* marquee width is the width in pixels of the marquee, default is 1 */
46     var $mnEdgeWidth = 2;
47    
48     /* use fill? */
49     var $mbFillROI = true;
50    
51     /* fill color */
52     var $mszFillColor = "0000FF";
53    
54     /* fill opacity */
55     var $mnFillOpacity = 25;
56    
57     var $mszOnROIChanged = "";
58    
59     /**
60      * construct a new ROI Rectangle Tool widget
61      */
62     function ROIManager()
63     {
64         // invoke constructor of parent
65         parent::CWCWidget();
66        
67         // set the description for this widget
68         $this->szWidgetDescription = <<<EOT
69 The ROIManager widget allows the user to draw multiple ROIs
70 EOT;
71
72         $this->maAttributes['MODE'] = new StringAttribute( 'MODE', false );
73         $this->maAttributes["EDGECOLOR"] = new HexColorAttribute( "EDGECOLOR", false );
74         $this->maAttributes["EDGEWIDTH"] = new IntegerAttribute( "EDGEWIDTH", false, 1 );
75         $this->maAttributes["FILLCOLOR"] = new HexColorAttribute( "FILLCOLOR", false );
76         $this->maAttributes["FILLOPACITY"] = new IntegerAttribute( "FILLOPACITY", false, 0, 100 );
77         $this->maAttributes["FILLROI"] = new BooleanAttribute( "FILLROI", false );
78         $this->maAttributes['ONROICHANGED'] = new StringAttribute( 'ONROICHANGED', false );
79         $this->mnMaturityLevel = MATURITY_BETA;
80     }
81    
82     /**
83      *
84      */
85     function InitDefaults()
86     {
87         parent::InitDefaults();
88        
89         if (isset($this->maParams['MODE']))
90         {
91             if (strcasecmp($this->maParams['MODE'], 'normal') == 0)
92             {
93                 $this->mnMode = 1;
94             }
95             elseif (strcasecmp($this->maParams['MODE'], 'add') == 0)
96             {
97                 $this->mnMode = 2;
98             }
99             elseif (strcasecmp($this->maParams['MODE'], 'subtract') == 0)
100             {
101                 $this->mnMode = 3;
102             }
103         }
104         if (isset($this->maParams["EDGECOLOR"]))
105             $this->mszEdgeColor = $this->maParams["EDGECOLOR"];
106         if (isset($this->maParams["ONROICHANGED"]))
107             $this->mszOnROIChanged = $this->maParams["ONROICHANGED"];
108         if (isset($this->maParams["EDGEWIDTH"]))
109             $this->mnEdgeWidth = $this->maParams["EDGEWIDTH"];   
110         if (isset($this->maParams["FILLCOLOR"]))
111             $this->mszFillColor = $this->maParams["FILLCOLOR"];
112         if (isset($this->maParams["FILLOPACITY"]))
113             $this->mnFillOpacity = $this->maParams["FILLOPACITY"];
114         if ($this->mnFillOpacity == 0)
115             $this->mbFillROI = false;
116         elseif (isset($this->maParams["FILLROI"]))
117             $this->mbFillROI = (strcasecmp($this->maParams["FILLROI"], "true") == 0) ? true : false; 
118     }
119    
120     function ParseURL()
121     {
122         if ($this->isVarSet( 'ROI_MODE' ))
123         {
124             $this->mnMode = $this->getVar( 'ROI_MODE' );
125         }
126        
127         // return success
128         return true;
129     }
130    
131     function GetHTMLHiddenVariables()
132     {
133         $aReturn = parent::GetHTMLHiddenVariables();
134        
135         $szVariable = "ROI_MODE";
136         $szValue = "<INPUT TYPE=\"HIDDEN\" NAME=\"".$szVariable."\" VALUE=\"".$this->mnMode."\">\n";
137         $aReturn[$szVariable] = $szValue;
138        
139         return $aReturn;
140     }
141    
142     /**
143      * GetJavascriptInitFunctions
144      *
145      * Functions to be called at the end of the load.
146      */
147     function GetJavascriptInitFunctions()
148     {
149         $szJsFunctionName = "ROIManagerInit";
150         $szFunction = "$szJsFunctionName();\n";
151         $aReturn[$szJsFunctionName] = $szFunction;
152
153         $aReturn['InitCWCROIManagerForm'] = 'goCWCROIManager.SetFormObject('.$this->mszHTMLForm.');';
154         if (isset($this->mszOnROIChanged) && $this->mszOnROIChanged != "")
155         {
156             $aReturn['InitCWCROIManagerForm'] .= "\ngoCWCROIManager.RegisterEvent( ROI_CHANGED, \"".$this->mszOnROIChanged."\");";
157         }
158        
159         return $aReturn;
160     }
161
162     /**
163      * javascript include files
164      */
165     function GetJavascriptIncludeFunctions()
166     {
167         $aReturn = parent::GetJavascriptIncludeFunctions();
168        
169         $szVar = "cwc_roi.js";
170         $aReturn[$szVar] = '<script src="'.$_SESSION['gszCoreWebPath'].
171                             '/widgets/js/cwc_roi.js" type="text/javascript"></script>';
172        
173         $szVar = "cwc_dhtml.js";
174         $aReturn[$szVar] = '<script src="'.$_SESSION['gszCoreWebPath'].
175                             '/widgets/js/cwc_dhtml.js" type="text/javascript"></script>';
176         return $aReturn;
177     }
178
179     /**
180      * @desc general javascript functions
181      */
182     function GetJavascriptFunctions()
183     {
184         $aReturn = parent::GetJavascriptFunctions();
185
186         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
187           $bCWCJSAPI = 1;
188         else
189           $bCWCJSAPI = 0;
190          
191         $minX = $this->moMapObject->oMap->extent->minx;
192         $maxX = $this->moMapObject->oMap->extent->maxx;
193         $minY = $this->moMapObject->oMap->extent->miny;
194         $maxY = $this->moMapObject->oMap->extent->maxy;
195        
196         $width = $this->moMapObject->oMap->width;
197         $height = $this->moMapObject->oMap->height;
198        
199         if ( isset( $_SESSION['gszCoreWebPath'] ) )
200             $szTmpCoreWebPath = $_SESSION['gszCoreWebPath'];
201         else
202             $szTmpCoreWebPath = "";
203        
204         $szRendererURL = $szTmpCoreWebPath."/widgets/ROIManager/ROIRenderer.php?".SID;
205                
206         $szName = 'ROIManagerInit';
207         $szFunction = <<<EOT
208 function {$szName}()
209 {
210     var x = CWCDHTML_FindObjectPosX( CWCDHTML_GetImage('mapFrameTL'));
211     var y = CWCDHTML_FindObjectPosY( CWCDHTML_GetImage('mapFrameTL'));
212     goCWCROIManager.SetPixelExtents( x, y,  x+{$width}, y+{$height})
213     goCWCROIManager.SetGeoExtents( {$minX}, {$minY}, {$maxX}, {$maxY});
214     goCWCROIManager.SetRendererURL( "{$szRendererURL}" );
215     goCWCROIManager.szEdgeColor = "{$this->mszEdgeColor}";
216     goCWCROIManager.nEdgeWidth = {$this->mnEdgeWidth};
217     goCWCROIManager.szFillColor = "{$this->mszEdgeColor}";
218     goCWCROIManager.nFillOpacity = {$this->mnFillOpacity};
219     goCWCROIManager.bUseFill = {$this->mbFillROI};
220    
221     ROIManagerCreateDHTMLLayers();
222 }
223 EOT;
224         $aReturn[$szName] = $szFunction;
225        
226        
227         $szName = 'ROIManagerCreateDHTMLLayers';
228         $szFunction = <<<EOT
229 function {$szName}()
230 {
231     var szRendererURL = goCWCROIManager.GetRendererURL();
232     var x = goCWCROIManager.pixMinX;
233     var y = goCWCROIManager.pixMinY;
234     var width = goCWCROIManager.pixMaxX - x;
235     var height = goCWCROIManager.pixMaxY - y;
236     var content = '<img name="ROIRenderer" id="ROIRenderer" src="' + szRendererURL + '&mode=0" border="0" width="' + width + '" height="' + height + '"' + 'onmouseover="MapWCaptureMouse();"onmouseout="MapWReleaseMouse()"' + '>' ;
237     CWCDHTML_CreateLayer(gROIRenderer, x, y, width, height, true, content);
238     CWCDHTML_HideLayer( gROIRenderer );
239     CWCDHTML_SetLayerZOrder( gROIRenderer, 12 );
240     if (CWCIsIE)
241     {
242         CWCDHTML_SetLayerOpacity( gROIRenderer, goCWCROIManager.nFillOpacity );
243     }
244 }
245 EOT;
246         $aReturn[$szName] = $szFunction;
247
248         return $aReturn;
249     }
250
251     /**
252      * GetJavascriptOnLoadFunctions
253      *
254      * Return JS code to be run in the onload function
255      */
256     function GetJavascriptOnloadFunctions()
257     {
258         $aReturn = array();
259      
260         return $aReturn;
261     }
262
263    
264     /**
265      * GetJavascriptVariables
266      *
267      * Return JS global variables and global code.
268      */
269     function GetJavascriptVariables()
270     {
271         $aReturn = array();
272
273         $szVariable = "gROIRenderer";
274         $szValue = " var $szVariable = \"gROIRenderer\";\n";
275         $aReturn[$szVariable] = $szValue;
276        
277         return $aReturn;
278     }
279 }
280 ?>
Note: See TracBrowser for help on using the browser.