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

root/Chameleon/trunk/Chameleon/BoundingBoxPopup/BoundingBoxPopup.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * BoundingBoxPopup Widget Class
4  *
5  * @project     CWC2
6  * @revision    $Id: BoundingBoxPopup.widget.php,v 1.8 2004/10/14 18:19:09 pspencer Exp $
7  * @purpose     Display a dialog box to type in coordinates to zoom to
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
30
31 include_once(dirname(__FILE__)."/../Widget.php");
32 include_once(dirname(__FILE__)."/../Button.php");
33 include_once(dirname(__FILE__)."/../Popup.php");
34 include_once ( COMMON."wrapper/map_navigator.php" );
35
36 /**
37  * BoundingBoxPopup
38  *
39  * @desc Display a widget that pops up a projection selection widget.
40  */
41 class BoundingBoxPopup extends CWCWidget
42 {
43     var $moButton;
44     var $moPopup;
45     var $moMapNavigator;
46
47     /**
48      * BoundingBoxPopup
49      *
50      * Constctor method for the BoundingBoxPopup
51      */
52     function BoundingBoxPopup()
53     {
54         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/BoundingBoxPopup.dbf";
55         parent::CWCWidget();
56
57         $this->moButton = new CWCButton( $this );
58         
59         $this->moPopup = new CWCPopup( $this );
60         $this->moPopup->mszLink = $_SESSION['gszCoreWebPath']."/widgets/BoundingBoxPopup/BoundingBoxPopup.phtml";
61
62         // set the description for this widget
63         $this->szWidgetDescription = <<<EOT
64 The BoundingBoxPopupWidget displays a popup dialog box that allows the user
65 to enter bounding box coordinates to zoom to (either rectangle or point)
66 EOT;
67         $this->mnMaturityLevel = MATURITY_BETA;
68
69     }
70
71     function InitDefaults()
72     {
73         parent::InitDefaults();
74         
75         //this widget should never belong to a toolset
76         $this->maParams["TOOLSET"] = "";
77         $this->moButton->InitDefaults();
78         $this->moButton->SetOnClick('clickBoundingBoxPopup');
79     }
80
81     /**
82      * SetMap
83      *
84      * Set the map session and create a navigation tool.
85      */
86     function SetMap($oMapSession)
87     {
88         $this->moMapObject = $oMapSession;
89
90         $this->moMapNavigator = new MapNavigator( $oMapSession );
91     }
92
93
94     function GetJavascriptInitFunctions()
95     {
96         return $this->moButton->GetJavascriptInitFunctions();
97     }
98
99     function GetJavascriptVariables()
100     {
101         return $this->moButton->GetJavascriptVariables();
102     }
103
104     function GetJavascriptOnLoadFunctions()
105     {
106         return $this->moButton->GetJavascriptOnLoadFunctions();
107     }
108
109     function GetJavascriptIncludeFunctions()
110     {
111         return $this->moButton->GetJavascriptIncludeFunctions();
112     }
113
114     /**
115      * GetHTMLHiddenVariables
116      *
117      * return the NAV_CMD varaiable.
118      */
119     function GetHTMLHiddenVariables()
120     {
121         $aReturn = $this->moButton->GetHTMLHiddenVariables();
122         
123         $szCmd = '';
124         if ($this->isVarSet('NAV_CMD'))
125             $szCmd = $this->getVar('NAV_CMD');
126         $szVariable = "NAV_CMD";
127         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
128         $aReturn[$szVariable] = $szValue;
129
130         $szVariable = "NAV_INPUT_TYPE";
131         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">";
132         $aReturn[$szVariable] = $szValue;
133
134         $szVariable = "NAV_INPUT_COORDINATES";
135         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
136         $aReturn[$szVariable] = $szValue;
137         
138         $szVariable = "NAV_INPUT_SRS";
139         $szValue = " <INPUT TYPE=HIDDEN NAME=$szVariable VALUE=\"\">\n";
140         $aReturn[$szVariable] = $szValue;
141
142         return $aReturn;
143     }
144
145     /**
146      * ParseURL
147      *
148      * Look for the COMPASS_POINT command and if found, recenter
149      * the image in the appropriate direction.
150      * according to the other NAV paramaters.
151      */
152     function  ParseURL()
153     {
154         $szCmd = "";
155         if ($this->isVarSet("NAV_CMD"))
156             $szCmd = $this->getVar("NAV_CMD");
157
158         if ($szCmd == "ZOOM_BBOX")
159         {
160             //process navigation here
161             $szInputCoords = "";
162             $szInputCoords = $this->getVar("NAV_INPUT_COORDINATES");
163             $szInputType = $this->getVar("NAV_INPUT_TYPE");
164
165             if(strlen($szInputCoords) <= 0)
166             {
167                 $_SESSION['gErrorManager']->setError(ERR_WARNING,
168                    trim($this->moMLT->get("7", "ERROR: No input coordinates specified in BoundingBoxPopup.php.")));
169                 return;
170             }
171             if (strlen($szInputType) <= 0)
172             {
173                 $_SESSION['gErrorManager']->setError(ERR_WARNING,
174                   trim($this->moMLT->get("8", "ERROR: No input type specified in BoundingBoxPopup.php.")));
175                 return;
176             }
177             
178             $aPixPos = explode(",", $szInputCoords);
179             
180             $szSRS = '';
181             if ($this->isVarSet('NAV_INPUT_SRS') && $this->getVar('NAV_INPUT_SRS') != "")
182             {
183                 $szSRS = trim($this->getVar('NAV_INPUT_SRS'));
184                 if (strcasecmp( substr( $szSRS, 0, 4 ), 'epsg') == 0)
185                 {
186                     $szSRS = "init=".strtolower($szSRS);
187                 }
188                 $oProjIn = ms_newProjectionObj( $szSRS );
189                 $oProjOut = ms_newProjectionObj( $this->moMapObject->oMap->getProjection() );
190                 if ($szInputType == "POINT")
191                 {
192                     $oPoint = ms_newPointObj();
193                     $oPoint->setXY( $aPixPos[0], $aPixPos[1] );
194                     $oPoint->project( $oProjIn, $oProjOut );
195                     $aPixPos[0] = $oPoint->x;
196                     $aPixPos[1] = $oPoint->y;
197                 }
198                 else
199                 {
200                     $oRect = ms_newRectObj();
201                     $oRect->setExtent( $aPixPos[0], $aPixPos[1], $aPixPos[2], $aPixPos[3] );
202                     $oRect->project( $oProjIn, $oProjOut );
203                     $aPixPos[0] = $oRect->minx;
204                     $aPixPos[1] = $oRect->miny;
205                     $aPixPos[2] = $oRect->maxx;
206                     $aPixPos[3] = $oRect->maxy;
207                 }
208             }
209
210             if ($szInputType == "POINT")
211             {
212               //echo "zooming to ".$aPixPos[0].",". $aPixPos[1]."<BR>";
213                 $oRect = $this->moMapObject->oMap->extent;
214                 $nX = $oRect->minx + ($oRect->maxx - $oRect->minx)/2;
215                 $nY = $oRect->miny + ($oRect->maxy - $oRect->miny)/2;
216                 $nOffX = $aPixPos[0] - $nX;
217                 $nOffY = $aPixPos[1] - $nY;
218                 
219                 $this->moMapObject->oMap->setextent( $oRect->minx + $nOffX,
220                                                      $oRect->miny + $nOffY,
221                                                      $oRect->maxx + $nOffX,
222                                                      $oRect->maxy + $nOffY );
223             }
224             else
225             {
226                 $this->moMapObject->oMap->setextent( $aPixPos[0], $aPixPos[1], $aPixPos[2], $aPixPos[3] );
227             }
228 /* -------------------------------------------------------------------- */
229 /*      Call the reporjectauto function in case the map projection      */
230 /*      is set to AUTO:XXX. If it is not, the function will do          */
231 /*      nothing.                                                        */
232 /* -------------------------------------------------------------------- */
233             $this->ReprojectAuto();
234
235         }
236         
237         // return success
238         return true;
239     }
240
241     /**
242      * GetJavascriptFunctions
243      *
244      * Build and return the array of functions needed in the
245      * widget.
246      */
247     function GetJavascriptFunctions()
248     {
249         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
250           $bCWCJSAPI = 1;
251         else
252           $bCWCJSAPI = 0;
253
254         $aReturn = $this->moButton->GetJavascriptFunctions();//array();
255         $szJsFunctionName = "clickBoundingBoxPopup";
256         $szButtonJS = $this->moPopup->DrawPublish();
257         $szFunction = <<<EOT
258 /**
259  * {$szJsFunctionName}
260  * popup a Bounding Box dialog
261  */
262 function {$szJsFunctionName}()
263 {
264     {$szButtonJS}
265     return;
266 }
267 EOT;
268         $aReturn[$szJsFunctionName] = $szFunction;
269
270         $szJsFunctionName = "applyBoundingBox";
271         $szFunction = <<<EOT
272 /**
273  * {$szJsFunctionName}
274  * popup a Bounding Box dialog
275  */
276 function {$szJsFunctionName}(nMinX, nMinY, nMaxX, nMaxY)
277 {
278     szCoords = "" + nMinX + "," + nMinY;
279     if (nMaxX != "" && nMaxY != "")
280     {
281         szType = "RECTANGLE";
282         szCoords = szCoords + "," + nMaxX + "," + nMaxY;
283     }
284     else
285     {
286         szType = "POINT";
287     }
288     {$this->mszHTMLForm}.NAV_CMD.value="ZOOM_BBOX";
289     {$this->mszHTMLForm}.NAV_INPUT_TYPE.value=szType;
290     {$this->mszHTMLForm}.NAV_INPUT_COORDINATES.value=szCoords;
291     
292     if (arguments.length == 5)
293     {
294         {$this->mszHTMLForm}.NAV_INPUT_SRS.value=arguments[4];   
295     }
296
297     if ({$bCWCJSAPI})
298     {
299         goCWCJSAPI.NAV_CMD="ZOOM_BBOX";
300         goCWCJSAPI.NAV_INPUT_TYPE = szType;
301         goCWCJSAPI.NAV_INPUT_COORDINATES=szCoords;
302         if (arguments.length == 5)
303         {
304             goCWCJSAPI.NAV_INPUT_SRS=arguments[4];
305         }
306         goCWCJSAPI.UpdateNavTools();
307     }
308     else
309     {
310         {$this->mszHTMLForm}.submit();
311     }
312      return;
313 }
314 EOT;
315
316         $aReturn[$szJsFunctionName] = $szFunction;
317
318         if (is_object($this->moMapObject))
319         {
320             $nPixWidth = $this->moMapObject->oMap->width;
321             $nGeoWidth = $this->moMapObject->oMap->extent->minx -
322                          $this->moMapObject->oMap->extent->maxx;
323
324             $nPixelWidth = abs($nPixWidth / $nGeoWidth);
325
326             if ($nPixelWidth > 1)
327                 $nNbDecimal = abs(log($nPixelWidth))/log(10)+1;
328             else
329                 $nNbDecimal = 0;
330
331             $nMinX = number_format($this->moMapObject->oMap->extent->minx, $nNbDecimal, ".", "");
332             $nMinY = number_format($this->moMapObject->oMap->extent->miny, $nNbDecimal, ".", "");
333             $nMaxX = number_format($this->moMapObject->oMap->extent->maxx, $nNbDecimal, ".", "");
334             $nMaxY = number_format($this->moMapObject->oMap->extent->maxy, $nNbDecimal, ".", "");
335         }
336         else
337         {
338             $nMinX = 0;
339             $nMinY = 0;
340             $nMaxX = 1;
341             $nMaxY = 1;
342         }
343
344         $szJsFunctionName = "getMapExtents";
345         $szFunction = <<<EOT
346 /**
347  * {$szJsFunctionName}
348  * return the current extents as an array (minx, miny, maxx, maxy)
349  */
350 function {$szJsFunctionName}()
351 {
352     return new Array( {$nMinX}, {$nMinY}, {$nMaxX}, {$nMaxY} );
353 }
354 EOT;
355
356         $aReturn[$szJsFunctionName] = $szFunction;
357
358         return $aReturn;
359     }
360
361     /**
362      * DrawPublish
363      *
364      * Return the HTML code using the name in the map file and the
365      * parameters of the CWC tag.
366      */
367     function DrawPublish()
368     {
369         if (!$this->mbVisible)
370             return "<!-- BoundingBox popup widget hidden -->";
371         
372         $szResult = $this->moButton->DrawPublish();
373
374         return $szResult;
375     }
376 }
377 ?>
378
Note: See TracBrowser for help on using the browser.