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 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program. If not, see <http://www.gnu.org/licenses/>. 23 */ 24 25 /** 26 * @namespace framework.data 27 */ 28 Ext.namespace("framework.data"); 29 30 /** 31 * XSL reader for Inviluppi Immagini service of Regione Sardegna 32 * @name_ EnvelopesAerialPhotos_XLSReader 33 * @class XSL reader for toponimi search service of Regione Sardegna 34 * @extends Ext.data.XmlReader - See <a href="http://dev.sencha.com/deploy/ext-3.3.1/docs?class=Ext.data.XmlReader">Ext.data.XmlReader</a> 35 * @constructor 36 * @param {object} meta object configuration 37 * @param {Ext.data.Record} recordType object definition 38 */ 39 framework.data.EnvelopesAerialPhotos_XLSReader = function(meta, recordType) { 40 meta = meta || {}; 41 42 43 Ext.applyIf(meta, { 44 idProperty: meta.idProperty || meta.idPath || meta.id, 45 successProperty: meta.successProperty || meta.success 46 }); 47 48 framework.data.EnvelopesAerialPhotos_XLSReader.superclass.constructor.call(this, meta, recordType || meta.fields); 49 }; 50 51 Ext.extend(framework.data.EnvelopesAerialPhotos_XLSReader, Ext.data.XmlReader, 52 /** 53 * @lends framework.data.EnvelopesAerialPhotos_XLSReader.prototype 54 */ 55 { 56 57 /** This method is only used by a DataProxy which has retrieved data from a remote server. 58 * Create responseXML if the responseText is a XML format 59 * @public 60 * @param {Object} response The XHR object which contains the parsed XML document. 61 * The response is expected to contain a method called 'responseXML' that returns an XML document object. 62 * @returns {Object} records A data block which is used by an {@link Ext.data.Store} as 63 * a cache of Ext.data.Records. 64 */ 65 read : function(response){ 66 if(!response.responseXML){ 67 var text = response.responseText; 68 try { // code for IE 69 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); 70 xmlDoc.async = "false"; 71 xmlDoc.loadXML(text); 72 response.responseXML = xmlDoc; 73 }catch(error) { // code for Mozilla, Firefox, Opera, etc. 74 try { 75 var parser = new DOMParser(); 76 var xmlDoc = parser.parseFromString(text,"text/xml"); 77 response.responseXML = xmlDoc; 78 }catch(error) { 79 alert(error.message); 80 return; 81 } 82 } 83 } 84 var doc = response.responseXML; 85 if(!doc) { 86 throw {message: "XmlReader.read: XML Document not available"}; 87 } 88 return this.readRecords(doc); 89 }, 90 91 92 /** fill up a object with query result 93 * @public 94 * @param {string} doc xml document 95 * @returns {object} array of record plus search informations 96 */ 97 readRecords: function(doc) { 98 99 this.xmlData = doc; 100 101 var root = doc.documentElement || doc; 102 103 var records = this.extractData(root); 104 105 return { 106 success: true, 107 records: records, 108 totalRecords: records[0].data.numresult 109 }; 110 }, 111 112 /** create array of record extracting data from a xml 113 * @public create records from xml content 114 * @param {string} root xml document 115 * @returns {array} record 116 */ 117 extractData: function(root) { 118 var opts = { 119 /** 120 * Property: namespaces 121 * {Object} Mapping of namespace aliases to namespace URIs. 122 */ 123 namespaces: { 124 gml: "http://www.opengis.net/gml", 125 wfs:"http://www.opengis.net/wfs" 126 127 } 128 }; 129 var records = []; 130 var recordType = Ext.data.Record.create(["source","visibility","name","shape","strisciata","fotogramma","typeImg","group","subGroup","title","layername","tmsUrl","opacity","fixed","selected"]); 131 //empty record for switch off layers 132 records.push(new recordType({source:'',visibility:'',name:'none',shape:'',strisciata:'',fotogramma:'',typeImg:'',group:'',"subGroup":'',title:'Immagini...',layername:'Immagini...', tmsUrl:'',opacity:'',fixed:'',selected:false },0)); 133 var format = new OpenLayers.Format.XML(opts); 134 var images = format.getElementsByTagNameNS(root, "http://www.regione.sardegna.it/", 'NOME'); 135 136 var mappingVoli = this.meta.mapVoli; 137 var inseriti = {}; 138 Ext.each(images, function(point, index) { 139 var nome = format.getChildValue(point); 140 if(inseriti[nome]!= ''){ 141 inseriti[nome] = ''; 142 var values = mappingVoli[nome]; 143 if(values){ 144 var record = new recordType(values, records.length); 145 records.push(record); 146 } 147 } 148 }) 149 return records; 150 } 151 }); 152 153