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 * @include framework/data/Catasto_XLSReader.js 12 */ 13 14 /** 15 * @namespace framework.plugins 16 */ 17 18 Ext.namespace('framework.widgets'); 19 20 /** 21 * Creates a combo box that handles results from a geocoding service. By 22 * default it uses Directory OpenLS service by Regione Autonoma della Sardegna, but it can be configured with a custom store 23 * to use other services standard OpenLS. If the user enters a valid address in the search 24 * box, the combo's store will be populated with records that match the 25 * address. 26 * @name_ RoutingPanel 27 * @class Creates a form that handles results from a routing service OpenLS. 28 * @constructor 29 * @extends <a target="_blank" href="http://docs.sencha.com/extjs/3.4.0/#!/api/Ext.form.FormPanel">Ext.Panel</a> 30 */ 31 32 framework.widgets.CatastoSearchPanel = Ext.extend(Ext.Panel, 33 /** 34 * @lends framework.widgets.CatastoSearchPanel.prototype 35 */ 36 { 37 /** api: config[urlService] 38 * 39 * url to proxy for authenticate http calls 40 * @public 41 * @type String 42 */ 43 urlService: null, 44 /** api: config[urlCatasto] 45 * 46 * url for wfs catasto service 47 * @public 48 * @type String 49 */ 50 urlCatasto: null, 51 /** api: config[serviceType] 52 * 53 * Service type for catasto service (query string parameter) 54 * Default WFS 55 * @public 56 * @type String 57 */ 58 serviceType: 'WFS', 59 /** api: config[version] 60 * 61 * Version for WFS service (query string parameter) 62 * Default 1.0.0 63 * @public 64 * @type String 65 */ 66 version: '1.0.0', 67 /** api: config[GetFeature] 68 * 69 * Request type for WFS service (query string parameter) 70 * Default GetFeature 71 * @public 72 * @type String 73 */ 74 requestType: 'GetFeature', 75 /** api: config[typeName] 76 * 77 * typeName for WFS service (query string parameter) 78 * @public 79 * @type String 80 */ 81 typeName: null, 82 /** api: config[infoFormat] 83 * 84 * maxFeatures for WFS service (query string parameter) 85 * Default 50 86 * @public 87 * @type String 88 */ 89 maxFeatures: 50, 90 /** api: config[geometryFields] 91 * 92 * fields from service answer to be transformed on OpenLayers.Bounds 93 * @public 94 * @type Array of String 95 */ 96 geometryFields: null, 97 /** api: config[authorizzationName] 98 * 99 * Variable used to retrived, server side, autorizzation to the authenticate service 100 * @public 101 * @type String 102 */ 103 authorizzationName: null, 104 /** api: config[serveltNameCat] 105 * 106 * Servlet name to access catasto services 107 * @public 108 * @type String 109 */ 110 serveltNameCat: 'catastorequest', 111 /** 112 * Create a panel with a form for catasto search. It draw on map the result found (only if the result is unique) 113 * @private 114 */ 115 initComponent: function () { 116 117 this.map = Ext.getCmp(this.map).map; 118 this.geoJSON = new OpenLayers.Format.GeoJSON(); 119 120 var tpl = new Ext.XTemplate( 121 '<tpl for=".">', 122 '<div class="x-combo-list-item"><b>{nomeComune}</b> ({codiceBelfiore})</div>', 123 '</tpl>' 124 ); 125 126 this.storeComuniEnabled = new Ext.data.Store({ 127 url: this.serveltNameCat, 128 sortInfo: { 129 field: 'nomeComune', 130 direction: 'ASC' // or 'DESC' (case sensitive for local sorting) 131 }, 132 reader: new Ext.data.JsonReader({ 133 id: 'id' 134 }, [ 135 {name: 'nomeComune', mapping: 'nome'}, 136 {name: 'codiceBelfiore', mapping: 'codiceBelfiore'} 137 ]) 138 }); 139 this.storeComuniEnabled.load({params: {method: 'getComuniEnabled'}}); 140 141 this.comboComuni = new Ext.form.ComboBox({ 142 // xtype: 'combo', 143 name: 'CODICECOMUNE', 144 id: 'codiceBelfiore', 145 tpl: tpl, 146 mode: 'local', 147 width: 175, 148 listWidth: 160, 149 cellCls: "sideFormTableLayout", 150 store: this.storeComuniEnabled, 151 editable: true, 152 // enableKeyEvents: true, 153 triggerAction: ' query', 154 // forceSelection: true, 155 valueField: 'codiceBelfiore', 156 displayField: 'nomeComune', 157 // emptyText: 'Seleziona un comune...', 158 fieldLabel: 'Comune', 159 labelWidth: 160, 160 labelAlign: 'top' 161 }); 162 163 this.txtFoglio = new Ext.form.TextField({ 164 name: 'FOGLIO', 165 // value: '14', 166 cellCls: "sideFormTableLayout", 167 enableKeyEvents: true, 168 maxLenghtField: 6, 169 listeners: { 170 keyup: function (obj, e) { 171 var value = obj.getValue(); 172 if (value.length > obj.maxLenghtField) 173 obj.setValue(obj.getValue().substr(0, obj.maxLenghtField)); 174 else 175 obj.setValue(obj.getValue().toUpperCase()); 176 } 177 } 178 }); 179 this.txtSezione = new Ext.form.TextField({ 180 name: 'SEZIONE', 181 // value: '', 182 cellCls: "sideFormTableLayout", 183 enableKeyEvents: true, 184 maxLenghtField: 6, 185 listeners: { 186 keyup: function (obj, e) { 187 var value = obj.getValue(); 188 if (value.length > obj.maxLenghtField) 189 obj.setValue(obj.getValue().substr(0, obj.maxLenghtField)); 190 else 191 obj.setValue(obj.getValue().toUpperCase()); 192 } 193 } 194 }); 195 this.txtNumero = new Ext.form.TextField({ 196 name: 'NUMERO', 197 // value: '380', 198 cellCls: "sideFormTableLayout", 199 enableKeyEvents: true, 200 maxLenghtField: 6, 201 listeners: { 202 keyup: function (obj, e) { 203 var value = obj.getValue(); 204 if (value.length > obj.maxLenghtField) 205 obj.setValue(obj.getValue().substr(0, obj.maxLenghtField)); 206 else 207 obj.setValue(obj.getValue().toUpperCase()); 208 } 209 } 210 }); 211 212 this.btnSearch = new Ext.Button({ 213 text: "Cerca", 214 cls: "btnSerchCatasto", 215 cellCls: "sideFormTableLayout", 216 handler: this.validateForm, 217 scope: this 218 }), 219 this.items = [ 220 { 221 layout: { 222 type: 'table', 223 columns: 2 224 225 }, 226 border: false, 227 items: [ 228 {xtype: "label", text: 'Comune*', cellCls: "sideFormTableLayout"}, 229 this.comboComuni, 230 {xtype: "label", text: 'Foglio*', cellCls: "sideFormTableLayout"}, 231 this.txtFoglio, 232 {xtype: "label", text: 'Sezione', cellCls: "sideFormTableLayout"}, 233 this.txtSezione, 234 {xtype: "label", text: 'Numero', cellCls: "sideFormTableLayout"}, 235 this.txtNumero, 236 {xtype: "label", text: '', cellCls: "sideFormTableLayout"}, 237 { 238 layout: { 239 type: 'table', 240 columns: 2 241 }, 242 border: false, 243 items: [ 244 this.btnSearch, {xtype: "label", style: 'font-size:10px;', text: '(* Campi obbligatori)'} 245 ]} 246 ]} 247 ]; 248 framework.widgets.CatastoSearchPanel.superclass.initComponent.apply(this, arguments); 249 this.on({ 250 show: this.reset, 251 scope: this 252 }) 253 }, 254 /** 255 * Validate search form 256 * @private 257 */ 258 validateForm: function () { 259 var error = ''; 260 if (this.comboComuni.getValue().length === 0) 261 error = error + '- Valorizzare campo "Codice comune" \n'; 262 if (this.txtFoglio.getValue().length === 0) 263 error = error + '- Valorizzare campo "Foglio" \n'; 264 if (this.txtSezione.getValue().length > 0 && this.txtNumero.getValue().length === 0) 265 error = error + '- Se si valorizza il campo "Sezione" Ú obbligatorio valorizzare anche il campo "Numero" \n'; 266 if (error != '') 267 alert(error); 268 else 269 this.submit(); 270 }, 271 /** 272 * Submit search form 273 * @private 274 */ 275 submit: function () { 276 var self = this; 277 if (!this.busyMask) { 278 this.busyMask = new Ext.LoadMask( 279 this.map.div, { 280 msg: 'ricerca in corso ...' 281 } 282 ); 283 } 284 if (this.winFather) { 285 var father = this.ownerCt; 286 while (father && father.ownerCt !== null && father.id !== this.winFather) { 287 father = father.ownerCt; 288 } 289 if (father && father.id === this.winFather) 290 father.hide(); 291 } 292 this.busyMask.show(); 293 294 Ext.Ajax.request({ 295 method: 'POST', 296 url: this.urlService + this.urlCatasto, 297 params: this.getParameters(), 298 success: function (result, request) { 299 self.busyMask.hide(); 300 //result.responseText = '{"type":"FeatureCollection","totalFeatures":1,"features":[{"type":"Feature","id":"PARTICELLECATASTO.fid-58d2dff3_144c043185d_68f4","geometry":{"type":"Polygon","coordinates":[[[1478535.143,4443040.794],[1478537.639,4443039.209],[1478544.708,4443034.177],[1478555.885,4443028.172],[1478557.27,4443027.968],[1478565.545,4443022.366],[1478574.003,4443015.627],[1478580.915,4443025.949],[1478576.452,4443029.204],[1478566.555,4443039.546],[1478549.235,4443056.163],[1478538.334,4443047.851],[1478535.143,4443040.794]]]},"geometry_name":"POLIGONO","properties":{"IDFEATURE":56329846,"CODICECOMUNE":"A007","FOGLIO":14,"SEZIONE":"_","NUMERO":"380","QUALITACOD":null,"QUALITADESCR":null,"SUPERFICIENOMINALE":null,"SUPERFICIENOMPORZIONE":null,"AREA":741,"ALLEGATO":"0","SVILUPPO":"0","bbox":[1478535.143,4443015.627,1478580.915,4443056.163]}}],"crs":{"type":"EPSG","properties":{"code":"3003"}},"bbox":[1478535.143,4443015.627,1478580.915,4443056.163]}'; 301 try { 302 var obj = Ext.decode(result.responseText); 303 if (obj && obj.features) { 304 if (obj.features.length === 0) 305 alert('Nessun dato trovato'); 306 else if (obj.features.length === 1) 307 self.drawPolygon(self.geoJSON.parseGeometry(obj.features[0].geometry)); 308 else if (obj.features.length > 1) 309 alert('Trovati più risultati!\n Affinare la ricerca per stabilire un extent.'); 310 } else 311 alert('Il catasto non risponde'); 312 } catch (ex) { 313 Ext.MessageBox.alert('Error', 'Il servizio ÃÅ¡ andato in errore!'); 314 } 315 316 }, 317 failure: function (result, request) { 318 self.busyMask.hide(); 319 Ext.MessageBox.alert('Error', result.responseText); 320 } 321 }); 322 }, 323 /** 324 * Create query string for wfs catasto service 325 * @private 326 */ 327 getParameters: function () { 328 var typeName = this.typeNameFogli; 329 if (this.txtSezione.getValue().length > 0 || this.txtNumero.getValue().length > 0) { 330 typeName = this.typeNameParticelle; 331 } 332 var parameters = {service: this.serviceType, version: this.version, request: this.requestType, 333 typeName: typeName, maxFeatures: this.maxFeatures, outputFormat: 'application/json', 334 FILTER: this.getQueryFilter(), 335 authorizzationName: this.authorizzationName}; 336 return parameters; 337 }, 338 /** 339 * Create filter for query string 340 * @private 341 */ 342 getQueryFilter: function () { 343 var filter = '<Filter><And>'; 344 filter = filter + this.getEqualFilter(this.comboComuni.getName(), this.comboComuni.getValue()); 345 filter = filter + this.getEqualFilter(this.txtFoglio.getName(), this.txtFoglio.getValue()); 346 if (this.txtSezione.getValue().length > 0) { 347 filter = filter + this.getEqualFilter(this.txtSezione.getName(), this.txtSezione.getValue()); 348 } 349 if (this.txtNumero.getValue().length > 0) { 350 filter = filter + this.getEqualFilter(this.txtNumero.getName(), this.txtNumero.getValue()); 351 } 352 return filter + '</And></Filter>'; 353 }, 354 /** 355 * Create equal condition for query string filter 356 * @private 357 */ 358 getEqualFilter: function (PropertyName, literal) { 359 return '<PropertyIsEqualTo><PropertyName>' + PropertyName + 360 '</PropertyName><Literal>' + literal + '</Literal></PropertyIsEqualTo>' 361 }, 362 /** 363 * Draw poligon extent on map 364 * @private 365 */ 366 drawPolygon: function (polygon) { 367 //Se utilizzato in ambiente di ricerca, agganciare a questo evento la pulizia della mappa 368 369 this.map.events.triggerEvent('cleanSearchObjects'); 370 this.layerExtent.events.remove('featureselected'); 371 372 this.layerExtent.destroyFeatures(); 373 if (window.popupAddr) { 374 window.popupAddr.close(); 375 window.popupAddr.destroy(); 376 } 377 if (this.map.getLayerIndex(this.layerExtent) === -1) { 378 this.map.addLayer(this.layerExtent) 379 } 380 this.layerExtent.events.remove('featureselected'); 381 var controlosToDelete = this.map.getControlsByClass("OpenLayers.Control.SelectFeature"); 382 for (var i = 0; controlosToDelete && i < controlosToDelete.length; i++) { 383 controlosToDelete[i].deactivate(); 384 this.map.removeControl(controlosToDelete[i]); 385 controlosToDelete[i].destroy(); 386 } 387 388 this.map.setLayerIndex(this.layerExtent, this.map.layers.length - 1); 389 this.map.boundRicerca = polygon; 390 391 this.map.zoomToExtent(polygon.getBounds()); 392 //this.map.setCenter(geometry.getBounds().getCenterLonLat(),this.map.getZoom()); 393 394 this.map.setCenter(polygon.getCentroid(), this.map.getZoom()); 395 396 var style = OpenLayers.Util.extend({ 397 cursor: "inherit", 398 fillColor: '#ee9900', 399 fillOpacity: 0.4, 400 strokeColor: "#ee9900", 401 strokeDashstyle: "solid", 402 strokeLinecap: "round", 403 strokeOpacity: 1, 404 strokeWidth: 1 405 }, OpenLayers.Feature.Vector.style['custom']); 406 407 var feature = new OpenLayers.Feature.Vector(polygon, null, style); 408 this.layerExtent.addFeatures(feature); 409 this.fireEvent('drawn'); 410 }, 411 /** 412 * Reset search form 413 * @private 414 */ 415 reset: function () { 416 this.comboComuni.setValue(''); 417 this.txtFoglio.setValue(''); 418 this.txtNumero.setValue(''); 419 this.txtSezione.setValue(''); 420 } 421 }); 422 423 /** api: xtype = framework_catastosearchpanel */ 424 Ext.reg("framework_catastosearchpanel", framework.widgets.CatastoSearchPanel);