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

root/Chameleon/trunk/Chameleon/RemoveLayer/RemoveLayer.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3 * RemoveLayer Widget class
4 *
5 * @project     CWC2
6 * @revision    $Id: RemoveLayer.widget.php,v 1.3 2005/05/27 20:07:35 bartvde Exp $
7 * @purpose     RemoveLayer Widget class
8 * @author      DM Solutions Group (pspencer@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 /* based on Code provided by GeoDan */
31
32 include_once(dirname(__FILE__)."/../Widget.php");
33 include_once(dirname(__FILE__)."/../Button.php");
34
35 /**
36 * RemoveLayer
37 *
38 * @desc Display a clickable image that will update the map
39 */
40 class RemoveLayer extends CWCWidget
41 {
42
43         /**
44         * RemoveLayer
45         *
46         * Constructor for the RemoveLayer
47         */
48         function RemoveLayer()
49         {
50                 // invoke constructor of parent
51                 parent::CWCWidget();
52                 $this->mnPriority = PRIORITY_HIGH;
53
54                 // set the description for this widget
55                 $this->szWidgetDescription = <<<EOT
56 The RemoveLayer widget removes the selected layer(s) from the map.  This widget uses
57 the SelectLayer widget which works best with the HTML LegendTemplate widget.
58 EOT;
59
60                 $this->moButton = new CWCButton($this);
61                 $this->moButton->SetOnClick( "clickRemoveLayer" );
62         $this->mnMaturityLevel = MATURITY_BETA;
63         }
64
65         function InitDefaults()
66         {
67                 parent::InitDefaults();
68                 $this->moButton->InitDefaults();
69         }
70
71         /**
72         * GetHTMLHiddenVariables
73         *
74         * Return HTML hidden variables.
75         */
76         function GetHTMLHiddenVariables()
77         {
78                 $szVariable = "REMOVE_LAYER".$this->mnId;
79                 $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
80                 $aReturn[$szVariable] = $szValue;
81                 return $aReturn;
82         }
83
84         /**
85         * GetJavascriptFunctions
86         *
87         * Return the Javacriptfunctions needed by the widget.
88         */
89         function GetJavascriptFunctions()
90         {
91                 $aReturn = $this->moButton->GetJavascriptFunctions();
92
93                 $szJsFunctionName = "clickRemoveLayer";
94                 $nId = $this->mnId;
95                 $szFunction = <<<EOT
96 /**
97  * {$szJsFunctionName}
98  * called when the user clicks the RemoveLayer icon
99  */
100
101 function {$szJsFunctionName}()
102 {
103     with({$this->mszHTMLForm})
104     {
105        REMOVE_LAYER{$nId}.value = "1";
106        submit();
107     }
108     return;
109 }
110
111 EOT;
112                 $aReturn[$szJsFunctionName] = $szFunction;
113
114                 return $aReturn;
115         }
116         /**
117         * return javascript functions
118         */
119         function GetJavascriptIncludeFunctions()
120         {
121                 return $this->moButton->GetJavascriptIncludeFunctions();
122         }
123
124         /**
125         * return javascript variables
126         */
127         function GetJavascriptVariables()
128         {
129                 return $this->moButton->GetJavascriptVariables();
130         }
131
132         /**
133         * return javascript onload functions
134         */
135         function GetJavascriptOnLoadFunctions()
136         {
137                 return $this->moButton->GetJavascriptOnLoadFunctions();
138         }
139
140         /**
141         * return javascript initialization funcitons
142         */
143         function GetJavascriptInitFunctions()
144         {
145                 return $this->moButton->GetJavascriptInitFunctions();
146         }
147
148         /**
149         * DrawPublish
150         *
151         * Return the HTML code using the name in the map file and the
152         * parameters of the CWC tag.
153         */
154         function DrawPublish()
155         {
156                 if (!$this->mbVisible)
157                         return "<!-- RemoveLayer widget hidden -->";
158                 return $this->moButton->DrawPublish();
159         }
160         /**
161         * ParseURL
162         *
163         * Look for selected layers and move them UP
164         */
165         function  ParseURL()
166         {
167                 if ($this->isVarSet('REMOVE_LAYER'.$this->mnId) &&
168                 $this->getVar('REMOVE_LAYER'.$this->mnId) == "1")
169                 {
170                         $oMap = $this->moMapObject->oMap;
171
172                         $aszSelectedLayers = array();
173                         if ($this->isVarSet('SELECTED_LAYERS'))
174                         {
175                                 $szSelectedLayers = $this->getVar( 'SELECTED_LAYERS' );
176                                 if (strlen($szSelectedLayers) > 0)
177                                 {
178                                         $aszSelectedLayers = explode( ",", $szSelectedLayers );
179                                 }
180                         }
181                         else
182                         {
183                                 $nLayers = $oMap->numlayers();
184                                 for ($i=0;$i<$nLayers;$i++)
185                                 {
186                                         $oLayer=$oMap->getLayer($i);
187                                         if ($oLayer->getMetaData("selected") == "1")
188                                         array_push($aszSelectedLayers, $oLayer->name);
189                                 }
190                         }
191
192                         if (count($aszSelectedLayers) > 0)
193                         {
194                                 $nLayers = $oMap->numlayers;
195                                 for($i=0; $i < $nLayers; $i++)
196                                 {
197                                         $oLayer = $oMap->getLayer($i);
198                                         if (in_array( $oLayer->name, $aszSelectedLayers ))
199                                         {
200                                                 $oLayer->set( "status", MS_DELETE );
201                                         }
202                                 }
203                         }
204                         $this->setVar('SELECTED_LAYERS', "");
205                 }
206                 return true;
207         }
208 }
209 ?>
Note: See TracBrowser for help on using the browser.