NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/Chameleon/trunk/Chameleon/MapImageWidget/MapImageWidget.widget.php

Revision 13 (checked in by jcleary, 17 years ago)

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * Base Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: MapImageWidget.widget.php,v 1.3 2004/10/14 18:19:17 pspencer Exp $
7  * @purpose     Base Widget class
8  * @author      DM Solutions Group (assefa@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
31 /**
32  * MapImageWidget
33  *
34  * @desc Map image widget. Provides a single click on the map and
35  * updates the NAV_INPUT_COORD parameter.
36  */
37 class MapImageWidget extends CWCWidget
38 {
39     var   $msMapImageName = "DEFAULT_MAP";
40     var   $mszDrawMapParams = "";
41     var   $mszWaitImage = "";
42     var   $mnWaitImageWidth;
43     var   $mnWaitImageHeight;
44     var   $mbBorder = false;
45     var   $mbAllowResize = true;
46     var   $mbNavigable = false;
47     var   $mbTransparent = false;
48     var   $mnWidth = "";
49     var   $mnHeight = "";
50     var   $mnMinxx = "";
51     var   $mnMinxy = "";
52     var   $mnMaxxx = "";
53     var   $mnMaxxy = "";
54     var   $mszImageType = "";
55
56     function MapImageWidget()
57     {
58         // invoke constructor of parent
59         parent::CWCWidget();
60
61         // set the description for this widget
62         $this->szWidgetDescription = "No description available.  Please set ".
63                         "this description in the constructor of this class.";
64
65         $this->maAttributes["WAITIMAGE"] = new StringAttribute( "WAITIMAGE", false);
66         $this->maAttributes["WAITIMAGEWIDTH"] = new IntegerAttribute( "WAITIMAGEWIDTH", false, 0 );
67         $this->maAttributes["WAITIMAGEHEIGHT"] = new IntegerAttribute( "WAITIMAGEHEIGHT", false, 0 );
68
69         $this->maAttributes["BORDER"] = new BooleanAttribute( "BORDER", false);
70
71         $this->maAttributes["ID"] = new StringAttribute("ID", false);
72
73         $this->maAttributes["SRS"] = new StringAttribute("SRS", false);
74         $this->maAttributes["MINX"] = new IntegerAttribute("MINX", false);
75         $this->maAttributes["MINY"] = new IntegerAttribute("MINY", false);
76         $this->maAttributes["MAXX"] = new IntegerAttribute("MAXX", false);
77         $this->maAttributes["MAXY"] = new IntegerAttribute("MAXY", false);
78
79         $this->maAttributes["WIDTH"] = new IntegerAttribute("WIDTH", false);
80         $this->maAttributes["HEIGHT"] = new IntegerAttribute("HEIGHT", false);
81         $this->maAttributes["ALLOWRESIZE"] = new BooleanAttribute( "ALLOWRESIZE", false);
82
83         $this->maAttributes["NAVIGABLE"] = new BooleanAttribute( "NAVIGABLE", false);
84
85         $this->maAttributes["TRANSPARENT"] = new BooleanAttribute( "TRANSPARENT", false);
86         $this->maAttributes["IMAGETYPE"] = new StringAttribute( "IMAGETYPE", false,
87              array("PNG", "PNG24", "JPEG", "GIF", "SWF"));
88
89         $this->mnPriority = PRIORITY_HIGH;
90         $this->mnMaturityLevel = MATURITY_BETA;
91     }
92
93     function InitDefaults()
94     {
95         //now check the widget attributes to see if it is overridden
96         if (isset($this->maParams["WAITIMAGE"]))
97         {
98             $this->mszWaitImage = $this->maParams["WAITIMAGE"];
99         }
100
101         if (isset($this->maParams["WAITIMAGEWIDTH"]))
102             $this->mnWaitImageWidth = $this->maParams["WAITIMAGEWIDTH"];
103         if (isset($this->maParams["WAITIMAGEHEIGHT"]))
104             $this->mnWaitImageHeight = $this->maParams["WAITIMAGEHEIGHT"];
105
106         if (isset($this->maParams["WIDTH"]))
107             $this->mnWidth = $this->maParams["WIDTH"];
108    
109         if (isset($this->maParams["HEIGHT"]))
110             $this->mnHeight = $this->maParams["HEIGHT"];
111
112         if (isset($this->maParams["BORDER"]))
113           $this->mbBorder = ((strcasecmp($this->maParams["BORDER"],"true")==0)?true:false);
114
115         if (isset($this->maParams["ALLOWRESIZE"]))
116         {
117             if (strcasecmp( $this->maParams["ALLOWRESIZE"] , "true" ) == 0)
118                 $this->mbAllowResize = true;
119             else
120                 $this->mbAllowResize = false;
121         }
122
123         if (isset($this->maParams["NAVIGABLE"]))
124         {
125             if (strcasecmp( $this->maParams["NAVIGABLE"] , "true" ) == 0)
126                 $this->mbNavigable = true;
127             else
128                 $this->mbNavigable = false;
129         }
130
131         if (isset($this->maParams["TRANSPARENT"]))
132             $this->mbTransparent = ((strtoupper($this->maParams["TRANSPARENT"]) == "TRUE") ? true : false);
133
134         if (isset($this->maParams["IMAGETYPE"]))
135             $this->mszImageType = $this->maParams["IMAGETYPE"];
136
137         parent::InitDefaults();
138     }
139
140     /**
141      * DrawPublish
142      *
143      * Draw the map and return the HTML.
144      */
145     function DrawPublish()
146     {
147         $oMap =& $this->moMapObject->oMap;
148
149         // Get a copy of width and height
150         $nOldWidth = $oMap->width+0;
151         $nOldHeight = $oMap->height+0;
152
153         // Get a copy of map extents
154         $nOldMinX = $oMap->extent->minx+0;
155         $nOldMinY = $oMap->extent->miny+0;
156         $nOldMaxX = $oMap->extent->maxx+0;
157         $nOldMaxY = $oMap->extent->maxy+0;
158
159         $oMap->width = $this->mnWidth;
160         $oMap->height = $this->mnHeight;
161
162         $nWidth = $oMap->width;
163         $nHeight = $oMap->height;
164
165         // reproject the extent specified in cwc tag to map projection
166         if ($oMap->getProjection() != "" && $this->GetValue("srs") != "" &&
167             strstr($oMap->getProjection(), $this->GetValue("srs")) === false)
168         {
169             // Get map rojection as output
170             $szTmpMapProj = $oMap->getProjection();
171
172             // Get projection specified in cwc tag
173             $projOutObj = ms_newprojectionobj( $szTmpMapProj );
174
175             $projInObj = ms_newprojectionobj("init=".strtolower($this->GetValue("srs")));
176
177             $poRect = ms_newrectobj();
178             $poRect->setextent($this->GetValue("minx", $nOldMinX),
179                                $this->GetValue("miny", $nOldMinY),
180                                $this->GetValue("maxx", $nOldMaxX),
181                                $this->GetValue("maxy", $nOldMaxY));
182            
183             $poRect->project($projInObj, $projOutObj);
184        
185             $this->mszDrawMapParams .= "&nMinX=".$poRect->minx.
186                                        "&nMinY=".$poRect->miny.
187                                        "&nMaxX=".$poRect->maxx.
188                                        "&nMaxY=".$poRect->maxy;
189         }
190         else
191         {
192             $this->mszDrawMapParams .= "&nMinX=".$this->GetValue("minx", $nOldMinX).
193                                        "&nMinY=".$this->GetValue("miny", $nOldMinY).
194                                        "&nMaxX=".$this->GetValue("maxx", $nOldMaxX).
195                                        "&nMaxY=".$this->GetValue("maxy", $nOldMaxY);
196         }
197
198         if ($this->mbTransparent != "")
199             $this->mszDrawMapParams .= "&bTransparent=".$this->mbTransparent;
200
201         if ($this->mszImageType != "")
202             $this->mszDrawMapParams .= "&gszImgType=".$this->mszImageType;
203
204         if($this->GetValue("id", $this->GetValue("name")) != "")
205             $this->mszDrawMapParams .= "&gszMapId=".$this->GetValue("id",
206                                                       $this->GetValue("name"));
207
208         $this->mnWidth = $this->GetValue("width", $nOldWidth);
209         $this->mnHeight = $this->GetValue("height", $nOldHeight);
210
211         $this->mszDrawMapParams .= "&nWidth=".$this->GetValue("width", $nOldWidth);
212         $this->mszDrawMapParams .= "&nHeight=".$this->GetValue("height", $nOldHeight);
213
214         $bNetscape4 = false;
215         if (isset($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT']))
216         {
217             if (stristr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], "Mozilla/4") && (!(stristr($GLOBALS['HTTP_SERVER_VARS']['HTTP_USER_AGENT'], "compatible"))))
218             $bNetscape4 = true;
219         }
220         else
221             $bNetscape4 = true;
222
223         if (!$this->mbNavigable)
224             $szImgType = "img";
225         else
226             $szImgType = "input type=image onclick=\"if (!bPageLoaded) return false;\"";
227
228         $szReturn = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr>";
229         if ($this->mbBorder)
230         {
231             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
232             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\" id=\"mapFrameTL\" name=\"mapFrameTL\"></td>";
233             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
234             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\"></td>";
235             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
236             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\" id=\"mapFrameTR\" name=\"mapFrameTR\"></td>";
237             $szReturn .= "</tr><tr><td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
238             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\"></td>";
239             $szReturn .= "<td><a name=\"mapanchor\" $szImgType><div style=\"width:$nWidth;height:$nHeight;\">";
240             if(!$bNetscape4 && $this->mszWaitImage != "")
241             {
242                 $szReturn .= "<ilayer id=\"".$this->msMapImageName."\" width=$nWidth height=$nHeight>";
243                 $szReturn .= "<layer id=\"".$this->msMapImageName."\" width=$nWidth height=$nHeight>";
244                 $szReturn .= "<table width=100% height=100% cellspacing=0 cellpading=0 border=0><tr>";
245                 $szReturn .= "<td align=center valign=center width=100% height=100%><$szImgType SRC=\"".$this->mszWaitImage;
246                 $szReturn .= "\" NAME=\"".$this->msMapImageName."\" border=\"0\"></td></tr></table></layer></ilayer></div></a></td>";
247             }
248             else
249             {
250                 $szReturn .= "<$szImgType SRC=\"".WEBCOMMON."/wrapper/drawmap.php?".$this->mszDrawMapParams;
251                 $szReturn .= "\" NAME=\"".$this->msMapImageName."\" border=\"0\"></div></a></td>";
252             }
253             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
254             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\"></td></tr><tr>";
255             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
256             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\" id=\"mapFrameBL\" name=\"mapFrameBL\"></td>";
257             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
258             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\"></td>";
259             $szReturn .= "<td bgcolor=\"000000\"><img src=\"".$_SESSION['gszCoreWebPath'];
260             $szReturn .= "/images/a_pixel.gif\" width=\"1\" height=\"1\" id=\"mapFrameBR\" name=\"mapFrameBR\"></td>";
261         }
262         else
263         {
264             if(!$bNetscape4 && $this->mszWaitImage != "")
265             {
266                 $szReturn .= "<td><a name=\"mapanchor\"><div style=\"width:$nWidth;height:$nHeight;\">";
267                 $szReturn .= "<ilayer id=\"".$this->msMapImageName."\" width=$nWidth height=$nHeight>";
268                 $szReturn .= "<layer id=\"".$this->msMapImageName."\" width=$nWidth height=$nHeight>";
269                 $szReturn .= "<table width=100% height=100% cellspacing=0 cellpading=0 border=0><tr>";
270                 $szReturn .= "<td align=center valign=center width=100% height=100%><$szImgType SRC=\"".
271                     (($bNetscape4 || $this->mszWaitImage == "") ? WEBCOMMON."/wrapper/drawmap.php?".$this->mszDrawMapParams: $this->mszWaitImage);
272                 $szReturn .= "\" NAME=\"".$this->msMapImageName."\" border=\"0\"></td></tr></table></layer></ilayer></div></a></td>";
273             }
274             else
275             {
276                 $szReturn .= "<td><a name=\"mapanchor\"><div style=\"width:$nWidth;height:$nHeight;\">";
277                 $szReturn .= "<$szImgType SRC=\"".WEBCOMMON."/wrapper/drawmap.php?".$this->mszDrawMapParams;
278                 $szReturn .= "\" NAME=\"".$this->msMapImageName."\" border=\"0\"></div></a></td>";
279             }
280         }
281
282         $szReturn .= "</tr></table>";
283
284         $oMap->width = $nOldWidth;
285         $oMap->height = $nOldHeight;
286
287         return $szReturn;
288     }
289
290
291     /**
292      * handle changes coming from the URL.  In this case, we only want
293      * to verify that the map size is valid
294      */
295     function ParseURL()
296     {
297         if (!$this->mbAllowResize)
298         {
299             $poMap =& $this->moMapObject->oMap;
300        
301             $nWidth = $poMap->width;
302             $nHeight = $poMap->height;
303
304             if (isset($this->maParams["WIDTH"]))
305                 $nWidth = $this->maParams["WIDTH"];
306             if (isset($this->maParams["HEIGHT"]))
307                 $nHeight = $this->maParams["HEIGHT"];
308             $poMap->set("width", $nWidth);
309             $poMap->set("height", $nHeight);
310         }
311         else
312         {
313             $poMap =& $this->moMapObject->oMap;
314
315             $nWidth = $poMap->width;
316             $nHeight = $poMap->height;
317
318             if (isset($this->maParams["WIDTH"]))
319                 $nWidth = $this->maParams["WIDTH"];
320             if (isset($this->maParams["HEIGHT"]))
321                 $nHeight = $this->maParams["HEIGHT"];
322            
323             $poMap->set("width", $nWidth);
324             $poMap->set("height", $nHeight);
325
326             if ($this->isVarSet( "MAP_WIDTH" ) &&
327                 $this->getVar( "MAP_WIDTH" ) != "" &&
328                 $this->getVar( "MAP_WIDTH" ) > 0 &&
329                 $this->isVarSet( "MAP_HEIGHT" ) &&
330                 $this->getVar( "MAP_HEIGHT" ) != "" &&
331                 $this->getVar( "MAP_HEIGHT" ) > 0)
332             {
333                 $this->moMapObject->oMap->set("width",
334                                               $this->getVar( "MAP_WIDTH" ));
335                 $this->moMapObject->oMap->set("height",
336                                               $this->getVar( "MAP_HEIGHT" ));
337             }
338         }
339         if ($this->isVarSet( 'MAP_EXTENTS_MINX' ) &&
340             $this->isVarSet( 'MAP_EXTENTS_MINY' ) &&
341             $this->isVarSet( 'MAP_EXTENTS_MAXX' ) &&
342             $this->isVarSet( 'MAP_EXTENTS_MAXY' ))
343         {
344             $this->moMapObject->oMap->setExtent(
345                                       $this->getVar( 'MAP_EXTENTS_MINX' ),
346                                       $this->getVar( 'MAP_EXTENTS_MINY' ),
347                                       $this->getVar( 'MAP_EXTENTS_MAXX' ),
348                                       $this->getVar( 'MAP_EXTENTS_MAXY' ));
349         }
350
351         return parent::ParseURL();
352     }
353
354     function GetHTMLHiddenVariables()
355     {
356         $aReturn = parent::GetHTMLHiddenVariables();
357
358         $szVariable = "NAV_INPUT_TYPE";
359         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"POINT\">";
360         $aReturn[$szVariable] = $szValue;
361
362         return $aReturn;
363     }
364
365     /**
366      * GetJavascriptFunctions
367      *
368      * Build and return the array of functions needed in the
369      * widget.
370      */
371     function GetJavascriptFunctions()
372     {
373         $aReturn = array();
374
375         srand($this->make_seed());
376         $randval = rand();
377         $name = $this->msMapImageName;
378
379         if (isset($_SESSION['gszCoreWebPath']))
380             $core = $_SESSION['gszCoreWebPath'];
381         else
382             $core = "";
383
384         $szJsFunctionName = "LoadMap(oLayer, szParam)";
385         $szFunction = "function $szJsFunctionName\n{\n".
386               "var url='".$core.
387               WEBCOMMON."/wrapper/drawmap.php?".SID."&dummy=".$randval.
388               "'+szParam;\n".
389               "if (navigator.appName == \"Netscape\" && navigator.appVersion[0] <= 4){\n".
390               ";\n}else{\n".
391               "oDstImg = new Image();\n".
392               "oDstImg.src = url;\n".
393               "oLayer.src = oDstImg.src;\n}".
394               "\n}";
395
396         $aReturn[$szJsFunctionName] = $szFunction;
397
398         return $aReturn;
399     }
400
401     /**
402      * GetJavascriptVariables
403      */
404     function getJavascriptVariables()
405     {
406         $aReturn = parent::getJavascriptVariables();
407
408         $szVarName = "bPageLoaded";
409         $aReturn[$szVarName] = "var bPageLoaded = false;\n";
410
411         return $aReturn;
412     }
413
414     /**
415      * GetJavascriptOnLoadFunctions
416      *
417      * On load functions.
418      */
419     function GetJavascriptOnLoadFunctions()
420     {
421         $aReturn = array();
422
423         $aReturn = parent::GetJavascriptOnLoadFunctions();
424        
425         $szFunctionName = "bPageLoaded";
426         $aReturn[$szFunctionName] = "bPageLoaded = true;\n";
427
428         $this->SetDrawMapURL();
429
430         if ($this->mszWaitImage != "")
431         {
432             $szJsFunctionName = "if (navigator.appName == \"Netscape\" && navigator.appVersion[0] <= 4) ; else LoadMap(document.images['".$this->msMapImageName."'],'".$this->mszDrawMapParams."')";
433
434             $szFunction = "$szJsFunctionName;\n";
435             $aReturn[$szJsFunctionName] = $szFunction;
436         }
437
438         return $aReturn;
439     }
440
441     function SetDrawMapURL()
442     {
443         $this->mszDrawMapParams .= "&map_session_mode=".$_SESSION['gnMapSessionMode'];
444
445         $this->mszDrawMapParams .= "&".SID;
446     }
447
448     // seed with microseconds
449     function make_seed()
450     {
451         list($usec, $sec) = explode(' ', microtime());
452         return (float) $sec + ((float) $usec * 100000);
453     }
454 }
455 ?>
Note: See TracBrowser for help on using the browser.