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

root/Chameleon/trunk/Chameleon/SelectLayers/SelectLayers.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * SelectLayers Widget class
4  *
5  * @project     GeoDan
6  * @revision    $Id: SelectLayers.widget.php,v 1.6 2005/01/19 01:53:02 pspencer Exp $
7  * @purpose     Select layers so that other widgets can do something to them.
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 include_once(dirname(__FILE__)."/../Widget.php");
31
32 /**
33  * SelectLayers
34  *
35  * @desc SelectLayers widget.
36  */
37 class SelectLayers extends CWCWidget
38 {
39     /**
40      * SelectLayers
41      *
42      * Constructor. Set the default values.
43      */
44     function SelectLayers()
45     {
46         // invoke constructor of parent
47         parent::CWCWidget();
48
49         // set the description for this widget
50         $this->szWidgetDescription = <<<EOT
51 The purpose of the Select Layers widget is to provide a mechanism via
52 javascript by which layers can be marked as selected for other widgets. This
53 could be used for changing layer order, querying or filtering a layer, or
54 extracting from a specific layer.  The widget is most useful when used with
55 an appropriate HTML legend and the LegendTemplate widget
56 EOT;
57         $this->mnMaturityLevel = MATURITY_BETA;
58
59      }
60
61     /**
62      * GetHTMLHiddenVariables
63      *
64      * return the NAV_CMD varaiable.
65      *
66      * @return NAV_CMD variable.
67      */
68     function GetHTMLHiddenVariables()
69     {
70         $szSelectedLayers = "";
71         $szSep = "";
72         $oMap = $this->moMapObject->oMap;
73         for($i=0; $i<$oMap->numlayers; $i++)
74         {
75             $oLayer = $oMap->getLayer($i);
76             if ($oLayer->getMetaData( "selected" ) == "1")
77             {
78                 $szSelectedLayers .= $szSep.($oLayer->name);
79                 $szSep = ",";
80             }
81         }
82         //get selected layers here.
83         $szVariable = "SELECTED_LAYERS";
84         $szValue = " <INPUT TYPE=\"HIDDEN\" NAME=\"$szVariable\" VALUE=\"$szSelectedLayers\">\n";
85         $aReturn[$szVariable] = $szValue;
86
87         return $aReturn;
88     }
89    
90     /**
91      * javascript include files
92      */
93     function GetJavascriptIncludeFunctions()
94     {
95         $aReturn = parent::GetJavascriptIncludeFunctions();
96        
97         $szVar = "cwc_events.js";
98         $aReturn[$szVar] = '<script src="'.$_SESSION['gszCoreWebPath'].
99                             '/widgets/js/cwc_events.js" type="text/javascript"></script>';
100        
101         return $aReturn;
102     }
103    
104     /**
105      * GetJavascriptOnLoadFunctions
106      */
107     function GetJavascriptInitFunctions()
108     {
109         $aResult = array();
110        
111         $aResult['SelectLayersRegisterEvent'] = "goEventManager.registerEventID( 'LAYER_SELECTION_CHANGED' );\n";
112        
113         return $aResult;
114     }
115      
116
117     /**
118      * GetJavascriptFunctions
119      *
120      * Return the Javacriptfunctions needed by the widget.
121      *
122      * @return Javacriptfunctions needed by the widget.
123      */
124     function GetJavascriptFunctions()
125     {
126         $szJsFunctionName = "CWCSelectLayer";
127         $szFunction = <<<EOT
128 /**
129  * {$szJsFunctionName}
130  * called to set a layer as selected.  If the layer is already selected, then
131  * it deselects the layer.  Returns true if the layer was added, false otherwise.
132  */
133 function {$szJsFunctionName}( szLayerName, bSingle )
134 {
135     with({$this->mszHTMLForm})
136     {
137         var aszLayers;
138         if (bSingle)
139         {
140             aszLayers = new Array();
141         }
142         else
143         {
144             aszLayers = SELECTED_LAYERS.value.split( "," );
145         }
146         var aszNewLayers = new Array();
147         var i;
148         var bNewLayer = true;
149         for (i=0; i < aszLayers.length; i++)
150         {
151             if (szLayerName == aszLayers[i])
152             {
153                 bNewLayer = false;
154             }
155             else
156             {
157                 aszNewLayers[aszNewLayers.length] = aszLayers[i];
158             }
159         }
160         if (bNewLayer)
161         {
162             aszNewLayers[aszNewLayers.length] = szLayerName;
163         }
164         SELECTED_LAYERS.value = aszNewLayers.toString();
165     }
166    
167     goEventManager.triggerEvent( 'LAYER_SELECTION_CHANGED' );
168    
169     return bNewLayer;
170 }
171 EOT;
172         $aReturn[$szJsFunctionName] = $szFunction;
173
174         return $aReturn;
175     }
176
177     /**
178      * ParseURL
179      *
180      * Look for selected layers and mark them as such.
181      */
182     function  ParseURL()
183     {
184         $oMap = $this->moMapObject->oMap;
185         if ($this->isVarSet( 'SELECTED_LAYERS' ))
186         {
187             $aszSelectedLayers = array();
188             if (strlen($this->getVar( 'SELECTED_LAYERS' )) > 0)
189             {
190                 $aszSelectedLayers = explode( ",", $this->getVar( 'SELECTED_LAYERS' ) );
191             }
192            
193             for($i=0; $i<$oMap->numlayers; $i++)
194             {
195                 $oLayer = $oMap->getLayer($i);
196                 if (in_array( $oLayer->name, $aszSelectedLayers ))
197                 {
198                     $oLayer->setMetaData( "selected", "1" );
199                 }
200                 else
201                 {
202                     $oLayer->setMetaData( "selected", "0" );
203                 }
204             }
205         }
206         else
207         {
208             $bHasSelected = false;
209             for($i=0; $i<$oMap->numlayers; $i++)
210             {
211                 $oLayer = $oMap->getLayer($i);
212                 $szSelected = $oLayer->getMetaData( "selected" );
213                 if ($szSelected != "")
214                 {
215                     $bHasSelected = true;
216                     break;
217                 }
218             }           
219             if (!$bHasSelected && $oMap->numlayers > 0)
220             {
221                 $oLayer = $oMap->getLayer( 0 );
222                 $oLayer->setMetaData( "selected", "1" );
223             }
224         }
225         // return success
226         return true;
227     }
228 }
229 ?>
Note: See TracBrowser for help on using the browser.