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

root/Chameleon/trunk/Chameleon/ScaleZoom/ScaleZoom.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ScaleZoom Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: ScaleZoom.widget.php,v 1.6 2004/11/15 19:45:02 wbronsema Exp $
7  * @purpose     ScaleZoom 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
30
31 include_once(dirname(__FILE__)."/../NavTool.php");
32
33 /**
34  * ScaleZoom
35  *
36  * @desc Display scale bar that the user can zoom to a different.
37  * scale using.
38  */
39 class ScaleZoom extends NavTool
40 {
41     var $mszDirection = "horizontal";
42     var $mszCurrentImage = "";
43     var $mbPutTableTags = true;
44
45     /**
46      * ScaleZoom
47      *
48      * Constructor for the ScaleZoom
49      */
50     function ScaleZoom( )
51     {
52         $this->mszLanguageResource = str_replace("\\","/",dirname(__FILE__))."/ScaleZoom.dbf";
53
54         // invoke constructor of parent
55         parent::NavTool();
56
57         $this->SetNavCommand("SCALE_ZOOM");
58
59         // set the description for this widget
60         $this->szWidgetDescription = <<<EOT
61 The ScaleZoom widget displays a series of preset scale buttons that the user
62 can use to quickly zoom in or out at predefined intervals.  The intermediate
63 scales are defined using sub-tags as follows: &lt;ZOOMVALUE SCALE="42000000"
64 IMAGE="images/zoom_h_1.gif" IMAGEWIDTH="14" IMAGEHEIGHT="22"/&gt;.  Any number
65 of zoomvalues are allowed, but there is likely a practical limit depending on
66 the images used.
67 EOT;
68
69         $this->maAttributes["INCREASEIMAGE"] = new StringAttribute("INCREASEIMAGE", false);
70         $this->maAttributes["DECREASEIMAGE"] = new StringAttribute("DECREASEIMAGE", false);
71         $this->maAttributes["INCREASETO"] = new IntegerAttribute("INCREASETO", false);
72         $this->maAttributes["DECREASETO"] = new IntegerAttribute("DECREASETO", false);
73         $this->maAttributes["ORIENTATION"] = new StringAttribute("ORIENTATION", false,
74             array( "HORIZONTAL", "VERTICAL" ));
75         $this->maAttributes["CURRENTIMAGE"] = new StringAttribute("CURRENTIMAGE", false);
76         $this->maAttributes["PUTTABLETAGS"] = new BooleanAttribute("PUTTABLETAGS", false);
77         $this->mnMaturityLevel = MATURITY_BETA;
78     }
79
80     function InitDefaults()
81     {
82         parent::InitDefaults();
83         $this->maParams["IMAGE"] = "DUMMY";
84         // Dont call parent; we want to overwrite some NAVtool behavior
85         // But we need the parrent mszHTMLForm variable and few other things.....
86
87         if (isset($this->maParams["VISIBLE"]))
88             $this->mbVisible = ((strcasecmp($this->maParams["VISIBLE"], "TRUE")==0) ? true : false);
89
90         if (isset($this->maParams["ENABLED"]))
91             $this->mbEnabled = ((strcasecmp($this->maParams["ENABLED"], "TRUE")==0) ? true : false);
92
93         if (isset($this->maParams["FORMINDEX"]))
94             $this->mnFormIndex = $this->maParams["FORMINDEX"];
95
96         if (isset($this->maParams["PUTTABLETAGS"]))
97             $this->mbPutTableTags = (strtoupper($this->maParams["PUTTABLETAGS"]) == "FALSE") ? false : true;
98
99         $this->mszHTMLForm = "document.forms[".$this->mnFormIndex."]";
100     }
101
102
103     /**
104      * GetJavascriptFunctions
105      *
106      * Build and return the array of functions needed in the
107      * widget.
108      */
109     function GetJavascriptFunctions()
110     {
111         $aReturn = parent::GetJavascriptFunctions();
112
113         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
114           $bCWCJSAPI = 1;
115         else
116           $bCWCJSAPI = 0;
117
118         $szJsFunctionName = "clickScaleValue";
119         $szFunction = <<<EOT
120 /**
121  * {$szJsFunctionName}
122  * popup a Projection Selector dialog
123  */
124 function {$szJsFunctionName}(szScale)
125 {
126     {$this->mszHTMLForm}.NAV_CMD.value = "SCALE_ZOOM";
127     {$this->mszHTMLForm}.SCALE_ZOOM.value = szScale;
128
129     if ($bCWCJSAPI)
130     {
131         goCWCJSAPI.SCALE_ZOOM = szScale;
132         goCWCJSAPI.UpdateScaleZoom();
133     }
134     else
135     {
136         {$this->mszHTMLForm}.submit();
137     }
138
139     return;
140 }
141 EOT;
142         $aReturn[$szJsFunctionName] = $szFunction;
143
144         return $aReturn;
145     }
146
147     /**
148      * GetHTMLHiddenVariables
149      *
150      * return the NAV_SCALE varaiable.
151      */
152     function GetHTMLHiddenVariables()
153     {
154         $aReturn = parent::GetHTMLHiddenVariables();
155
156         $szVariable = "SCALE_ZOOM";
157         $szValue = "<INPUT TYPE=\"HIDDEN\" NAME=\"$szVariable\" VALUE=\"\">\n";
158         $aReturn[$szVariable] = $szValue;
159
160         return $aReturn;
161     }
162
163     /**
164      * ParseURL
165      *
166      * Compare NAV_SCALE to SCALE and zoomscale if they are different
167      */
168     function  ParseURL()
169     {
170         parent::ParseURL();
171
172         $szCmd = "";
173         if ($this->isVarSet( "NAV_CMD" ))
174             $szCmd = $this->getVar( "NAV_CMD" );
175
176         if ($szCmd == "SCALE_ZOOM")
177         {
178
179             $szCurrentScale = $this->moMapObject->oMap->scale;
180
181             $szNewScale = "";
182             if ($this->isVarSet( "SCALE_ZOOM" ))
183                 $szNewScale = $this->getVar( "SCALE_ZOOM" );
184
185             if ($szNewScale != "")
186             {
187                 $this->moMapNavigator->zoomScale( $szNewScale);
188             /**
189         Call the reporjectauto function in case the map projection
190         is set to AUTO:XXX. If it is not, the function will do
191         nothing.
192             */
193                 $this->ReprojectAuto();                       
194              
195             }
196         }
197
198         return true;
199     }
200
201     /**
202      * DrawPublish
203      *
204      * Return the HTML code using the name in the map file and the
205      * parameters of the CWC tag.
206      */
207     function DrawPublish()
208     {
209         $oApp = GetChameleonApplication();
210        
211         $szJsOnClick = "";
212        
213         if (!$this->mbVisible)
214             return "<!-- ScaleZoom widget hidden -->";
215        
216         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
217           $bCWCJSAPI = 1;
218         else
219           $bCWCJSAPI = 0;
220
221         if (isset($this->maSharedResourceWidgets["CWCJSAPI"]))
222         {
223               $szSubmit = ";goCWCJSAPI.UpdateNavTools();";
224         }
225         else
226         {
227               $szSubmit = $this->mszHTMLForm . ".submit();return false;";
228         }
229
230        
231         $nCurrentScale = (int)$this->moMapObject->oMap->scale;
232         if(isset($this->maParams["INCREASETO"]))
233             $nIncreaseTo = $this->maParams["INCREASETO"];
234         else
235             $nIncreaseTo = 1;
236         if(isset($this->maParams["DECREASETO"]))
237             $nDecreaseTo = $this->maParams["DECREASETO"];
238         else
239             $nDecreaseTo = 100000000;
240
241         $nFactor = 1; //if we are within this much, it's a match
242         $aScale = array();
243         if (isset( $this->maszContents["ZOOMVALUE"]))
244         {
245             foreach($this->maszContents["ZOOMVALUE"] as $aZoom)
246             {
247                 $nScale = (int)$aZoom["SCALE"];
248                 if ($nScale != "-1")
249                 {
250                     if (abs($nCurrentScale - $nScale) <= $nFactor)
251                         $nCurrentScale = $nScale;
252                     array_push( $aScale, $nScale );
253                 }
254             }
255             rsort($aScale);
256             $nCurrentZoomLevel = 0;
257             $nCurrentScaleDiff = 1000000000;
258             $bCurrentZoom = isset($this->maParams["CURRENTIMAGE"]);
259             $nScales = count($aScale);
260             for($i=0;$i<$nScales;$i++)
261             {
262                 if(abs($nCurrentScale - $aScale[$i]) < $nCurrentScaleDiff)
263                 {
264                     $nCurrentScaleDiff = abs($nCurrentScale - $aScale[$i]);
265                     if($bCurrentZoom)
266                         $nCurrentZoomLevel = $i;
267                     if(isset($aScale[$i+1]))
268                         $nIncreaseTo = $aScale[$i+1];
269                     else
270                         $nIncreaseTo = $aScale[$nScales-1];
271                     if(isset($aScale[$i-1]))
272                         $nDecreaseTo = $aScale[$i-1];
273                     else
274                         $nDecreaseTo = $aScale[0];
275                 }
276             }
277         }
278
279         if (!isset($this->maParams["INCREASEIMAGE"]))
280         {
281             $szImageIncrease = "";
282         }
283         else
284         {
285             $szImageIncrease = $oApp->findFile( $this->maParams["INCREASEIMAGE"] );
286             $szImageIncrease = $oApp->fileSystemToURL( $szImageIncrease );
287         }
288         if (!isset($this->maParams["DECREASEIMAGE"]))
289         {
290             $szImageDecrease = "";
291         }
292         else
293         {
294             $szImageDecrease = $oApp->findFile( $this->maParams["DECREASEIMAGE"] );
295             $szImageDecrease = $oApp->fileSystemToURL( $szImageDecrease );
296         }
297        
298         $szDirection = $this->mszDirection;
299         if (isset($this->maParams["ORIENTATION"]))
300             $szDirection = $this->maParams["ORIENTATION"];
301
302         $szResult = "";
303         if ($this->mbPutTableTags)
304             $szResult = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
305
306         $szResult .= "<tr>\n";
307
308         if ($nDecreaseTo != "-1")
309         {
310             $szStart = "<a href=\"#\" onClick=\"clickScaleValue($nDecreaseTo);\">";
311             $szEnd = "</a>";
312         }
313
314         if ($szImageDecrease != "")
315             $szResult .= "<td>$szStart<img src=\"$szImageDecrease\" title=\"".trim($this->moMLT->get("1", "Zoom Out to 1:"))."$nDecreaseTo\" alt=\"".trim($this->moMLT->get("1", "Zoom Out to 1:"))."$nDecreaseTo\" border=\"0\">$szEnd</td>\n";
316         if (isset( $this->maszContents["ZOOMVALUE"] ))
317         {
318             $i = 0;
319             foreach($this->maszContents["ZOOMVALUE"] as $aZoom)
320             {
321                 if (strcasecmp($szDirection, "VERTICAL") == 0)
322                 {
323                     $szResult .= "</tr>\n<tr>\n";
324                 }
325                 if (!isset( $aZoom["SCALE"] ) || !isset( $aZoom["IMAGE"]))
326                     continue;
327                 $szWidth = $szHeight = "";
328                 $szScale = $aZoom["SCALE"];
329                
330                 $szImage = $oApp->findFile($aZoom["IMAGE"]);
331                 $szImage = $oApp->fileSystemToURL( $szImage );
332                
333                 if (isset( $aZoom["IMAGEWIDTH"] ))
334                     $szWidth = " width=\"".$aZoom["IMAGEWIDTH"]."\"";
335                 if (isset( $aZoom["IMAGEHEIGHT"] ))
336                     $szHeight = " height=\"".$aZoom["IMAGEHEIGHT"]."\"";
337
338                 if ($szScale == "-1")
339                 {
340                     $szResult .= "<td><img src=\"$szImage\"$szWidth$szHeight title=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" alt=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" border=\"0\"></td>";
341                     $nCurrentZoomLevel++;
342                 }
343                 else
344                 if(isset($this->maParams["CURRENTIMAGE"]) &&
345                    $i == $nCurrentZoomLevel)
346                 {
347                     $szResult .= "<td><img src=\"".$this->maParams["CURRENTIMAGE"]."\"$szWidth$szHeight title=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" alt=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" border=\"0\"></td>";
348                 }
349                 else
350                     $szResult .= "<td><a href=\"#\" onClick=\"clickScaleValue($szScale);\"><img src=\"$szImage\"$szWidth$szHeight title=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" alt=\"".trim($this->moMLT->get("3", "Zoom to 1:"))."$szScale\" border=\"0\"></a></td>";
351
352                 $i++;
353
354             }
355             if (strcasecmp($szDirection, "VERTICAL") == 0)
356                 {
357                     $szResult .= "</tr>\n<tr>\n";
358                 }
359
360         }
361         $szStart = "<a href=\"#\" onClick=\"clickScaleValue($nIncreaseTo);\">";
362         $szEnd = "</a>";
363         if ($szImageIncrease != "")
364             $szResult .= "<td>$szStart<img src=\"$szImageIncrease\" title=\"".trim($this->moMLT->get("2", "Zoom In to 1:"))."$nIncreaseTo\" alt=\"".trim($this->moMLT->get("2", "Zoom In to 1:"))."$nIncreaseTo\" border=\"0\">$szEnd</td>";
365         $szResult .= "</tr>";
366
367         if ($this->mbPutTableTags)
368             $szResult .= "</table>\n";
369
370         return $szResult;
371
372     }
373 }
374 ?>
Note: See TracBrowser for help on using the browser.