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.widgets.search
 12  */
 13 Ext.namespace("framework.widgets.search");
 14 
 15 
 16 /** api: example
 17  *  This class can be configured via the Toolbar. It is usually not created explicitly.
 18  *  It can be either a regular 'featureinfo' or 'tooltips' widget button.
 19  *  A FeatureInfoPopup can be triggered by clcking or hovering, dependent on the config, both shown below.
 20  *  Below two sample configs for the toolbar.
 21  *
 22  *  .. code-block:: javascript
 23 
 24          {
 25            type: "featureinfo", 
 26            options: {
 27                 pressed: true,
 28                 getfeatureControl: {
 29                     hover: true,
 30                     drillDown: false,
 31                     maxFeatures: 1
 32                 },
 33                 popupWindow: {
 34                     width: 320,
 35                     height: 200,
 36                     anchored: false,
 37                     featureInfoPanel: {
 38                         // Option values are 'Grid', 'Tree' and 'XML', default is 'Grid' (results in no display menu)
 39                         displayPanels: ['Grid'],
 40                         // Export to download file. Option values are 'CSV', 'XLS', 'GMLv2', 'GeoJSON', 'WellKnownText', default is no export (results in no export menu).
 41                         exportFormats: [],
 42                         // exportFormats: ['CSV', 'XLS', 'GMLv2'],
 43                         maxFeatures: 1
 44                     }
 45                 }
 46          }
 47          },
 48 
 49          {
 50            type: "tooltips", options: {
 51            // Pressed cannot be true when anchored is true!
 52            pressed: false,
 53            getfeatureControl: {
 54                hover: true,
 55                drillDown: false,
 56                maxFeatures: 1
 57            },
 58            popupWindow: {
 59                title: "Information",
 60                hideonmove: false,
 61                anchored: true,
 62                //layer: "World Cities (FAO)",
 63                featureInfoPanel: {
 64                    // Option values are 'Grid', 'Tree' and 'XML', default is 'Grid' (results in no display menu)
 65                    displayPanels: ['Grid'],
 66                    // Export to download file. Option values are 'CSV', 'XLS', default is no export (results in no export menu).
 67                    exportFormats: []
 68                    // exportFormats: ['CSV', 'XLS'],
 69                }
 70            }
 71          }}
 72 
 73  */
 74 
 75 /**
 76 * A Popup to hold the Panel designed to hold WMS GetFeatureInfo (GFI) data for one or more WMS layers.
 77 * @name_ FeatureInfoPopup
 78 * @class A Popup to hold the Panel designed to hold WMS GetFeatureInfo (GFI) data for one or more WMS layers.
 79 * @constructor
 80 @extends <a target="_blank" href="http://geoext.org/lib/GeoExt/widgets/Popup.html">GeoExt.Popup</a>
 81 */
 82 framework.widgets.search.FeatureInfoPopup = Ext.extend(GeoExt.Popup, 
 83 /** 
 84  * @lends framework.widgets.search.FeatureInfoPopup.prototype 
 85  */
 86 {
 87 
 88     title: 'FeatureInfo popup',
 89     layout: 'fit',
 90     resizable: true,
 91     width: 320,
 92     height: 200,
 93     anchorPosition: "auto",
 94     panIn: false,
 95     draggable: true,
 96     unpinnable: false,
 97     maximizable: false,
 98     collapsible: false,
 99     closeAction: 'hide',
100     olControl: null,
101 
102     /** api: config[anchored]
103      * ``Boolean``
104      *  The popup will show where the the clicked or where the mouse stopped.
105      * @public
106      * @type Boolean
107      */
108     anchored: true,
109 
110     /** api: config[hideonmove]
111      *  
112      *  The popup will hide if hideonmove parameter is ``true``. Will be ``false`` if not set.
113      *  This parameter only applies when hover is ``true``.
114      *  @public
115      *  @type Boolean
116      */
117     hideonmove: false,
118 
119     /** api: config[layer]
120      * 
121      *  The layer to get feature information from. Parameter value will be ``""`` if not set.
122      *  If not set, all visible layers of the map will be searched. In case the drillDown
123      *  parameter is ``false``, the topmost visible layer will searched.
124      *  @public
125      *  @type String
126      */
127     layer: null,
128     
129     /**
130      * Image icon button.
131      * @public
132      * @type String
133      */
134     iconButton: 'theme/app/img/camera16x16.png',
135     
136      /** 
137      *  Override init component
138      *  @private 
139      */ 
140     initComponent: function () {
141                
142         if (!this.map)
143             this.map = this.target.mapPanel.map;
144          
145         //If hideonmove = true, the anchorPosition cannot be "auto"
146         //because the popup will not show in FireFox.
147         if (this.hideonmove) {
148             this.anchorPosition = "bottom-left";
149         }
150 
151         // Create the FI Panel and subscribe to its emitted events
152         this.fiPanel = this.createFeatureInfoPanel();
153         this.fiPanel.addListener('beforefeatureinfo', this.onBeforeFeatureInfo, this);
154         this.fiPanel.addListener('featureinfo', this.onFeatureInfo, this);
155         
156         
157         
158         // Hide tooltip if mouse moves again.
159         // For closures ("this" is not valid in callbacks)
160         var self = this;
161         this.olControl = this.fiPanel.olControl;
162         if (this.hideonmove && this.olControl.handler && this.olControl.handler.callbacks.move) {
163             this.olControl.handler.callbacks.move = function () {
164                 self.olControl.cancelHover();
165                 self.hide();
166             }
167         }
168 
169         // Add FI Panel to our window
170         this.items = [this.fiPanel];
171 
172         // Superclass init
173         framework.widgets.search.FeatureInfoPopup.superclass.initComponent.call(this);
174         if(this.mapPanel)
175             this.addListener("afterrender", this.onPanelRendered, this);
176     },
177     
178     /** api: method[createFeatureInfoPanel]
179      * Create feature info Panel
180      * @private
181      */
182     onPanelRendered: function () {
183         //chiude la finestra quando la mappa viene nascosta
184         var self = this;
185         var mapPanel = Ext.getCmp(this.mapPanel);
186         if(mapPanel){
187             mapPanel.on({
188                 'hide':function(){
189                     self.isPopupVisible = self.isVisible();
190                     self.hide();
191                 },
192                 'show':function(){
193                     if(self.isPopupVisible == true)
194                         self.show();
195                     delete self.isPopupVisible;
196                 },
197                 scope: self
198             })
199         }
200     },
201     
202 
203     /** api: method[createFeatureInfoPanel]
204      * Create feature info Panel
205      * @private
206      */
207     createFeatureInfoPanel: function () {
208         // Default properties of the featureinfoPanel.
209         var defaultConfig = {
210             title: null,
211             header: false,
212             border: false,
213             showTopToolbar: false,
214             // Export to download file. Option values are 'CSV', 'XLS', default is no export (results in no export menu).
215             exportFormats: [],
216             maxFeatures: 8,
217             hover: false,
218             drillDown: true,
219             map: this.map,
220             infoFormat: 'application/vnd.ogc.gml',
221             layer: this.layer,
222             olControl: this.olControl,
223             iconButton: this.iconButton,
224             listeners: {
225                 showAerialPhoto: function(record) {
226                     this.fireEvent('showAerialPhoto',record);
227                 },
228                 scope: this
229             }
230         };
231 
232         var config = Ext.apply(defaultConfig, this.featureInfoPanel);
233         return new framework.widgets.search.FeatureInfoPanel(config);
234     },
235 
236     /** api: method[onBeforeFeatureInfo]
237      * Hide feature info Panel
238      * @private
239      */
240     onBeforeFeatureInfo: function (evt) {
241         this.hide();
242     },
243 
244     /** api: method[onFeatureInfo]
245      * Show feature info Panel
246      * @private
247      */
248     onFeatureInfo: function (evt) {
249         //If the event was not triggered from this.olControl, do nothing
250         // Don't show popup when no features found in in tooltips (anchored mode)
251         if ((!evt.features || evt.features.length == 0) && this.anchored && this.olControl.hover) {
252             this.hide();
253             return;
254         }
255         // Features available: popup at geo-location
256         this.location = this.map.getLonLatFromPixel(evt.xy);
257         this.show();
258     },
259 
260     /** api: method[deactivate]
261      * Hide feature info Panel
262      * @private
263      */
264      deactivate: function () {
265         this.hide();
266     }
267 
268 
269 });
270 
271 /** api: xtype = framework_featureinfopopup */
272 Ext.reg('framework_featureinfopopup', framework.widgets.search.FeatureInfoPopup);
273