1 |
<?php |
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 |
|
---|
8 |
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 |
|
---|
13 |
|
---|
14 |
|
---|
15 |
|
---|
16 |
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 |
|
---|
21 |
|
---|
22 |
|
---|
23 |
|
---|
24 |
|
---|
25 |
|
---|
26 |
|
---|
27 |
|
---|
28 |
|
---|
29 |
include_once(dirname(__FILE__)."/../Widget.php"); |
---|
30 |
include_once(dirname(__FILE__)."/../Button.php"); |
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 |
class LayerManagerAction extends CWCWidget |
---|
38 |
{ |
---|
39 |
var $mszAction; |
---|
40 |
var $moButton; |
---|
41 |
var $mszCurrentState = ""; |
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 |
|
---|
48 |
function LayerManagerAction() |
---|
49 |
{ |
---|
50 |
|
---|
51 |
parent::CWCWidget(); |
---|
52 |
|
---|
53 |
$this->moParent =& $oParent; |
---|
54 |
$this->mnPriority = PRIORITY_HIGH; |
---|
55 |
|
---|
56 |
|
---|
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 |
|
---|
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 |
|
---|
83 |
|
---|
84 |
|
---|
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 |
|
---|
106 |
|
---|
107 |
|
---|
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 |
|
---|
149 |
|
---|
150 |
|
---|
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 |
|
---|
167 |
|
---|
168 |
|
---|
169 |
|
---|
170 |
function GetJavascriptInitFunctions() |
---|
171 |
{ |
---|
172 |
$aReturn = $this->moButton->GetJavascriptInitFunctions(); |
---|
173 |
|
---|
174 |
return $aReturn; |
---|
175 |
} |
---|
176 |
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 |
|
---|
182 |
function GetJavascriptIncludeFunctions() |
---|
183 |
{ |
---|
184 |
$aReturn = $this->moButton->GetJavascriptIncludeFunctions(); |
---|
185 |
|
---|
186 |
return $aReturn; |
---|
187 |
} |
---|
188 |
|
---|
189 |
|
---|
190 |
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 |
|
---|
195 |
function DrawPublish() |
---|
196 |
{ |
---|
197 |
if (!$this->mbVisible) |
---|
198 |
return "<!-- LayerManagerAction widget hidden -->"; |
---|
199 |
|
---|
200 |
return $this->moButton->DrawPublish(); |
---|
201 |
} |
---|
202 |
|
---|
203 |
|
---|
204 |
|
---|
205 |
|
---|
206 |
|
---|
207 |
function ParseURL() |
---|
208 |
{ |
---|
209 |
$this->moButton->ParseURL(); |
---|
210 |
if ($this->isVarSet("LAYERMANAGER_ACTION") && |
---|
211 |
$this->getVar("LAYERMANAGER_ACTION") == $this->mszAction) |
---|
212 |
{ |
---|
213 |
|
---|
214 |
$oNewMapSession = new MapSession_RW; |
---|
215 |
|
---|
216 |
|
---|
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 |
|
---|
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 |
|
---|
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 |
|
---|
251 |
$szSelectedLayer = $this->getVar('LAYERMANAGER_LAYER'); |
---|
252 |
|
---|
253 |
|
---|
254 |
$aszSelectedVisibleLayers = ($this->isVarSet('LAYERMANAGER_LAYERS')) ? |
---|
255 |
$this->getVar('LAYERMANAGER_LAYERS') : array(); |
---|
256 |
|
---|
257 |
|
---|
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); |
---|
276 |
else |
---|
277 |
if ($this->mszAction == "UP") |
---|
278 |
$oMap->moveLayerDown($i); |
---|
279 |
else |
---|
280 |
if ($this->mszAction == "DELETE") |
---|
281 |
$oLayer->set('status', MS_DELETE); |
---|
282 |
|
---|
283 |
|
---|
284 |
break; |
---|
285 |
} |
---|
286 |
} |
---|
287 |
|
---|
288 |
$aszLayerNames = $oMap->getAllLayerNames(); |
---|
289 |
|
---|
290 |
if ($this->mszAction == "APPLY") |
---|
291 |
{ |
---|
292 |
|
---|
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 |
?> |
---|
334 |
|
---|