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 /**
 12  * @include OpenLayers/Control/DrawFeature.js
 13  * @include OpenLayers/StyleMap.js
 14  * @include OpenLayers/Projection.js
 15  * @include OpenLayers/Layer/Vector.js
 16  * @include OpenLayers/BaseTypes/LonLat.js
 17  * @include OpenLayers/Geometry/Point.js
 18  * @include widgets/WMSLayerPanel.js
 19  */
 20 
 21 /**
 22  * @namespace framework.plugins
 23  */
 24 
 25 Ext.namespace('framework.widgets');
 26 
 27 /**
 28  * Creates a combo box that handles results from a geocoding service. By
 29  * default it uses Directory OpenLS service by Regione Autonoma della Sardegna, but it can be configured with a custom store
 30  * to use other services standard OpenLS. If the user enters a valid address in the search
 31  * box, the combo's store will be populated with records that match the
 32  * address.
 33  * @name_ RoutingPanel
 34  * @class Creates a form that handles results from a routing service OpenLS.
 35  * @constructor
 36  * @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.FormPanel">Ext.form.FormPanel</a>
 37  */
 38 framework.widgets.CapabilitiesPanel = Ext.extend(Ext.Panel,
 39         /** 
 40          * @lends framework.widgets.RoutingPanel.prototype 
 41          */
 42                 {
 43                     /**
 44                      *  Configured map for rounting
 45                      * 
 46                      * @public
 47                      * @type {Object} OpenLayers.Map
 48                      */
 49                     map: null,
 50                     /**
 51                      *  The combo box used for searching the start point
 52                      *  In order to work, the combo needs to have a propoerty locationString: lat,lon (WGS 84, example: locationString: '47.25976,9.58423') assigned depending of the searched position
 53                      *  See geocoding_type for the proposed combo.
 54                      * 
 55                      * @public
 56                      * @type {Object} Ext.form.ComboBox
 57                      */
 58                     startLocationCombo: null,
 59                     /** 
 60                      * Create a panel with one search component active, a comboBox as a switcher 
 61                      * search engine and a botton to perform the search on the active componet.
 62                      * @private
 63                      */
 64                     initComponent: function() {
 65                         this.layout = 'border';
 66                         this.cls = 'detailsMapServerClass';
 67                         this.border = true;
 68                         var store = new GeoExt.data.WMSCapabilitiesStore({
 69                             url: this.url ? this.url : 'Proxy?http://webgis.regione.sardegna.it/geoserver/ows?service=WMS&request=GetCapabilities'
 70                         });
 71                         store.load();
 72 
 73                         var grid = new Ext.grid.GridPanel({
 74                             store: store,
 75                             height: 280,
 76                             width: 400,
 77                             minSize: 50,
 78                             region: 'west',
 79                             split: true,
 80                             collapseMode: 'mini',
 81                             self_: this,
 82                             cm: new Ext.grid.ColumnModel([
 83                                 {header: "Name", dataIndex: "name", sortable: true, resizable: true},
 84                                 {id: "title", header: "Title", dataIndex: "title", sortable: true, resizable: true}
 85                             ]),
 86                             enableColumnHide: false,
 87                             viewConfig: {
 88                                 forceFit: true,
 89                                 sortAscText: 'Ordine crescente',
 90                                 sortDescText: 'Ordine decrescente',
 91                                 columnsText: 'Colonne',
 92                                 lockText: "Colonna fissa",
 93                                 unlockText: "Colonna libera"
 94                             },
 95                             sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
 96                             autoExpandColumn: "title",
 97                             bbar: ["->", {
 98                                     text: "Add Layer",
 99                                     handler: function() {
100                                         var record = grid.getSelectionModel().getSelected();
101                                         if (record && !record.isOnMap) {
102                                             record.isOnMap = true;
103                                             var copy = record.clone();
104                                             copy.getLayer().mergeNewParams({
105                                                 format: "image/png",
106                                                 transparent: "true"
107                                             });
108                                             mapPanel.layers.add(copy);
109                                             mapPanel.map.zoomToExtent(
110                                                     OpenLayers.Bounds.fromArray(copy.get("llbbox"))
111                                                     );
112                                         }
113                                     }
114                                 }]
115                         });
116 
117                         var mapPanel = new GeoExt.MapPanel({
118                             height: 300,
119                             width: 375,
120                             region: 'east'
121 //                            , map: {
122 //                                projection: "EPSG:3003",
123 //                                units: 'm',
124 //                                //resolutions: [0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048],
125 //                                maxResolution: 2048,
126 //                                maxExtent: [1010000, 4290000, 1990000, 4590000],
127 //                                restrictedExtent: [1209895, 4294504, 1786972, 4580410],
128 //                                panMethod: 'null',
129 //                                center: [1496530, 4433776],
130 //                                numZoomLevels: 15,
131 //                                zoom: 2,
132 //                                layers: [new OpenLayers.Layer.WMS("Regione","http://webgis.regione.sardegna.it/geoserver/ows",
133 //                                            {
134 //                                                layers: 'dbu:LIMITEAMMINISTRREGIONALE',
135 //                                                format: "image/png",
136 //                                                STYLES: 'overview'
137 //                                            })]
138 //                            }
139                         });
140 
141                         Ext.get(mapPanel.map.getViewport()).setStyle('background-color', '#fdfdfd');
142 
143                         var tree = new Ext.tree.TreePanel({
144                             title: "Layers",
145                             self: this,
146                             root: new GeoExt.tree.LayerContainer({
147                                 text: 'Map Layers',
148                                 layerStore: mapPanel.layers,
149                                 leaf: false,
150                                 expanded: true
151                             }),
152                             enableDD: true,
153                             width: 250,
154                             height: 300,
155                             minSize: 50,
156                             region: 'center',
157                             split: true,
158                             tbar: [{
159                                     text: "Show Properties",
160                                     handler: function() {
161                                         var node = tree.getSelectionModel().getSelectedNode();
162                                         var record;
163                                         if (node && node.layer) {
164                                             var layer = node.layer;
165                                             var store = node.layerStore;
166                                             record = store.getAt(store.findBy(function(record) {
167                                                 return record.getLayer() === layer;
168                                             }));
169                                         }
170                                         if (record) {
171                                             showProp(record);
172                                         }
173                                     }
174                                 }]
175                         });
176 
177                         this.items = [
178                             grid,
179                             tree,
180                             mapPanel
181                         ]
182 
183                         window.prop;
184                         function showProp(record) {
185                             if (window.prop) {
186                                 window.prop.close();
187                             }
188                             window.prop = new Ext.Window({
189                                 title: "Properties: " + record.get("title"),
190                                 constrainHeader: true,
191                                 width: 280,
192                                 height: 350,
193                                 layout: "fit",
194                                 items: [{
195                                         xtype: "gxp_wmslayerpanel",
196                                         layerRecord: record,
197                                         defaults: {style: "padding: 10px"}
198                                     }]
199                             });
200                             window.prop.items.get(0).add(new gxp.WMSStylesDialog({
201                                 title: "Styles",
202                                 layerRecord: record,
203                                 autoScroll: true
204                             }));
205                             window.prop.show();
206                         }
207 
208 
209 
210                         var objReturn = framework.widgets.CapabilitiesPanel.superclass.initComponent.apply(this, arguments);
211                         return objReturn;
212                     }
213                 });
214 
215         /** api: xtype = framework_capabilitiespanel */
216         Ext.reg("framework_capabilitiespanel", framework.widgets.CapabilitiesPanel);