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

root/Chameleon/trunk/Chameleon/LayerAttributes/LayerAttributes.widget.php

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

Latest Chameleon code checkout from previous repository

Line 
1 <?php
2 /**
3  * LayerAttributes Widget class
4  *
5  * @project     GeoInnovations 2002 - SECT
6  * @revision    $Id: LayerAttributes.widget.php,v 1.3 2004/10/14 18:19:14 pspencer Exp $
7  * @purpose     LayerAttributes Widget class puts the attributes of a layer
8  *              into a shared resource for the use of a JSList widget
9  * @author      DM Solutions Group (dev@dmsolutions.ca)
10  * @copyright
11  * <b>Copyright (c) 2004, DM Solutions Group Inc.</b>
12  * Permission is hereby granted, free of charge, to any person obtaining a
13  * copy of this software and associated documentation files (the "Software"),
14  * to deal in the Software without restriction, including without limitation
15  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  * and/or sell copies of the Software, and to permit persons to whom the
17  * Software is furnished to do so, subject to the following conditions:
18  *
19  * The above copyright notice and this permission notice shall be included
20  * in all copies or substantial portions of the Software.
21  *
22  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
25  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28  * DEALINGS IN THE SOFTWARE.
29  */
30
31 include_once(dirname(__FILE__)."/../Widget.php");
32 include_once( dirname(__FILE__)."/../LayerAttributes.php" );
33
34 /**
35  * LayerAttributes Widget
36  *
37  * @desc a widget that extracts the attributes of a map layer and inserts it
38  *       into a SharedResource.
39  */
40 class LayerAttributes extends CWCWidget
41 {
42     /* the name of the shared resource to dump the results into */
43     var $mszSharedResourceName;
44
45     /* the index of the layer in the mapfile */
46     var $mnAttributeLayerIndex;
47     
48     var $mszSelectedItem = "";
49     
50     /**
51      * LayerAttributes
52      *
53      * Constructor method for the LayerAttributes widget.
54      */
55     function LayerAttributes()
56     {
57         // invoke constructor of parent
58         parent::CWCWidget();
59
60         
61         // set the description for this widget
62         $this->szWidgetDescription = <<<EOT
63 The LayerAttributes widget gets the contents of a mapfile layer and adds an array to
64 a SharedResource widget in a format suitable for feeding a JSList widget.
65 The layer to process must be passed in the url as nlayerindex.
66 EOT;
67
68         $this->maAttributes["SHAREDRESOURCENAME"] =
69             new StringAttribute( "SHAREDRESOURCENAME", true );
70
71         $this->maAttributes["LAYERNAME"] =
72             new StringAttribute( "LAYERNAME", false );
73         $this->maAttributes["ITEM"] =
74             new StringAttribute( "ITEM", true, array( "CLASSITEM", "LABELITEM", "TILEITEM", "FILTERITEM", "STYLEITEM" ) );
75         $this->maAttributes["ONCHANGE"] =
76             new StringAttribute( "ONCHANGE", false );
77         $this->maAttributes["VISIBILITY"] =
78             new BooleanAttribute( "VISIBILITY", false );
79         
80         $this->mnMaturityLevel = MATURITY_ALPHA;
81     }
82
83     /**
84      * initialize respectable defaults
85      */
86     function InitDefaults()
87     {
88         parent::InitDefaults();
89
90         if (isset($this->maParams["SHAREDRESOURCENAME"]))
91         {
92             $this->mszSharedResourceName =
93                 $this->maParams["SHAREDRESOURCENAME"];
94         }
95         if (!isset($this->maParams["ONCHANGE"]))
96         {
97             $this->maParams["ONCHANGE"] = '';
98         }
99     }
100
101     /**
102      * return an array of HTML variables to include in the page
103      */
104     function GetHTMLHiddenVariables()
105     {
106         $aReturn = array();
107         $szVariable = 'nlayerindex';
108
109         return $aReturn;
110     }
111         
112     /**
113      * Parse the layer and create the necessary entries in the
114      * shared resource.
115      */
116     function ParseURL()
117     {
118         $srName = $this->mszSharedResourceName;
119         
120         $oMap = $this->moMapObject->oMap;
121         
122         if ($this->isVarSet('initlayername'))
123         {
124             //this is coming from the main interface
125             //convert a named layer into a layer index
126             $oLayer = $oMap->getLayerByName( $this->getVar('initlayername') );
127             $this->mnAttributeLayerIndex = $oLayer->index;
128         }
129         elseif($this->isVarSet('initlayerindex'))
130         {
131             $oLayer = $oMap->getLayer( $this->getVar('initlayerindex') );
132             $this->mnAttributeLayerIndex = $oLayer->index;
133         }
134         else
135         {
136             //use previously set layer - reloading
137             $oLayer = $oMap->getLayer( $this->getVar('nlayerindex') );
138             $this->mnAttributeLayerIndex = $oLayer->index;
139         }
140         
141         if ( strcasecmp( $this->maParams['ITEM'], 'classitem' ) == 0 )
142             $this->mszSelectedItem = $oLayer->classitem;
143         else if ( strcasecmp( $this->maParams['ITEM'], 'labelitem' ) == 0 )
144             $this->mszSelectedItem = $oLayer->labelitem;
145         else if ( strcasecmp( $this->maParams['ITEM'], 'tileitem' ) == 0 )
146             $this->mszSelectedItem = $oLayer->tileitem;
147         else if ( strcasecmp( $this->maParams['ITEM'], 'filteritem' ) == 0 )
148             $this->mszSelectedItem = $oLayer->filteritem;
149         else if ( strcasecmp( $this->maParams['ITEM'], 'styleitem' ) == 0 )
150             $this->mszSelectedItem = $oLayer->styleitem;
151             
152         //:TODO: format results as a proper sr so that
153         //we can allow this widget to use it's own drawing
154         //or pass it off to a JSList if visiblity=false
155         
156         //gather attributes and assign them to sharedreosource
157         //first check for existing shared resource, then session vars then
158         //get it from server/local layer
159         if(!(isset($this->maSharedResourceWidgets[$srName]) &&
160             count($this->maSharedResourceWidgets[$srName]->maszContents)))
161         {
162             if (isset($_SESSION[$srName][$oLayer->name]))
163             {
164                 $this->maSharedResourceWidgets[$srName] =
165                     $_SESSION[$srName][$oLayer->name];
166             }
167             else
168             {
169                 $this->maSharedResourceWidgets[$srName]->maszContents =
170                                             GetLayerAttributes($oLayer);
171                 $_SESSION[$srName][$oLayer->name] =
172                                             $this->maSharedResourceWidgets[$srName];
173             }
174         }         
175         
176         return true;
177     }
178     
179     function DrawPublish()
180     {
181         if (!$this->mbVisible)
182             return "<!-- LayerAttributes widget hidden -->";
183             
184         $srName = $this->mszSharedResourceName;       
185         $sr = $this->maSharedResourceWidgets[$srName];
186         
187         //generate an option select list of attributes
188         //or a text entry box if there are none.
189         if (!count($sr->maszContents))
190         {
191             $szResult  = '<input TYPE="text" SIZE="10" NAME="';
192             $szResult .= $this->maParams['ITEM'].
193                         '" ID="' .$this->maParams['ITEM'].
194                         '" ONCHANGE="'.
195                         $this->maParams['ONCHANGE'];
196             $szResult .= '" >'."\n";
197         }
198         else
199         {
200             $szResult = '<SELECT NAME="' .$this->maParams['ITEM'].
201                         '" id="' .$this->maParams['ITEM'].
202                         '" ONCHANGE="'.
203                         $this->maParams['ONCHANGE'].
204                         '" >'."\n";
205             $szResult .= '  <OPTION VALUE="">None'."\n";
206             foreach(array_keys($sr->maszContents['fields']) as $szFieldName)
207             {
208                 if ($szFieldName != "LayerType")
209                 {
210                     $szResult .= '  <OPTION VALUE="'. $szFieldName.'"';
211                     if (strcasecmp( $szFieldName, $this->mszSelectedItem) == 0)
212                         $szResult .= ' SELECTED';
213                     $szResult .= '>'. $szFieldName."\n";
214                 }
215             }
216             $szResult .= '</SELECT>'."\n";
217         }
218         
219         return $szResult;
220     }
221 }
222 ?>
Note: See TracBrowser for help on using the browser.