1 /**
  2  * @fileOverview  
  3  * Copyright (c) 2013 Regione Autonoma della Sardegna
  4  * Published under the GPL license.<br>
  5  * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a>
  6  * for the full text of the license.
  7  * @version 0.1
  8  */
  9 
 10 /**
 11  * @namespace framework.plugins
 12  */
 13 Ext.namespace("framework.form");
 14 
 15 /**
 16 * Combo to select the images layer of the map.
 17 * This implementation, by default, place a comboBox on the center of the map. 
 18 * The component shoult be put inside a panel to customize position inside the map. 
 19 * @name_ ImagesLayersComboBox
 20 * @class Creates a Combo to select the active layer of the map.
 21 * @constructor
 22 @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.ComboBox">Ext.form.ComboBox</a>
 23 */
 24 framework.form.ImagesLayersComboBox = Ext.extend(Ext.form.ComboBox,
 25 /** 
 26  * @lends framework.form.ImagesLayersComboBox.prototype 
 27  */
 28 {
 29 
 30     /** private: property[groupName]
 31      * group name filter,
 32      * @public
 33      * @type String
 34      */
 35     groupName: null,
 36     
 37     /** private: property[layers]
 38     * layers object that populate the comboBox ,
 39     * @public
 40     * @type [object] array of layers
 41     */
 42     layers: null,
 43     
 44     /** private: property[order]
 45      * Groups order on comboBox,
 46      * @public
 47      * @type [String]
 48      */
 49     order: null,
 50 
 51     /** private: property[tpl]
 52      * template result search.
 53      * @private
 54      * @type Ext.XTemplate
 55      */
 56     tpl: new Ext.XTemplate(
 57         '<ul><tpl for=".">',
 58         '<tpl if="(values.name != \'none\') && (this.group != values.subGroup)">',
 59         '<tpl exec="this.group = values.subGroup"></tpl>',
 60         '<li><b>{subGroup}</b><li>',
 61         '</tpl>',
 62         '<li class="x-combo-list-item" role="None">{layername}</li>',
 63         '</tpl></ul>'
 64     ),
 65     
 66    /**
 67      * proxy, default is null.
 68      * @private
 69      * @type String
 70      */
 71     proxy: null,
 72     
 73     volilayerName:'INVILUPPIIMMAGINI',
 74     
 75     voliTagName:'NOME',
 76     
 77     epsg:'EPSG%3A3003',
 78     
 79     sortByField:'NOME',
 80     
 81     /** Init the component creating a store and object'events.
 82     * @public
 83     */  
 84     initComponent: function() {
 85 
 86         //var epsgOutput = this.srs.replace("EPSG:","");
 87         
 88         if(!this.map){
 89             var mapPanel = this.findParentBy(function(cmp) {
 90                 return cmp instanceof GeoExt.MapPanel;
 91                 });
 92             this.map = mapPanel.map;
 93         }
 94         
 95         this.extent = {bottom:0,left:0,right:0,top:0};
 96         
 97         if (Ext.isString(this.srs)) {
 98             this.srs = new OpenLayers.Projection(this.srs);
 99         }
100         var sUrl="";
101         if (this.proxy)
102             sUrl = this.proxy + escape(this.url);
103         else
104             sUrl = this.url;
105 
106         if (!this.store) {
107             this.store = new Ext.data.Store({
108                 proxy: new Ext.data.HttpProxy({
109                     url: sUrl,
110                     method: 'POST'
111                 }),
112                 fields: ["source","visibility","name","shape","strisciata","fotogramma","typeImg","group","subGroup","title","layername","tmsUrl","opacity","fixed","selected"],
113                 reader: this.reader,
114                 
115                 listeners: {
116                     load: function (){
117                              this.combo.fireEvent('viewReady');
118                     },
119                     
120                     beforeload: function(store, operation) {
121                        var queryParam = this.combo.queryParam;
122                        store.baseParams[queryParam] = "&typename=" + this.combo.volilayerName + "&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&propertyName=" + 
123                                 this.combo.voliTagName + "&SRS=" + this.combo.epsg + 
124                                 "&BBOX=" + this.combo.extent.left + "," + this.combo.extent.bottom + "," + this.combo.extent.right + "," + this.combo.extent.top + 
125                                 "&sortby="+this.combo.sortByField;
126                     }
127                 },
128                 baseParams: {
129                     'xmlRequest': ''
130                 }
131             });
132             this.store.combo = this;
133         }
134 
135         this.on({
136             //added: this.handleAdded,
137             focus: function() {
138                    var currentExtent = this.map.getExtent();
139                    if (currentExtent && (this.extent.left!=currentExtent.left || 
140                            this.extent.bottom!=currentExtent.bottom || this.extent.right!=currentExtent.right 
141                            || this.extent.top!=currentExtent.top)) {
142     	  
143                         this.extent = currentExtent; 
144                           if(!this.list)
145                             this.initList();
146                          else
147                             this.doQuery("xxxxx",true);
148                         
149                    }
150                 },
151             afterrender: function(){
152                 var visibleLayer = this.getVisibleLayer();
153                 this.setValue(visibleLayer? visibleLayer:this.emptyText);
154                 this.activeLayer = visibleLayer? new String(visibleLayer):null;
155             },
156             select: function(combo, record, index){
157                 this.fireEvent('selectAerialPhoto', index);
158                 var layer = this.map.getLayersByName(record.data.title);
159                 if(index == 0){
160                     if(this.activeLayer && !(this.activeLayer instanceof String)){
161                         this.activeLayer[0].setVisibility(false);
162                     }
163                 }else if(layer){
164                     if(this.activeLayer){
165                         if(this.activeLayer instanceof String){
166                             this.activeLayer = this.map.getLayersByName(this.activeLayer);
167                         }                        
168                         this.activeLayer[0].setVisibility(false);
169                     }
170                     this.activeLayer = layer;
171                     layer[0].setVisibility(true);
172                 }
173                 this.setValue(record.data.layername);
174             },scope: this
175         });
176         return framework.form.ImagesLayersComboBox.superclass.initComponent.apply(this, arguments);
177     },
178     
179     
180     getVisibleLayer : function(){
181         var elem = null;
182         for(var index in this.layers){
183                 elem = this.layers[index];
184                 if(elem.group == this.groupName){
185                      if(elem.visibility == true){
186                         return elem.layername;
187                     }
188                 }
189             }
190         return null;
191     }
192     
193     
194    
195 
196 
197 });
198 
199 /** api: xtype = framework_layerscombobox */
200 Ext.reg("framework_imageslayerscombobox", framework.form.ImagesLayersComboBox);
201