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__)."/../Label.php"); |
---|
31 |
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 |
class Extent extends CWCWidget |
---|
36 |
{ |
---|
37 |
var $moLabel; |
---|
38 |
var $mszClass = "CWCExtentWidgetClass"; |
---|
39 |
var $mszStyle = ""; |
---|
40 |
var $mszExtent = ""; |
---|
41 |
var $mnDefaultTextFieldSize = 20; |
---|
42 |
|
---|
43 |
|
---|
44 |
|
---|
45 |
|
---|
46 |
function Extent( ) |
---|
47 |
{ |
---|
48 |
|
---|
49 |
parent::CWCWidget(); |
---|
50 |
|
---|
51 |
|
---|
52 |
$this->szWidgetDescription = <<<EOT |
---|
53 |
The Extent widget displays one of the extents of the map in text on the |
---|
54 |
output page. |
---|
55 |
EOT; |
---|
56 |
|
---|
57 |
$this->moLabel = new CWCLabel($this); |
---|
58 |
$this->maAttributes["EXTENT"] = new StringAttribute( "EXTENT", true, |
---|
59 |
array( "MINX", "MINY", "MAXX", "MAXY" ) ); |
---|
60 |
$this->maAttributes["WIDGETCLASS"] = new StringAttribute( "WIDGETCLASS", false ); |
---|
61 |
$this->maAttributes["WIDGETSTYLE"] = new StringAttribute( "WIDGETSTYLE", false ); |
---|
62 |
$this->maAttributes["TEXTFIELDSIZE"] = new IntegerAttribute( "TEXTFIELDSIZE", false, 0 ); |
---|
63 |
$this->mnMaturityLevel = MATURITY_TECHNICALRELEASE; |
---|
64 |
} |
---|
65 |
|
---|
66 |
|
---|
67 |
|
---|
68 |
|
---|
69 |
function InitDefaults() |
---|
70 |
{ |
---|
71 |
parent::InitDefaults(); |
---|
72 |
|
---|
73 |
if (isset($this->maParams["WIDGETCLASS"])) |
---|
74 |
$this->mszClass = $this->maParams["WIDGETCLASS"]; |
---|
75 |
if (isset($this->maParams["WIDGETSTYLE"])) |
---|
76 |
$this->mszStyle = $this->maParams["WIDGETSTYLE"]; |
---|
77 |
if (isset($this->maParams["EXTENT"])) |
---|
78 |
$this->mszExtent = strtoupper($this->maParams["EXTENT"]); |
---|
79 |
if (isset($this->maParams["TEXTFIELDSIZE"])) |
---|
80 |
$this->mnDefaultTextFieldSize = strtoupper($this->maParams["TEXTFIELDSIZE"]); |
---|
81 |
} |
---|
82 |
|
---|
83 |
|
---|
84 |
|
---|
85 |
|
---|
86 |
|
---|
87 |
function GetJavascriptFunctions() |
---|
88 |
{ |
---|
89 |
$aReturn = array(); |
---|
90 |
|
---|
91 |
$poMap = $this->moMapObject->oMap; |
---|
92 |
|
---|
93 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
94 |
$bCWCJSAPI = 1; |
---|
95 |
else |
---|
96 |
$bCWCJSAPI = 0; |
---|
97 |
|
---|
98 |
if ($bCWCJSAPI) |
---|
99 |
{ |
---|
100 |
$szJsFunctionName = "ExtentWRegisterForEvent"; |
---|
101 |
$szFunction = <<<EOT |
---|
102 |
/** |
---|
103 |
* {$szJsFunctionName} |
---|
104 |
* called to register and even when the map extents changes (JSAPI) |
---|
105 |
*/ |
---|
106 |
function {$szJsFunctionName}() |
---|
107 |
{ |
---|
108 |
goCWCJSAPI.RegisterEvent(MAP_EXTENT_CHANGED, "ExtentWMapExtentsChanged"); |
---|
109 |
} |
---|
110 |
EOT; |
---|
111 |
|
---|
112 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
113 |
|
---|
114 |
$szJsFunctionName = "ExtentWMapExtentsChanged"; |
---|
115 |
$szFunction = <<<EOT |
---|
116 |
/** |
---|
117 |
* {$szJsFunctionName} |
---|
118 |
* called when the mapextents are changed to update the extent(JSAPI) |
---|
119 |
*/ |
---|
120 |
function {$szJsFunctionName}() |
---|
121 |
{ |
---|
122 |
// update the extent labels |
---|
123 |
{$this->mszHTMLForm}.Extent_MINX.value = goCWCJSAPI.oMap.minx; |
---|
124 |
{$this->mszHTMLForm}.Extent_MINY.value = goCWCJSAPI.oMap.miny; |
---|
125 |
{$this->mszHTMLForm}.Extent_MAXX.value = goCWCJSAPI.oMap.maxx; |
---|
126 |
{$this->mszHTMLForm}.Extent_MAXY.value = goCWCJSAPI.oMap.maxy; |
---|
127 |
} |
---|
128 |
EOT; |
---|
129 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
130 |
|
---|
131 |
} |
---|
132 |
|
---|
133 |
return $aReturn; |
---|
134 |
} |
---|
135 |
|
---|
136 |
|
---|
137 |
|
---|
138 |
|
---|
139 |
|
---|
140 |
|
---|
141 |
|
---|
142 |
function GetJavascriptOnLoadFunctions() |
---|
143 |
{ |
---|
144 |
$aReturn = array(); |
---|
145 |
|
---|
146 |
$aReturn = parent::GetJavascriptOnLoadFunctions(); |
---|
147 |
|
---|
148 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
149 |
{ |
---|
150 |
$szJsFunctionName = "ExtentWRegisterForEvent"; |
---|
151 |
$szFunction = "$szJsFunctionName();\n"; |
---|
152 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
153 |
} |
---|
154 |
|
---|
155 |
return $aReturn; |
---|
156 |
} |
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|
161 |
function DrawPublish() |
---|
162 |
{ |
---|
163 |
if (!$this->mbVisible) |
---|
164 |
return "<!-- ExtentWidget hidden -->"; |
---|
165 |
|
---|
166 |
$szValue = ""; |
---|
167 |
$szClass = ""; |
---|
168 |
$szStyle = ""; |
---|
169 |
|
---|
170 |
if (strlen($this->mszExtent) == 0) |
---|
171 |
return "<!-- EXTENT WIDGET MISSING EXTENT ATTRIBUTE -->\n"; |
---|
172 |
|
---|
173 |
|
---|
174 |
$szEval = "\$szValue = \$this->moMapObject->oMap->extent->"; |
---|
175 |
$szEval .= strtolower($this->mszExtent).";"; |
---|
176 |
eval( $szEval ); |
---|
177 |
|
---|
178 |
$nPixSize = $this->moMapObject->oMap->width; |
---|
179 |
$nGeoSize = $this->moMapObject->oMap->extent->minx - |
---|
180 |
$this->moMapObject->oMap->extent->maxx; |
---|
181 |
|
---|
182 |
$nPixelSize = abs($nPixSize / $nGeoSize); |
---|
183 |
|
---|
184 |
if ($nPixelSize > 1) |
---|
185 |
$nNbDecimal = abs(log($nPixelSize))/log(10)+1; |
---|
186 |
else |
---|
187 |
$nNbDecimal = 0; |
---|
188 |
|
---|
189 |
$nMinX = number_format($szValue, $nNbDecimal, ".", ""); |
---|
190 |
|
---|
191 |
|
---|
192 |
if (!$this->mbVisible) |
---|
193 |
return "<!-- Extent widget hidden -->"; |
---|
194 |
|
---|
195 |
$nSize = $this->mnDefaultTextFieldSize; |
---|
196 |
if (isset($this->maParams["TextFieldSize"])) |
---|
197 |
$nSize = strtoupper($this->maParams["TextFieldSize"]); |
---|
198 |
|
---|
199 |
$szClass = ""; |
---|
200 |
if ( strlen($this->mszClass) > 0 ) |
---|
201 |
$szClass = " CLASS=\"$this->mszClass\""; |
---|
202 |
$szStyle = ""; |
---|
203 |
if ( strlen($this->mszStyle) > 0 ) |
---|
204 |
$szStyle = " STYLE=\"$this->mszStyle\""; |
---|
205 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
206 |
$szContents="<input".$szClass.$szStyle." type=\"text\" name=\"Extent_".$this->mszExtent."\" value=\"".$nMinX."\" size=\"$nSize\" readonly>"; |
---|
207 |
else |
---|
208 |
$szContents="<span".$szClass.$szStyle." name=\"txtExtentLabel".$this->mnId."\">".$nMinX."</span>"; |
---|
209 |
return $this->moLabel->DrawPublish( $szContents ); |
---|
210 |
|
---|
211 |
} |
---|
212 |
} |
---|
213 |
?> |
---|
214 |
|
---|