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

root/Chameleon/trunk/Chameleon/ZoomSelectedLayers/ZoomSelectedLayers.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * ZoomSelectedLayers Widget class
4  *
5  * @project     CWC2
6  * @revision    $Id: ZoomSelectedLayers.widget.php,v 1.11 2005/01/25 16:00:19 jfournier Exp $
7  * @purpose     Zoom Selected Layers 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 include_once(dirname(__FILE__)."/../NavTool.php");
31
32 /**
33  * ZoomSelectedLayersWidget
34  *
35  * @desc ZoomSelectedLayers widget.
36  */
37 class ZoomSelectedLayers extends NavTool
38 {
39     var $mnBuffer = 0.01;
40
41     /**
42      * ZoomSelectedLayersWidget
43      *
44      * Constructor. Set the default values.
45      */
46     function ZoomSelectedLayers()
47     {
48         // invoke constructor of parent
49         parent::NavTool();
50         $this->SetNavCommand( "ZOOM_SELECTED" );
51         $this->mbSubmitOnClick = true;
52        
53         // set the description for this widget
54         $this->szWidgetDescription = "Zoom to the extents of the selected layers plus a small (1%) buffer";
55        
56         $this->maAttributes['BUFFER'] = new IntegerAttribute( 'BUFFER', false, 0, 100 );
57         $this->mnMaturityLevel = MATURITY_BETA;
58     }
59    
60     function InitDefaults()
61     {
62         parent::InitDefaults();
63         if (isset($this->maParams['BUFFER']))
64         {
65             $this->mnBuffer = $this->maParams['BUFFER'] / 100;
66         }
67     }
68
69     /**
70      * ParseURL
71      *
72      * Look for the ZOOM_IN command and if founddo the zooming
73      * according to the other NAV paramaters.
74      */
75     function  ParseURL()
76     {
77         parent::ParseURL();
78        
79         //sanity test on getextent function
80         if ($this->moMapObject->oMap->numlayers == 0)
81             return true;
82        
83         $oLayer=$this->moMapObject->oMap->getLayer(0);
84         if (!method_exists( $oLayer, "getextent" ))
85         {
86             $_SESSION['gErrorManager']->setError(ERR_WARNING, "The version of mapscript that you are using is not supported by the ZoomSelectedLayers widget.  You must use version 4.2.3+ or version 4.4.0+ (beta2 does not work)");
87             return false;
88         }
89        
90         $szCmd = "";
91         if ($this->isVarSet( "NAV_CMD" ))
92           $szCmd = trim($this->getVar( "NAV_CMD" ));
93          
94         if ($szCmd == "ZOOM_SELECTED")
95         {
96             //handle ZoomSelectedLayers here.
97             $szOriginalExtents = trim($this->moMapObject->oMap->getMetaData( "original_extents" ));
98             $szOriginalProjection = $this->moMapObject->oMap->getMetaData( "original_projection" );
99             if (strlen($szOriginalExtents) > 0)
100             {
101                 $aszExtents = explode(",", $szOriginalExtents);
102                 if (count($aszExtents) == 4)
103                 {
104                         if ($szOriginalProjection != "" && $szOriginalProjection != $this->moMapObject->oMap->getprojection())
105                         {
106                             $aszExtents = $this->moMapNavigator->reprojectExtentFromCenter($aszExtents, $this->moMapObject->oMap->width, $this->moMapObject->oMap->height, $szOriginalProjection,$this->moMapObject->oMap->getProjection());
107                         }
108                 }
109             }
110             $szMapProj = $this->moMapObject->oMap->getProjection();
111             $oMapProj = ms_newProjectionObj( $szMapProj );
112             $oQueryExtent = ms_newRectObj();
113             $oQueryExtent->setextent( $aszExtents[0],$aszExtents[1],$aszExtents[2],$aszExtents[3] );
114             for($i=0; $i<$this->moMapObject->oMap->numlayers;$i++)
115             {
116                 $oLayer = $this->moMapObject->oMap->getLayer($i);
117                 if ($oLayer->getMetaData( "selected" ) == "1" )
118                 {
119                     @$oLayer->queryByRect( $oQueryExtent );
120                     if ($oLayer->getNumResults() > 0)
121                     {
122                         $nResults = $oLayer->getNumResults();
123                         $oBBox = $oLayer->getExtent();
124                        
125                         $szLayerProj = $oLayer->getProjection();
126                         if ($szLayerProj != $szMapProj)
127                         {
128                             $oLayerProj = ms_newProjectionObj( $szLayerProj );
129                             $oBBox->project( $oLayerProj, $oMapProj );
130                         }
131                     }
132                 }
133                
134             }
135             if (isset($oBBox))
136             {
137                 $width = ($oBBox->maxx - $oBBox->minx) * $this->mnBuffer;
138                 $height = ($oBBox->maxy - $oBBox->miny) * $this->mnBuffer;
139                
140                 if( $width == 0 || $height == 0 )
141                 {
142                     /*
143                      * if projection is not lat/lon
144                      * change point to lat/lon
145                      * calculate 1 degree buffer as rect object
146                      * reproject rect obj back into orig proj
147                      * calculate new width/height
148                      */
149                      if( $szMapProj != "init=epsg:4326" )
150                      {
151                         $oLLProj = ms_newprojectionobj( "init=epsg:4326" );
152                         $oBBox->project( $oMapProj, $oLLProj );
153                      }
154                      $oBBox->setextent( $oBBox->minx - 0.5, $oBBox->miny - 0.5, $oBBox->maxx + 0.5, $oBBox->maxy + 0.5 );
155                      if( $szMapProj != "init=epsg:4326" )
156                      {
157                          $oBBox->project( $oLLProj, $oMapProj );
158                      }
159                      $width = ($oBBox->maxx - $oBBox->minx);
160                      $height = ($oBBox->maxy - $oBBox->miny);
161                 }
162                
163                 //echo 'minx: ' . ($oBBox->minx - $width ). ', miny: ' . ($oBBox->miny - $height ). ', maxx: ' . ($oBBox->maxx+$width ). ', maxy: ' .( $oBBox->maxy + $height ). '<br><br>';
164                 $this->moMapObject->oMap->setextent( $oBBox->minx - $width, $oBBox->miny - $height, $oBBox->maxx+$width, $oBBox->maxy + $height );
165             }
166                
167         }       
168         // return success
169         return true;
170     }
171 }
172 ?>
Note: See TracBrowser for help on using the browser.