1 |
<?php |
---|
2 |
/** |
---|
3 |
* LayerManagerAction Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: |
---|
7 |
* @purpose LayerManagerAction Widget class |
---|
8 |
* @author DM Solutions Group (sacha@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__)."/../Button.php"); |
---|
31 |
|
---|
32 |
/** |
---|
33 |
* LayerOrderUp |
---|
34 |
* |
---|
35 |
* @desc Display a clickable image that will update the map |
---|
36 |
*/ |
---|
37 |
class LayerManagerAction extends CWCWidget |
---|
38 |
{ |
---|
39 |
var $mszAction; |
---|
40 |
var $moButton; |
---|
41 |
var $mszCurrentState = ""; |
---|
42 |
|
---|
43 |
/** |
---|
44 |
* LayerManagerAction |
---|
45 |
* |
---|
46 |
* Constructor for the LayerManagerAction |
---|
47 |
*/ |
---|
48 |
function LayerManagerAction() |
---|
49 |
{ |
---|
50 |
// invoke constructor of parent |
---|
51 |
parent::CWCWidget(); |
---|
52 |
|
---|
53 |
$this->moParent =& $oParent; |
---|
54 |
$this->mnPriority = PRIORITY_HIGH; |
---|
55 |
|
---|
56 |
// set the description for this widget |
---|
57 |
$this->szWidgetDescription = <<<EOT |
---|
58 |
See alse the UpdateMap Widget |
---|
59 |
The LayerManagerAction widget will possibly cause the layerorder to be changed |
---|
60 |
See visibility checkbox handling |
---|
61 |
EOT; |
---|
62 |
$this->maAttributes["ACTION"] = new StringAttribute( "ACTION", true, array("UP", "DOWN", "DELETE", "APPLY") ); |
---|
63 |
|
---|
64 |
$this->moButton = new CWCButton($this); |
---|
65 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
66 |
} |
---|
67 |
|
---|
68 |
/** |
---|
69 |
* Get LayerManager action |
---|
70 |
*/ |
---|
71 |
function InitDefaults() |
---|
72 |
{ |
---|
73 |
parent::InitDefaults(); |
---|
74 |
$this->moButton->InitDefaults(); |
---|
75 |
|
---|
76 |
$this->mszAction = $this->maParams['ACTION']; |
---|
77 |
|
---|
78 |
$this->moButton->SetOnClick( "clickLayerManagerAction", $this->mszAction ); |
---|
79 |
} |
---|
80 |
|
---|
81 |
/** |
---|
82 |
* GetHTMLHiddenVariables |
---|
83 |
* |
---|
84 |
* Return HTML hidden variables. |
---|
85 |
*/ |
---|
86 |
function GetHTMLHiddenVariables() |
---|
87 |
{ |
---|
88 |
$aReturn = array_merge($this->moButton->GetHTMLHiddenVariables(), parent::GetHTMLHiddenVariables()); |
---|
89 |
|
---|
90 |
$szVariable = "LAYERMANAGER_ACTION"; |
---|
91 |
$szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">"; |
---|
92 |
$aReturn[$szVariable] = $szValue; |
---|
93 |
|
---|
94 |
if ($this->mszCurrentState != "") |
---|
95 |
{ |
---|
96 |
$szVariable = "LAYERMANAGER_CURRENT_STATE"; |
---|
97 |
$szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"".$this->mszCurrentState."\">"; |
---|
98 |
$aReturn[$szVariable] = $szValue; |
---|
99 |
} |
---|
100 |
|
---|
101 |
return $aReturn; |
---|
102 |
} |
---|
103 |
|
---|
104 |
/** |
---|
105 |
* GetJavascriptFunctions |
---|
106 |
* |
---|
107 |
* Return the Javacriptfunctions needed by the widget. |
---|
108 |
*/ |
---|
109 |
function GetJavascriptFunctions() |
---|
110 |
{ |
---|
111 |
$aReturn = $this->moButton->GetJavascriptFunctions();; |
---|
112 |
|
---|
113 |
$szJsFunctionName = "clickLayerManagerAction"; |
---|
114 |
$szFunction = <<<EOT |
---|
115 |
/** |
---|
116 |
* {$szJsFunctionName} |
---|
117 |
* called when the user clicks the LayerOrderUp icon |
---|
118 |
*/ |
---|
119 |
function {$szJsFunctionName}(obj, szAction) |
---|
120 |
{ |
---|
121 |
{$this->mszHTMLForm}['LAYERMANAGER_ACTION'].value = szAction; |
---|
122 |
{$this->mszHTMLForm}.submit(); |
---|
123 |
|
---|
124 |
return; |
---|
125 |
} |
---|
126 |
EOT; |
---|
127 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
128 |
|
---|
129 |
$szJsFunctionName = "LayerManagerApplyChanges"; |
---|
130 |
$szFunction = <<<EOT |
---|
131 |
/** |
---|
132 |
* {$szJsFunctionName} |
---|
133 |
* called when the user clicks Apply |
---|
134 |
*/ |
---|
135 |
function {$szJsFunctionName}() |
---|
136 |
{ |
---|
137 |
opener.LayerManagerCallBack(0, this); |
---|
138 |
|
---|
139 |
return; |
---|
140 |
} |
---|
141 |
EOT; |
---|
142 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
143 |
|
---|
144 |
return $aReturn; |
---|
145 |
} |
---|
146 |
|
---|
147 |
/** |
---|
148 |
* GetJavascriptOnLoadFunctions |
---|
149 |
* |
---|
150 |
* On load functions. |
---|
151 |
*/ |
---|
152 |
function GetJavascriptOnLoadFunctions() |
---|
153 |
{ |
---|
154 |
$aReturn = $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
155 |
|
---|
156 |
if ($this->isVarSet('LAYERMANAGER_ACTION') && |
---|
157 |
$this->getVar('LAYERMANAGER_ACTION') == "APPLY" && |
---|
158 |
$this->mszAction == "APPLY") |
---|
159 |
$aReturn['LayerManagerApplyChanges'] = "LayerManagerApplyChanges();\n"; |
---|
160 |
|
---|
161 |
return $aReturn; |
---|
162 |
} |
---|
163 |
|
---|
164 |
|
---|
165 |
/** |
---|
166 |
* GetJavascriptInitFunctions |
---|
167 |
* |
---|
168 |
* On init functions. |
---|
169 |
*/ |
---|
170 |
function GetJavascriptInitFunctions() |
---|
171 |
{ |
---|
172 |
$aReturn = $this->moButton->GetJavascriptInitFunctions(); |
---|
173 |
|
---|
174 |
return $aReturn; |
---|
175 |
} |
---|
176 |
|
---|
177 |
/** |
---|
178 |
* GetJavascriptIncludeFunctions() |
---|
179 |
* |
---|
180 |
* On init functions. |
---|
181 |
*/ |
---|
182 |
function GetJavascriptIncludeFunctions() |
---|
183 |
{ |
---|
184 |
$aReturn = $this->moButton->GetJavascriptIncludeFunctions(); |
---|
185 |
|
---|
186 |
return $aReturn; |
---|
187 |
} |
---|
188 |
|
---|
189 |
/** |
---|
190 |
* DrawPublish |
---|
191 |
* |
---|
192 |
* Return the HTML code using the name in the map file and the |
---|
193 |
* parameters of the CWC tag. |
---|
194 |
*/ |
---|
195 |
function DrawPublish() |
---|
196 |
{ |
---|
197 |
if (!$this->mbVisible) |
---|
198 |
return "<!-- LayerManagerAction widget hidden -->"; |
---|
199 |
|
---|
200 |
return $this->moButton->DrawPublish(); |
---|
201 |
} |
---|
202 |
/** |
---|
203 |
* ParseURL |
---|
204 |
* |
---|
205 |
* Look for selected layers and move them Up or Down or Delete. |
---|
206 |
*/ |
---|
207 |
function ParseURL() |
---|
208 |
{ |
---|
209 |
$this->moButton->ParseURL(); |
---|
210 |
if ($this->isVarSet("LAYERMANAGER_ACTION") && |
---|
211 |
$this->getVar("LAYERMANAGER_ACTION") == $this->mszAction) |
---|
212 |
{ |
---|
213 |
// create a new map session object |
---|
214 |
$oNewMapSession = new MapSession_RW; |
---|
215 |
|
---|
216 |
// set the temp directory for the map session |
---|
217 |
$oNewMapSession->setTempDir( $_SESSION['gszTmpPath'] ); |
---|
218 |
|
---|
219 |
if (!$this->isVarSet("LAYERMANAGER_CURRENT_STATE") || |
---|
220 |
$this->getVar("LAYERMANAGER_CURRENT_STATE") == "") |
---|
221 |
{ |
---|
222 |
$oNewMapSession->restoreState( $_SESSION["gszCurrentState"], |
---|
223 |
$_SESSION['gszMapName'], |
---|
224 |
dirname($_SESSION['gszMapName'] ) ); |
---|
225 |
} |
---|
226 |
else |
---|
227 |
{ |
---|
228 |
$oNewMapSession->restoreState( $this->getVar("LAYERMANAGER_CURRENT_STATE"), |
---|
229 |
$_SESSION['gszMapName'], |
---|
230 |
dirname($_SESSION['gszMapName'] ) ); |
---|
231 |
|
---|
232 |
// restore projection, extent and mapsize |
---|
233 |
$oNewMapSession->oMap->setProjection($this->moMapObject->oMap->getProjection(), |
---|
234 |
true); |
---|
235 |
$oNewMapSession->oMap->setextent($this->moMapObject->oMap->extent->minx, |
---|
236 |
$this->moMapObject->oMap->extent->miny, |
---|
237 |
$this->moMapObject->oMap->extent->maxx, |
---|
238 |
$this->moMapObject->oMap->extent->maxy); |
---|
239 |
$oNewMapSession->oMap->set("width", $this->moMapObject->oMap->width); |
---|
240 |
$oNewMapSession->oMap->set("height", $this->moMapObject->oMap->height); |
---|
241 |
} |
---|
242 |
|
---|
243 |
// Make sure the imageurl and imagepath are set to chameleon configuration |
---|
244 |
$oNewMapSession->oMap->web->set("imageurl", $_SESSION['gszTmpWebPath']); |
---|
245 |
$oNewMapSession->oMap->web->set("imagepath", $_SESSION['gszTmpImgPath']); |
---|
246 |
$oNewMapSession->oMap->selectOutputFormat($_SESSION['gszImgType']); |
---|
247 |
|
---|
248 |
$oMap =& $oNewMapSession->oMap; |
---|
249 |
|
---|
250 |
//Get the Layer selected by radio button |
---|
251 |
$szSelectedLayer = $this->getVar('LAYERMANAGER_LAYER'); |
---|
252 |
|
---|
253 |
// Get the Layer(s) sleected by checkbox. |
---|
254 |
$aszSelectedVisibleLayers = ($this->isVarSet('LAYERMANAGER_LAYERS')) ? |
---|
255 |
$this->getVar('LAYERMANAGER_LAYERS') : array(); |
---|
256 |
|
---|
257 |
// check for visibility. |
---|
258 |
for($i=0; $i < $oMap->numlayers; $i++) |
---|
259 |
{ |
---|
260 |
$oLayer = $oMap->getLayer($i); |
---|
261 |
|
---|
262 |
if (in_array($oLayer->name, $aszSelectedVisibleLayers)) |
---|
263 |
$oLayer->set('status', MS_ON); |
---|
264 |
else |
---|
265 |
$oLayer->set('status', MS_OFF); |
---|
266 |
} |
---|
267 |
|
---|
268 |
for($i=0; $i < $oMap->numlayers; $i++) |
---|
269 |
{ |
---|
270 |
$oLayer = $oMap->getLayer($i); |
---|
271 |
|
---|
272 |
if ($oLayer->name == $szSelectedLayer) |
---|
273 |
{ |
---|
274 |
if ($this->mszAction == "DOWN") |
---|
275 |
$oMap->moveLayerUp($i); //lower in mapfile is higher in the layerlist |
---|
276 |
else |
---|
277 |
if ($this->mszAction == "UP") |
---|
278 |
$oMap->moveLayerDown($i); //Higher in mapfile is lower in the layerlist |
---|
279 |
else |
---|
280 |
if ($this->mszAction == "DELETE") |
---|
281 |
$oLayer->set('status', MS_DELETE); // Delete layer from mapfile |
---|
282 |
|
---|
283 |
// Stop looping throught layers. |
---|
284 |
break; |
---|
285 |
} |
---|
286 |
} |
---|
287 |
|
---|
288 |
$aszLayerNames = $oMap->getAllLayerNames(); |
---|
289 |
|
---|
290 |
if ($this->mszAction == "APPLY") |
---|
291 |
{ |
---|
292 |
// check for visibility. |
---|
293 |
for($i=0; $i < $this->moMapObject->oMap->numlayers; $i++) |
---|
294 |
{ |
---|
295 |
$oLayer = $this->moMapObject->oMap->getLayer($i); |
---|
296 |
|
---|
297 |
if (in_array($oLayer->name, $aszLayerNames)) |
---|
298 |
{ |
---|
299 |
if (in_array($oLayer->name, $aszSelectedVisibleLayers)) |
---|
300 |
$oLayer->set('status', MS_ON); |
---|
301 |
else |
---|
302 |
$oLayer->set('status', MS_OFF); |
---|
303 |
} |
---|
304 |
else |
---|
305 |
{ |
---|
306 |
$oLayer->set('status', MS_DELETE); |
---|
307 |
} |
---|
308 |
} |
---|
309 |
|
---|
310 |
$anLayers = $oNewMapSession->oMap->getLayersDrawingOrder(); |
---|
311 |
$anOrder = array(); |
---|
312 |
for($i=0; $i < $oNewMapSession->oMap->numlayers; $i++) |
---|
313 |
for($j=0; $j < $this->moMapObject->oMap->numlayers; $j++) |
---|
314 |
{ |
---|
315 |
$oLayer1 = $this->moMapObject->oMap->getLayer($j); |
---|
316 |
$oLayer2 = $oNewMapSession->oMap->getLayer($i); |
---|
317 |
|
---|
318 |
if ($oLayer1->name == $oLayer2->name) |
---|
319 |
$anOrder[$i] = $j; |
---|
320 |
} |
---|
321 |
|
---|
322 |
$this->moMapObject->oMap->setLayersDrawingOrder($anOrder); |
---|
323 |
} |
---|
324 |
|
---|
325 |
$this->mszCurrentState = urlencode($oNewMapSession->saveState()); |
---|
326 |
|
---|
327 |
$this->setVar("LAYERMANAGER_CURRENT_STATE", $this->mszCurrentState); |
---|
328 |
} |
---|
329 |
|
---|
330 |
return true; |
---|
331 |
} |
---|
332 |
} |
---|
333 |
?> |
---|