1 |
<?php |
---|
2 |
/** |
---|
3 |
* MapTips Widget class |
---|
4 |
* |
---|
5 |
* @project CWC2 |
---|
6 |
* @revision $Id: MapTips.widget.php,v 1.20 2005/05/06 15:21:01 pspencer Exp $ |
---|
7 |
* @purpose MapTips Widget class |
---|
8 |
* @author Jason Fournier (dev@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 |
/* |
---|
31 |
* MODIFICATIONS (C) 2005, Andreas Hocevar <andreas.hocevar@prisma-solutions.at> |
---|
32 |
* - bugfix: use tolerance from cwc2 call (and not 3!) |
---|
33 |
* - bugfix: use correct variable $this->mszOnMouseOut (not $this->onMouseOut) |
---|
34 |
* for $onmouseout and fix semicolon typo in $onmouseover definiton. |
---|
35 |
* - bugfix: set default onmouseover and onmouseout to correct names |
---|
36 |
* (i.e. MapTipContent and MapTip clear instead of MapTipsContent and |
---|
37 |
* MapTipsClear). |
---|
38 |
* - add feature: if keyword "LinkUniqueID" (case insensitive) is found in the |
---|
39 |
* LINKURL attribute, it is replaced by the current link-id. This is useful |
---|
40 |
* if your LinkURL looks more like "javascript:openURL(12345, 'foo')" that |
---|
41 |
* "http://www.foo.bar/index.php?id=12345". |
---|
42 |
* - add feature: new LINKTARGET attribute. If not set, "_blank" is used to |
---|
43 |
* keep compatibility with previous versions. If LINKTARGET attribute is set |
---|
44 |
* to "", it will be omitted in the according hfres. |
---|
45 |
*/ |
---|
46 |
|
---|
47 |
include_once(dirname(__FILE__)."/../Widget.php"); |
---|
48 |
include_once(dirname(__FILE__)."/../Button.php"); |
---|
49 |
include_once(dirname(__FILE__)."/../Popup.php"); |
---|
50 |
include_once(dirname(__FILE__)."/../LayerAttributes.php"); |
---|
51 |
/** |
---|
52 |
* MapTips Widget |
---|
53 |
* |
---|
54 |
* @desc A widget that draws dynamic MapTips on the MapImage. Uses an |
---|
55 |
* imagemap to dynamically position a hidden layer with relevant |
---|
56 |
* information. |
---|
57 |
*/ |
---|
58 |
class MapTips extends CWCWidget |
---|
59 |
{ |
---|
60 |
var $moButton; |
---|
61 |
var $moPopup; |
---|
62 |
|
---|
63 |
/* default settings for the widget params */ |
---|
64 |
var $mszDefaultText = " "; // Default text for noon-active maptip |
---|
65 |
var $mnTolerance = 4; // Imagemap point tolerance for each AREA entry |
---|
66 |
var $mszLayer = ''; |
---|
67 |
var $maszAttributes = array(); |
---|
68 |
var $mszLinkURL = ''; // URL to go to |
---|
69 |
var $mszLinkTarget = '_blank'; // Link target |
---|
70 |
var $mszLinkUniqueID = ''; // unique location id to append to url |
---|
71 |
var $mszTitleClass = 'label'; |
---|
72 |
var $mszTitleStyle = ''; |
---|
73 |
var $mszLabelClass = 'label'; |
---|
74 |
var $mszLabelStyle = ''; |
---|
75 |
|
---|
76 |
/* internal vars */ |
---|
77 |
var $mszImageMapName = 'maptips_imagemap'; |
---|
78 |
var $mszMapTipsDiv = 'maptips_container'; |
---|
79 |
var $mszTransparentMapDiv = 'maptips_overlay'; |
---|
80 |
var $mszTransparentMapImage = 'maptips_image'; |
---|
81 |
var $mszPixelGif = ''; |
---|
82 |
|
---|
83 |
var $mszOnMouseOver = 'MapTipsOver'; |
---|
84 |
var $mszOnMouseOut = 'MapTipsOut'; |
---|
85 |
var $mszOnClick = ''; |
---|
86 |
/** |
---|
87 |
* MapTips |
---|
88 |
* |
---|
89 |
* @desc Constructor method for the MapTips widget. |
---|
90 |
|
---|
91 |
*/ |
---|
92 |
function MapTips() |
---|
93 |
{ |
---|
94 |
/* invoke constructor of parent */ |
---|
95 |
parent::CWCWidget(); |
---|
96 |
|
---|
97 |
/* set the description for this widget */ |
---|
98 |
$this->szWidgetDescription = <<<EOT |
---|
99 |
The MapTips widget allows users to show dynamic |
---|
100 |
maptips (tooltips) containing information pertinent to |
---|
101 |
their application. The widget relies on an array of |
---|
102 |
data stored as a Shared Resource. It will create |
---|
103 |
an imagemap from the query results and place js to handle the |
---|
104 |
dhmtl |
---|
105 |
EOT; |
---|
106 |
|
---|
107 |
$this->moPopup = new CWCPopup( $this ); |
---|
108 |
$this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/MapTips/MapTipsPopup.phtml"; |
---|
109 |
|
---|
110 |
$this->moButton = new CWCButton( $this ); |
---|
111 |
|
---|
112 |
/* declare the required OR allowable cwc2 parameters for this widget */ |
---|
113 |
$this->maAttributes["LAYER"] = new StringAttribute( "LAYER", false ); |
---|
114 |
$this->maAttributes["ATTRIBUTES"] = new StringAttribute( "ATTRIBUTES", false ); |
---|
115 |
$this->maAttributes["DEFAULTTEXT"] = new StringAttribute( "DEFAULTTEXT", false ); |
---|
116 |
$this->maAttributes["TOLERANCE"] = new IntegerAttribute( "TOLERANCE", false ); |
---|
117 |
$this->maAttributes["LINK"] = new BooleanAttribute( "LINK", false ); |
---|
118 |
$this->maAttributes["LINKURL"] = new StringAttribute( "LINKURL", false ); |
---|
119 |
$this->maAttributes["LINKTARGET"] = new StringAttribute( "LINKTARGET", false ); |
---|
120 |
$this->maAttributes["LINKUNIQUEID"] = new StringAttribute( "LINKUNIQUEID", false ); |
---|
121 |
$this->maAttributes["MAPTIPSDIV"] = new StringAttribute( "MAPTIPSDIV", true ); |
---|
122 |
$this->maAttributes["TITLECLASS"] = new StringAttribute( "TITLECLASS", false ); |
---|
123 |
$this->maAttributes["TITLESTYLE"] = new StringAttribute( "TITLESTYLE", false ); |
---|
124 |
$this->maAttributes["LABELCLASS"] = new StringAttribute( "LABELCLASS", false ); |
---|
125 |
$this->maAttributes["LABELSTYLE"] = new StringAttribute( "LABELSTYLE", false ); |
---|
126 |
$this->maAttributes["ONMOUSEOVER"] = new StringAttribute( "ONMOUSEOVER", false ); |
---|
127 |
$this->maAttributes["ONMOUSEOUT"] = new StringAttribute( "ONMOUSEOUT", false ); |
---|
128 |
$this->maAttributes["ONCLICK"] = new StringAttribute( "ONCLICK", false ); |
---|
129 |
$this->mnMaturityLevel = MATURITY_BETA; |
---|
130 |
} |
---|
131 |
|
---|
132 |
|
---|
133 |
/** |
---|
134 |
* InitDefaults |
---|
135 |
* |
---|
136 |
*/ |
---|
137 |
function InitDefaults() |
---|
138 |
{ |
---|
139 |
|
---|
140 |
parent::InitDefaults(); |
---|
141 |
|
---|
142 |
$this->moButton->InitDefaults(); |
---|
143 |
//this widget should never belong to a toolset |
---|
144 |
$this->maParams["TOOLSET"] = ""; |
---|
145 |
$this->moButton->SetOnClick('clickMapTipsPopup'); |
---|
146 |
$this->moPopup->InitDefaults(); |
---|
147 |
|
---|
148 |
/* init the params if user set them */ |
---|
149 |
if (isset($this->maParams["LAYER"])) |
---|
150 |
$this->mszLayer = $this->maParams["LAYER"]; |
---|
151 |
if (isset($this->maParams["ATTRIBUTES"])) |
---|
152 |
$this->maszAttributes = explode( ",", $this->maParams["ATTRIBUTES"] ); |
---|
153 |
|
---|
154 |
if (isset($this->maParams["DEFAULTTEXT"])) |
---|
155 |
$this->mszDefaultText = $this->maParams["DEFAULTTEXT"]; |
---|
156 |
|
---|
157 |
if (isset($this->maParams["TOLERANCE"])) |
---|
158 |
$this->mnTolerance = $this->maParams["TOLERANCE"]; |
---|
159 |
|
---|
160 |
if (isset($this->maParams["LINK"])) |
---|
161 |
{ |
---|
162 |
$this->mszLink = $this->maParams["LINK"]; |
---|
163 |
if (isset($this->maParams["LINKURL"])) |
---|
164 |
$this->mszLinkURL = $this->maParams["LINKURL"]; |
---|
165 |
if (isset($this->maParams["LINKTARGET"])) |
---|
166 |
$this->mszLinkTarget = $this->maParams["LINKTARGET"]; |
---|
167 |
if (isset($this->maParams["LINKUNIQUEID"])) |
---|
168 |
$this->mszLinkUniqueID = $this->maParams["LINKUNIQUEID"]; |
---|
169 |
} |
---|
170 |
|
---|
171 |
if (isset($this->maParams['ONMOUSEOVER']) && isset($this->maParams['ONMOUSEOUT'])) |
---|
172 |
{ |
---|
173 |
$this->mszOnMouseOver = $this->maParams['ONMOUSEOVER']; |
---|
174 |
$this->mszOnMouseOut = $this->maParams['ONMOUSEOUT']; |
---|
175 |
} |
---|
176 |
if (isset($this->maParams["ONCLICK"])) |
---|
177 |
$this->mszOnClick = $this->maParams["ONCLICK"]; |
---|
178 |
|
---|
179 |
$this->mszImageMapName .= $this->mnId; |
---|
180 |
$this->mszTransparentMapImage .= $this->mnId; |
---|
181 |
|
---|
182 |
if (isset($this->maParams["MAPTIPSDIV"])) |
---|
183 |
$this->mszMapTipsDiv = $this->maParams["MAPTIPSDIV"]; |
---|
184 |
|
---|
185 |
if (isset($this->maParams["TITLECLASS"])) |
---|
186 |
$this->mszTitleClass = $this->maParams["TITLECLASS"]; |
---|
187 |
if (isset($this->maParams["TITLESTYLE"])) |
---|
188 |
$this->mszTitleStyle = $this->maParams["TITLESTYLE"]; |
---|
189 |
if (isset($this->maParams["LABELCLASS"])) |
---|
190 |
$this->mszLabelClass = $this->maParams["LABELCLASS"]; |
---|
191 |
if (isset($this->maParams["LABELSTYLE"])) |
---|
192 |
$this->mszLabelStyle = $this->maParams["LABELSTYLE"]; |
---|
193 |
|
---|
194 |
$this->mszPixelGif = $_SESSION['gszCoreWebPath'].'/skins/default/images/a_pixel.gif'; |
---|
195 |
|
---|
196 |
} |
---|
197 |
|
---|
198 |
function GetJavascriptOnLoadFunctions() |
---|
199 |
{ |
---|
200 |
$aReturn = $this->moButton->GetJavascriptOnLoadFunctions(); |
---|
201 |
|
---|
202 |
if ($this->mszLayer != '') |
---|
203 |
{ |
---|
204 |
/* this positions the transparent gif over the map to be used in conjunction with the MapTips. */ |
---|
205 |
/* the gif has an image map associated with it */ |
---|
206 |
$szJsFunctionName = "CWCDHTML_PositionLayerByImage"; |
---|
207 |
$szFunction = "$szJsFunctionName('".$this->mszTransparentMapDiv."', 'mapimage', 'tl', 0, 0 );"; |
---|
208 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
209 |
} |
---|
210 |
|
---|
211 |
return $aReturn; |
---|
212 |
} |
---|
213 |
|
---|
214 |
/** |
---|
215 |
* DrawPublish() |
---|
216 |
* |
---|
217 |
* @desc draw this widget on the page |
---|
218 |
*/ |
---|
219 |
function DrawPublish() |
---|
220 |
{ |
---|
221 |
$szResult = ""; |
---|
222 |
|
---|
223 |
if ($this->mszLayer != '') |
---|
224 |
{ |
---|
225 |
$szImageMap = $this->GenerateImageMap(); |
---|
226 |
if ($szImageMap !== false) |
---|
227 |
{ |
---|
228 |
$szResult .= $szImageMap; |
---|
229 |
$szResult .= "\n\n"; |
---|
230 |
} |
---|
231 |
} |
---|
232 |
|
---|
233 |
/* return the result */ |
---|
234 |
if (!$this->mbVisible) |
---|
235 |
return "<!-- MapTips activation widget -->".$szResult; |
---|
236 |
|
---|
237 |
if ($this->mbVisible) |
---|
238 |
{ |
---|
239 |
$szResult .= $this->moButton->DrawPublish(); |
---|
240 |
|
---|
241 |
} |
---|
242 |
return $szResult; |
---|
243 |
|
---|
244 |
} |
---|
245 |
|
---|
246 |
/** |
---|
247 |
* ParseURL inspects incoming form variables and sets up the |
---|
248 |
* maptips object to generate an image map (which happens in |
---|
249 |
* drawpublish) |
---|
250 |
*/ |
---|
251 |
function ParseURL() |
---|
252 |
{ |
---|
253 |
//only do this if t |
---|
254 |
if ($this->isVarSet( 'MAPTIPS_LAYER' ) && $this->getVar( 'MAPTIPS_LAYER' ) != "") |
---|
255 |
{ |
---|
256 |
$this->mszLayer = $this->getVar( 'MAPTIPS_LAYER' ); |
---|
257 |
$this->maszAttributes = explode( ",", $this->getVar( 'MAPTIPS_ATTRIBUTES' ) ); |
---|
258 |
$this->mszLinkURL = $this->getVar( 'MAPTIPS_URL' ); |
---|
259 |
$this->mszLinkUniqueID = $this->getVar( 'MAPTIPS_UNIQUEID' ); |
---|
260 |
} |
---|
261 |
return true; |
---|
262 |
} |
---|
263 |
|
---|
264 |
/** |
---|
265 |
* GenerateImageMap() |
---|
266 |
* |
---|
267 |
* @desc ImageMap generation |
---|
268 |
*/ |
---|
269 |
function GenerateImageMap() |
---|
270 |
{ |
---|
271 |
/** |
---|
272 |
* SAMPLE MAPTIP IMAGEMAP LINE OUTPUT |
---|
273 |
* <map name="maptip_circle_1"> |
---|
274 |
* <area shape="circle" coords="41,125,6" href="http://url-to-info" target="_blank" |
---|
275 |
* onmouseover="MapTipInit(10,'maptips_static','static');" |
---|
276 |
* onmouseout="MapTipClear( 'maptips_static', 'No Location Selected' );"> |
---|
277 |
* </map> |
---|
278 |
* |
---|
279 |
* This is a general client-side imagemap that attaches itself to the |
---|
280 |
* transparent gif inside the maptipscontainer DIV. pix coords from |
---|
281 |
* GetQueryDump() populate the circle locations of the image map. |
---|
282 |
*/ |
---|
283 |
|
---|
284 |
$szMap = false; |
---|
285 |
//delete temp WFS layer??? |
---|
286 |
$bDeleteLayer = false; |
---|
287 |
|
---|
288 |
$oMap =& $this->moMapObject->oMap; |
---|
289 |
|
---|
290 |
$oLayer = @$oMap->getLayerByName( $this->mszLayer ); |
---|
291 |
|
---|
292 |
if ($oLayer == null || $oLayer->isVisible() == MS_FALSE) |
---|
293 |
{ |
---|
294 |
return $szMap; |
---|
295 |
} |
---|
296 |
|
---|
297 |
$nCount = 0; |
---|
298 |
|
---|
299 |
$szTitleTag = "<span"; |
---|
300 |
if ($this->mszTitleClass != "") |
---|
301 |
{ |
---|
302 |
$szTitleTag .= ' class='.$this->mszTitleClass; |
---|
303 |
} |
---|
304 |
if ($this->mszTitleStyle != "") |
---|
305 |
{ |
---|
306 |
$szTitleTag .= " style=\"".$this->mszTitleStyle."\""; |
---|
307 |
} |
---|
308 |
$szTitleTag .= ">"; |
---|
309 |
|
---|
310 |
$szLabelTag = "<span"; |
---|
311 |
if ($this->mszLabelClass != "") |
---|
312 |
{ |
---|
313 |
$szLabelTag .= ' class='.$this->mszLabelClass; |
---|
314 |
} |
---|
315 |
if ($this->mszLabelStyle != "") |
---|
316 |
{ |
---|
317 |
$szLabelTag .= " style=\"".$this->mszLabelStyle."\""; |
---|
318 |
} |
---|
319 |
$szLabelTag .= ">"; |
---|
320 |
|
---|
321 |
if ($oLayer->connectiontype == MS_WMS) |
---|
322 |
{ |
---|
323 |
//create a temp WFS layer if possible? |
---|
324 |
$aszAttributes = GetLayerAttributes( $oLayer ); |
---|
325 |
if (count($aszAttributes) > 0 && |
---|
326 |
isset($aszAttributes['onlineresource']) && |
---|
327 |
$aszAttributes['onlineresource'] != '') |
---|
328 |
{ |
---|
329 |
$oWFSLayer = ms_newLayerObj( $oMap ); |
---|
330 |
$oWFSLayer->set( "status", MS_ON ); |
---|
331 |
$oWFSLayer->set( "name", "wfs_".$oLayer->name ); |
---|
332 |
$oWFSLayer->set( "connectiontype", MS_WFS ); |
---|
333 |
$oWFSLayer->set( 'connection', $aszAttributes['onlineresource'] ); |
---|
334 |
$oWFSLayer->set( "type", eval( 'return '.$aszAttributes['fields']['LayerType'].';' ) ); |
---|
335 |
$oWFSLayer->set( "tolerance", 5 ); |
---|
336 |
|
---|
337 |
//to get the required SRS we need to get the capabilities first |
---|
338 |
$szSRS = getWFSSRS( $aszAttributes['onlineresource'].'request=getcapabilities', $oLayer->name ); |
---|
339 |
$oWFSLayer->setmetadata( "wfs_srs", $szSRS ); |
---|
340 |
$oWFSLayer->setmetadata( "wfs_typename", $oLayer->name); |
---|
341 |
$oClass = ms_newClassObj( $oWFSLayer ); |
---|
342 |
|
---|
343 |
//todo set class up |
---|
344 |
$oLayer = $oWFSLayer; |
---|
345 |
$bDeleteLayer = true; |
---|
346 |
} |
---|
347 |
|
---|
348 |
} |
---|
349 |
|
---|
350 |
if ($oLayer->type == MS_LAYER_POINT || |
---|
351 |
$oLayer->type == MS_LAYER_LINE || |
---|
352 |
$oLayer->type == MS_LAYER_POLYGON ) |
---|
353 |
{ |
---|
354 |
//there is a mapserver bug (569) that stops us from putting |
---|
355 |
//the template on the layer ... it has to go in the classes |
---|
356 |
//instead :( |
---|
357 |
|
---|
358 |
$szMap = "<map name=\"".$this->mszImageMapName."\">\n"; |
---|
359 |
$szValues = "new Array("; |
---|
360 |
$szContents = "new Array("; |
---|
361 |
$szSep = ""; |
---|
362 |
for( $j=0; $j<count( $this->maszAttributes ); $j++) |
---|
363 |
{ |
---|
364 |
$szContents .= $szSep."\"[".$this->maszAttributes[$j]."]\""; |
---|
365 |
$szValues .= $szSep."\"".$this->maszAttributes[$j]."\""; |
---|
366 |
$szSep = ","; |
---|
367 |
} |
---|
368 |
$szContents .= ")"; |
---|
369 |
$szValues .= ")"; |
---|
370 |
$href= 'href="javascript:void(0);" '; |
---|
371 |
$onmouseover = 'onmouseover=\''.$this->mszOnMouseOver.'(arguments[0], '.$szContents.', '.$szValues.')\' '; |
---|
372 |
$onmouseout = 'onmouseout=\''.$this->mszOnMouseOut.'(arguments[0],'.$szContents.', '.$szValues.')\' '; |
---|
373 |
$onmousemove = 'onmousemove="CWC2OnMouseMoveFunction(arguments[0])"'; |
---|
374 |
$onclick = ($this->mszOnClick == '')?'':'onclick=\''.$this->mszOnClick.'(arguments[0],'.$szContents.', '.$szValues.')\' '; |
---|
375 |
|
---|
376 |
if ($oLayer->type == MS_LAYER_POINT) |
---|
377 |
{ |
---|
378 |
$szTemplate = '<area shape="circle" coords="[shpxy xf="," proj="image"],'.$this->mnTolerance.'" '.$href.$onmouseover.$onmouseout.$onmousemove.$onclick.'>'; |
---|
379 |
} |
---|
380 |
elseif ($oLayer->type == MS_LAYER_LINE) |
---|
381 |
{ |
---|
382 |
//we handle lines separately because we need to buffer them ... |
---|
383 |
$szTemplate = '[shpxy xf="," sf="~" proj="image"],'.$szContents.'|'; |
---|
384 |
} |
---|
385 |
elseif ($oLayer->type == MS_LAYER_POLYGON) |
---|
386 |
{ |
---|
387 |
$szTemplate = '<area shape="polygon" coords="[shpxy xf="," pf=" " proj="image"]" '.$href.$onmouseover.$onmouseout.$onmousemove.$onclick.'>'; |
---|
388 |
} |
---|
389 |
|
---|
390 |
$szTemplatePath = getSessionSavePath()."maptips_template.html"; |
---|
391 |
$hTemplate = fopen( $szTemplatePath, "w+" ); |
---|
392 |
fwrite( $hTemplate, $szTemplate ); |
---|
393 |
fclose( $hTemplate ); |
---|
394 |
$aszOldTemplates = array(); |
---|
395 |
for ($i=0; $i<$oLayer->numclasses; $i++) |
---|
396 |
{ |
---|
397 |
$oClass = $oLayer->getClass( $i ); |
---|
398 |
array_push( $aszOldTemplates, $oClass->template ); |
---|
399 |
$oClass->set( "template", $szTemplatePath ); |
---|
400 |
} |
---|
401 |
$szOldTemplate = $oLayer->template; |
---|
402 |
//need to clear the template on the layer if it is is set ... but there |
---|
403 |
//was no way to do this before 2003/03/09 mapscript |
---|
404 |
//$oLayer->set( "template", null ); |
---|
405 |
|
---|
406 |
@$oLayer->queryByRect( $oMap->extent ); |
---|
407 |
//echo "num results = ".$oLayer->getNumResults()."<BR>"; |
---|
408 |
$szCoords = $oMap->processQueryTemplate( array(), false ); |
---|
409 |
|
---|
410 |
for ($i=0; $i<$oLayer->numclasses; $i++) |
---|
411 |
{ |
---|
412 |
$oClass = $oLayer->getClass( $i ); |
---|
413 |
$oClass->set( "template", $aszOldTemplates[$i] ); |
---|
414 |
} |
---|
415 |
//$oLayer->set( "template", $szOldTemplate ); |
---|
416 |
|
---|
417 |
//need to post-process lines into polygon with buffering |
---|
418 |
if ($oLayer->type == MS_LAYER_LINE) |
---|
419 |
{ |
---|
420 |
$szNewCoords = ""; |
---|
421 |
$aszLines = explode( "|", $szCoords ); |
---|
422 |
$nLines = count( $aszLines ); |
---|
423 |
for ($i=0; $i < ($nLines); $i++) |
---|
424 |
{ |
---|
425 |
$aszLineParts = explode( "~", $aszLines[$i] ); |
---|
426 |
$aszLineCoords = explode( " ", $aszLineParts[0] ); |
---|
427 |
$nLineCoords = count($aszLineCoords); |
---|
428 |
for ($j=0; $j<$nLineCoords -1; $j++ ) |
---|
429 |
{ |
---|
430 |
if (trim($aszLineCoords[$j]) == "" ) |
---|
431 |
continue; |
---|
432 |
|
---|
433 |
$aszCoord1 = explode( ",", $aszLineCoords[$j] ); |
---|
434 |
$aszCoord2 = explode( ",", $aszLineCoords[$j + 1] ); |
---|
435 |
if (count( $aszCoord1 ) >= 2 && count( $aszCoord2) >= 2 ) |
---|
436 |
{ |
---|
437 |
$anLine = $this->bufferLine( $aszCoord1[0], $aszCoord1[1], |
---|
438 |
$aszCoord2[0], $aszCoord2[1], |
---|
439 |
2 ); |
---|
440 |
$szBufferedLine = implode( ",", $anLine ); |
---|
441 |
//echo $szBufferedLine."<BR>";MapTipInit(\''.$szContents.'\', \''.$this->mszDynamicDIV.'\', \'dynamic\', [shpxy xf="," transform] ) |
---|
442 |
$szNewCoords .= '<area shape="polygon" coords="'.$szBufferedLine. |
---|
443 |
'" '.$href.$onmouseover.$onmouseout.$onmousemove.$onclick.'>'; |
---|
444 |
} |
---|
445 |
} |
---|
446 |
} |
---|
447 |
$szCoords = $szNewCoords; |
---|
448 |
} |
---|
449 |
|
---|
450 |
$szMap .= $szCoords; |
---|
451 |
$szMap .= "</map>"; |
---|
452 |
$szMap .= "<map name=\"nullmap\"></map>\n"; |
---|
453 |
|
---|
454 |
if ($bDeleteLayer) |
---|
455 |
$oLayer->set( "status", MS_DELETE ); |
---|
456 |
} |
---|
457 |
|
---|
458 |
return $szMap; |
---|
459 |
} |
---|
460 |
|
---|
461 |
/** |
---|
462 |
* calculate a polygon that buffers the line by a given radius |
---|
463 |
* |
---|
464 |
* line algorithm is y = mx + b where m is the slope and b is the y intercept |
---|
465 |
* |
---|
466 |
* |
---|
467 |
*/ |
---|
468 |
function bufferLine( $nX1, $nY1, $nX2, $nY2, $nRadius ) |
---|
469 |
{ |
---|
470 |
//echo "buffering line from $nX1,$nY1 to $nX2,$nY2 by $nRadius<BR>"; |
---|
471 |
//default result is just the line |
---|
472 |
$anResult = array( $nX1, $nY1, $nX1, $nY1, $nX2, $nY2, $nX2, $nY2 ); |
---|
473 |
|
---|
474 |
//take care of vertical line - infinite slope - div by zero error |
---|
475 |
if ($nY1 == $nY2) |
---|
476 |
{ |
---|
477 |
if ($nY1 > $nY2) |
---|
478 |
$dir = -1; |
---|
479 |
else |
---|
480 |
$dir = 1; |
---|
481 |
$anResult[0] = $nX1 - $nRadius; |
---|
482 |
$anResult[1] = $nY1 - $dir * $nRadius; |
---|
483 |
$anResult[2] = $nX1 + $nRadius; |
---|
484 |
$anResult[3] = $nY1 - $dir * $nRadius; |
---|
485 |
$anResult[4] = $nX2 - $nRadius; |
---|
486 |
$anResult[5] = $nY2 + $dir * $nRadius; |
---|
487 |
$anResult[6] = $nX2 + $nRadius; |
---|
488 |
$anResult[7] = $nY2 + $dir * $nRadius; |
---|
489 |
} |
---|
490 |
//take care of horizontal line case because it is easy |
---|
491 |
elseif ($nX1 == $nX2) |
---|
492 |
{ |
---|
493 |
if ($nX1 > $nX2) |
---|
494 |
$dir = -1; |
---|
495 |
else |
---|
496 |
$dir = 1; |
---|
497 |
$anResult[0] = $nX1 - $dir *$nRadius; |
---|
498 |
$anResult[1] = $nY1 - $nRadius; |
---|
499 |
$anResult[2] = $nX1 - $dir * $nRadius; |
---|
500 |
$anResult[3] = $nY1 + $nRadius; |
---|
501 |
$anResult[4] = $nX2 + $dir * $nRadius; |
---|
502 |
$anResult[5] = $nY2 - $nRadius; |
---|
503 |
$anResult[6] = $nX2 + $dir * $nRadius; |
---|
504 |
$anResult[7] = $nY2 + $nRadius; |
---|
505 |
} |
---|
506 |
else |
---|
507 |
{ |
---|
508 |
//complicated case, sloped line |
---|
509 |
$lrun = $nX2 - $nX1; |
---|
510 |
$lrise = $nY2 - $nY1; |
---|
511 |
$lhyp = sqrt( pow( $lrise, 2 ) + pow( $lrun, 2 ) ); |
---|
512 |
$ex1 = $nX1 - $nRadius*$lrun/$lhyp; |
---|
513 |
$ey1 = $nY1 - $nRadius*$lrise/$lhyp; |
---|
514 |
$ex2 = $nX2 + $nRadius*$lrun/$lhyp; |
---|
515 |
$ey2 = $nY2 + $nRadius*$lrise/$lhyp; |
---|
516 |
$anResult[0] = (int)($ex1 + $nRadius*$lrise/$lhyp); |
---|
517 |
$anResult[1] = (int)($ey1 - $nRadius*$lrun/$lhyp); |
---|
518 |
$anResult[2] = (int)($ex1 - $nRadius*$lrise/$lhyp); |
---|
519 |
$anResult[3] = (int)($ey1 + $nRadius*$lrun/$lhyp); |
---|
520 |
$anResult[4] = (int)($ex2 - $nRadius*$lrise/$lhyp); |
---|
521 |
$anResult[5] = (int)($ey2 + $nRadius*$lrun/$lhyp); |
---|
522 |
$anResult[6] = (int)($ex2 + $nRadius*$lrise/$lhyp); |
---|
523 |
$anResult[7] = (int)($ey2 - $nRadius*$lrun/$lhyp); |
---|
524 |
} |
---|
525 |
return $anResult; |
---|
526 |
} |
---|
527 |
|
---|
528 |
|
---|
529 |
/** |
---|
530 |
* GetJavascriptIncludeFunctions |
---|
531 |
* |
---|
532 |
* javascript include files |
---|
533 |
*/ |
---|
534 |
function GetJavascriptIncludeFunctions() |
---|
535 |
{ |
---|
536 |
$aReturn = array(); |
---|
537 |
|
---|
538 |
$aReturn = parent::GetJavascriptIncludeFunctions(); |
---|
539 |
|
---|
540 |
/* layer_fn.js contains generic layer functions */ |
---|
541 |
$szJsIncludeName = "cwc_dhtml.js"; |
---|
542 |
|
---|
543 |
$szInclude = "<script language=\"JavaScript\" src=\"" . |
---|
544 |
$_SESSION["gszCoreWebPath"]."/widgets/js/cwc_dhtml.js\" type=\"text/javascript\"></script>"; |
---|
545 |
$aReturn[$szJsIncludeName] = $szInclude; |
---|
546 |
|
---|
547 |
/* maptips.js contains all the maptip js functionality */ |
---|
548 |
$szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/MapTips/maptips.js"; |
---|
549 |
$szInclude = "<script language=\"JavaScript\" src=\"" . |
---|
550 |
$_SESSION["gszCoreWebPath"]."/widgets/MapTips/maptips.js\" type=\"text/javascript\"></script>"; |
---|
551 |
$aReturn[$szJsIncludeName] = $szInclude; |
---|
552 |
|
---|
553 |
/* maptips.css styles the dynamic and static DIV's used with maptips */ |
---|
554 |
$szJsIncludeName = $_SESSION["gszCoreWebPath"]."/widgets/css/maptips.css"; |
---|
555 |
$szInclude = "<link rel=\"stylesheet\" href=\"" . |
---|
556 |
$_SESSION["gszCoreWebPath"]."/widgets/css/maptips.css\" type=\"text/css\">"; |
---|
557 |
$aReturn[$szJsIncludeName] = $szInclude; |
---|
558 |
|
---|
559 |
return $aReturn; |
---|
560 |
} |
---|
561 |
|
---|
562 |
|
---|
563 |
/** |
---|
564 |
* GetJavascriptInitFunctions |
---|
565 |
* |
---|
566 |
* @desc These get spit out at the bottom of the template after the page is processed |
---|
567 |
*/ |
---|
568 |
function GetJavascriptInitFunctions() |
---|
569 |
{ |
---|
570 |
$aReturn = $this->moButton->GetJavascriptInitFunctions(); |
---|
571 |
|
---|
572 |
$aReturn['MapTipsCreateDHTMLLayers'] = "MapTipsCreateDHTMLLayers();\n"; |
---|
573 |
|
---|
574 |
return $aReturn; |
---|
575 |
} |
---|
576 |
|
---|
577 |
/** |
---|
578 |
* GetHTMLHiddenVariables |
---|
579 |
* |
---|
580 |
* return the map size variables. |
---|
581 |
*/ |
---|
582 |
function GetHTMLHiddenVariables() |
---|
583 |
{ |
---|
584 |
$aReturn = $this->moButton->GetHTMLHiddenVariables(); |
---|
585 |
|
---|
586 |
$szVariable = "MAPTIPS_LAYER"; |
---|
587 |
$szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"".$this->mszLayer."\">\n"; |
---|
588 |
$aReturn[$szVariable] = $szValue; |
---|
589 |
|
---|
590 |
$szVariable = "MAPTIPS_ATTRIBUTES"; |
---|
591 |
$szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"".implode( ",", $this->maszAttributes)."\">\n"; |
---|
592 |
$aReturn[$szVariable] = $szValue; |
---|
593 |
|
---|
594 |
$szVariable = "MAPTIPS_URL"; |
---|
595 |
$szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"".$this->mszLinkURL."\">\n"; |
---|
596 |
$aReturn[$szVariable] = $szValue; |
---|
597 |
|
---|
598 |
$szVariable = "MAPTIPS_UNIQUEID"; |
---|
599 |
$szValue = "<INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"".$this->mszLinkUniqueID."\">\n"; |
---|
600 |
$aReturn[$szVariable] = $szValue; |
---|
601 |
|
---|
602 |
return $aReturn; |
---|
603 |
} |
---|
604 |
|
---|
605 |
|
---|
606 |
/** |
---|
607 |
* GetJavascriptFunctions |
---|
608 |
* |
---|
609 |
* Build and return the array of functions needed in the |
---|
610 |
* widget. |
---|
611 |
*/ |
---|
612 |
function GetJavascriptFunctions() |
---|
613 |
{ |
---|
614 |
$aReturn = $this->moButton->GetJavascriptFunctions(); |
---|
615 |
|
---|
616 |
if (isset($this->maSharedResourceWidgets["CWCJSAPI"])) |
---|
617 |
$bCWCJSAPI = 1; |
---|
618 |
else |
---|
619 |
$bCWCJSAPI = 0; |
---|
620 |
|
---|
621 |
/* grab a handle on the map object and get the height & width */ |
---|
622 |
$poMap = $this->moMapObject->oMap; |
---|
623 |
$nMapWidth = $poMap->width; |
---|
624 |
$nMapHeight = $poMap->height; |
---|
625 |
$szJsFunctionName = "MapTipsCreateDHTMLLayers"; |
---|
626 |
$szFunction = <<<EOT |
---|
627 |
function $szJsFunctionName() |
---|
628 |
{ |
---|
629 |
szContent = '<img src="{$this->mszPixelGif}" width="{$nMapWidth}" height="{$nMapHeight}" border="0" usemap="#{$this->mszImageMapName}" name="maptipsimage" onmouseover="MapTips_CaptureMouse()" onmouseout="MapTips_ReleaseMouse(arguments[0])">'; |
---|
630 |
CWCDHTML_CreateLayer( "{$this->mszTransparentMapDiv}", -1000, -1000, {$nMapWidth}, {$nMapHeight}, true, szContent ); |
---|
631 |
CWCDHTML_SetLayerZOrder( "{$this->mszTransparentMapDiv}", 500 ); |
---|
632 |
|
---|
633 |
szContent = 'Arrrr! This be the maptips div, ye scurvy dog!'; |
---|
634 |
CWCDHTML_CreateLayer( "{$this->mszMapTipsDiv}", -1000, -1000, 200, 200, true, szContent ); |
---|
635 |
CWCDHTML_SetLayerZOrder("{$this->mszMapTipsDiv}", 501 ); |
---|
636 |
|
---|
637 |
} |
---|
638 |
EOT; |
---|
639 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
640 |
|
---|
641 |
$szJsFunctionName = "clickMapTipsPopup"; |
---|
642 |
$szButtonJS = $this->moPopup->DrawPublish(); |
---|
643 |
$szFunction = <<<EOT |
---|
644 |
/** |
---|
645 |
* {$szJsFunctionName} |
---|
646 |
* popup a MapTips configuration dialog |
---|
647 |
*/ |
---|
648 |
function {$szJsFunctionName}() |
---|
649 |
{ |
---|
650 |
{$szButtonJS} |
---|
651 |
return; |
---|
652 |
} |
---|
653 |
EOT; |
---|
654 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
655 |
|
---|
656 |
$szJsFunctionName = "applyMapTips"; |
---|
657 |
$szFunction = <<<EOT |
---|
658 |
/** |
---|
659 |
* {$szJsFunctionName} |
---|
660 |
* apply a maptips configuration to the page |
---|
661 |
* szLayer - the layer to draw maptips info from |
---|
662 |
* szAttributes - |
---|
663 |
*/ |
---|
664 |
function {$szJsFunctionName}(szLayer, szAttributes, szURL, szUniqueID /*, bShowTips */) |
---|
665 |
{ |
---|
666 |
|
---|
667 |
{$this->mszHTMLForm}.MAPTIPS_LAYER.value=szLayer; |
---|
668 |
{$this->mszHTMLForm}.MAPTIPS_ATTRIBUTES.value=szAttributes; |
---|
669 |
{$this->mszHTMLForm}.MAPTIPS_URL.value=szURL; |
---|
670 |
{$this->mszHTMLForm}.MAPTIPS_UNIQUEID.value=szUniqueID; |
---|
671 |
|
---|
672 |
bShow = true; |
---|
673 |
if (arguments.length == 5) |
---|
674 |
{ |
---|
675 |
bShow = arguments[4]; |
---|
676 |
} |
---|
677 |
|
---|
678 |
if ({$bCWCJSAPI}) |
---|
679 |
{ |
---|
680 |
//TODO: implement this! |
---|
681 |
{$this->mszHTMLForm}.submit(); |
---|
682 |
} |
---|
683 |
else |
---|
684 |
{ |
---|
685 |
{$this->mszHTMLForm}.submit(); |
---|
686 |
} |
---|
687 |
return; |
---|
688 |
} |
---|
689 |
EOT; |
---|
690 |
|
---|
691 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
692 |
|
---|
693 |
$szJsFunctionName = "MapTips_CaptureMouse"; |
---|
694 |
$szFunction = <<< EOT |
---|
695 |
function {$szJsFunctionName}() |
---|
696 |
{ |
---|
697 |
document.onmousemove = MapTips_MouseMove; |
---|
698 |
} |
---|
699 |
EOT; |
---|
700 |
|
---|
701 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
702 |
|
---|
703 |
$szJsFunctionName = "MapTips_ReleaseMouse"; |
---|
704 |
$szFunction = <<< EOT |
---|
705 |
function {$szJsFunctionName}(e) |
---|
706 |
{ |
---|
707 |
CWC2OnMouseMoveFunction( e ); |
---|
708 |
document.onmousemove = null; |
---|
709 |
} |
---|
710 |
EOT; |
---|
711 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
712 |
|
---|
713 |
$szJsFunctionName = "MapTips_MouseMove"; |
---|
714 |
$szFunction = <<< EOT |
---|
715 |
function {$szJsFunctionName}(e) |
---|
716 |
{ |
---|
717 |
CWC2OnMouseMoveFunction( e ); |
---|
718 |
} |
---|
719 |
EOT; |
---|
720 |
$aReturn[$szJsFunctionName] = $szFunction; |
---|
721 |
|
---|
722 |
|
---|
723 |
// return the array of functions |
---|
724 |
return $aReturn; |
---|
725 |
|
---|
726 |
} |
---|
727 |
|
---|
728 |
function GetJavascriptVariables() |
---|
729 |
{ |
---|
730 |
$aReturn = array(); |
---|
731 |
|
---|
732 |
$aReturn['maptips_navcmd'] = 'var szMapTipsNavCmd = "";'."\n"; |
---|
733 |
|
---|
734 |
return $aReturn; |
---|
735 |
} |
---|
736 |
} |
---|
737 |
|
---|
738 |
?> |
---|
739 |
|
---|
740 |
|
---|