1 |
<?php |
---|
2 |
/** |
---|
3 |
* Extent Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: Extent.widget.php,v 1.7 2005/01/11 12:32:19 pspencer Exp $ |
---|
7 |
* @purpose Extent Widget class |
---|
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 |
include_once(dirname(__FILE__)."/../Widget.php"); |
---|
30 |
include_once(dirname(__FILE__)."/../Label.php"); |
---|
31 |
|
---|
32 |
/** |
---|
33 |
* a widget to display one of the map extents |
---|
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 |
* construct a new Extent widget |
---|
45 |
*/ |
---|
46 |
function Extent( ) |
---|
47 |
{ |
---|
48 |
// invoke constructor of parent |
---|
49 |
parent::CWCWidget(); |
---|
50 |
|
---|
51 |
// set the description for this widget |
---|
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 |
* Initialize default values from tag |
---|
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 |
* return an array of javascript functions needed by Extent widget |
---|
85 |
* @return array of name = function values |
---|
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 |
* return an array of javascript functions needed by Extent widget |
---|
139 |
* and called when the page is loaded. |
---|
140 |
* @return array of name = function values |
---|
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 |
* draw the extent in published state |
---|
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 |
//get the requested extent value |
---|
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 |
// show the extent as a textbox made to look like a label |
---|
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 |
?> |
---|