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  * @requires plugins/LayerSource.js
 12  * @require framework/plugins/ClickableAttribution.js
 13  * @require framework/plugins/InfoMetaPopup.js
 14  */
 15 
 16 /**
 17  * @namespace framework.plugins
 18  */
 19 Ext.ns("framework.plugins");
 20 
 21 /** @example
 22  *  The configuration in the ``sources`` property of the :class:`gxp.Viewer` is
 23  *  straightforward:
 24  *
 25  *  .. code-block:: javascript
 26  *
 27  *    "ras": {
 28  *        ptype: "framework_rassource"
 29  *    }
 30  *
 31  *  A typical configuration for a layer from this source (in the ``layers``
 32  *  array of the viewer's ``map`` config option would look like this:
 33  *
 34  *  .. code-block:: javascript
 35  *
 36  *    {
 37  *        source: "ras",
 38  *        name: "RAS"
 39  *    }
 40  *
 41  */
 42 
 43 /** 
 44  * Plugin for using RAS TMS layers with :class:`gxp.Viewer` instances.
 45  * @name_ RASSource
 46  * @class Plugin for using service TMS for Regione Sardegna 
 47  * @constructor
 48  * @extends <a target="_blank" href="http://gxp.opengeo.org/master/doc/lib/plugins/LayerSource.html">gxp.plugins.LayerSource</a>
 49  */
 50 framework.plugins.RASSource = Ext.extend(gxp.plugins.LayerSource, 
 51 /** 
 52 * @lends framework.plugins.RASSource.prototype 
 53 */
 54 {
 55     /**
 56     * framework_rassource plugin type.
 57     * @public
 58     * @type String
 59     */
 60     ptype: "framework_rassource",
 61 
 62     /**
 63     * A descriptive title for this layer source (i18n).
 64     * @public
 65     * @type String
 66     */
 67     title: "RAS TMS Layers",
 68 
 69     /**
 70     * Attribution string for osmarender generated layer (i18n)
 71     * @public
 72     * @type String
 73     */
 74     rasAttribution: "Data CC-By-SA by <a href='http://www.regione.sardegna.it/' target='_blank'>Regione Sardegna</a>",
 75     
 76     /**
 77     * Url tms
 78     * Default tms Regione Sardegna: http://webgis.regione.sardegna.it/tms/
 79     * @public
 80     * @type String
 81     */
 82     urltms: "http://webgis.regione.sardegna.it/tms",
 83     
 84     
 85     storeNT: null,
 86     
 87     /** 
 88     * Creates a store of layer records.  Fires "ready" when store is loaded.
 89     * @public
 90     */  
 91     createStore: function() {
 92         
 93           var layersNT, optionsNT;
 94           var layers, options;    
 95         
 96           if (optionsNT_ex) {
 97               
 98               optionsNT = optionsNT_ex.slice();
 99               optionsNT.forEach(function(entry, index) {
100                   if (Array.isArray(entry.maxExtent)) {
101                     optionsNT[index].maxExtent = new OpenLayers.Bounds(entry.maxExtent[0],entry.maxExtent[1],entry.maxExtent[2],entry.maxExtent[3]);
102                     optionsNT[index].tileOrigin = new OpenLayers.LonLat(entry.tileOrigin[0],entry.tileOrigin[1]);
103                  }
104                });
105            
106              layersNT = layersNT_ex.slice();
107              
108               layersNT.forEach(function(entry, index) {
109                     layersNT[index] = new OpenLayers.Layer.TMS(entry[0],entry[1],entry[2]);
110               });
111               
112 
113               
114           }
115           else {
116         
117             optionsNT = new Array(
118             {
119                   layername: 'sfondo_ortofoto2008_EPSG3003',
120                   type: "png",
121                   resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
122                   background: "#FFFFFF",
123                   maxExtent: new OpenLayers.Bounds(1159976,4299800,1570920,4577800),
124                   tileOrigin: new OpenLayers.LonLat(1159976,4299800),
125                   attribution: 'Dati cartografici © Regione Autonoma Sardegna',
126                   candidateBaseLayer: false,
127                   displayInLayerSwitcher: false,
128                   serviceVersion: '',
129                   overview: 'ortofoto2008_EPSG3003'
130               },
131               {
132                   layername: 'sfondo_ortofoto1943_EPSG3003',
133                   type: "png",
134                   resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
135                   background: "#FFFFFF",
136                   maxExtent: new OpenLayers.Bounds(1159976,4299800,1570920,4577800),
137                   tileOrigin: new OpenLayers.LonLat(1159976,4299800),
138                   attribution: 'Dati cartografici © Regione Autonoma Sardegna',
139                   candidateBaseLayer: false,
140                   displayInLayerSwitcher: false,
141                   serviceVersion: '',
142                   overview: 'ortofoto1943_EPSG3003'
143               }
144               );
145           
146             
147                 layersNT = [
148                     new OpenLayers.Layer.TMS(optionsNT[0].overview, this.urltms, optionsNT[0]),
149                     new OpenLayers.Layer.TMS(optionsNT[1].overview, this.urltms, optionsNT[1])
150                 ];
151         }
152         
153         
154         this.storeNT = new GeoExt.data.LayerStore({
155             layers: layersNT,
156             fields: [
157                 {name: "name", type: "string"},
158                 {name: "source", type: "string"},
159                 {name: "group", type: "string"},
160                 {name: "fixed", type: "boolean"},
161                 {name: "selected", type: "boolean"},
162                 {name: "type", type: "string"},
163                 {name: "args"}
164             ]
165         });
166         
167         if (options_ex) {
168               options = options_ex.slice();
169               
170               options.forEach(function(entry, index) {
171                   if (Array.isArray(entry.maxExtent)) {
172                     options[index].maxExtent = new OpenLayers.Bounds(entry.maxExtent[0],entry.maxExtent[1],entry.maxExtent[2],entry.maxExtent[3]);
173                     options[index].tileOrigin = new OpenLayers.LonLat(entry.tileOrigin[0],entry.tileOrigin[1]);
174                   }
175               });
176                   
177               layers = layers_ex.slice();
178               
179               layers.forEach(function(entry, index) {
180                     layers[index] = new OpenLayers.Layer.TMS(entry[0],entry[1],entry[2]);
181               });           
182               
183           }
184           else {
185 
186 
187                 options = new Array(
188                 {
189                     layername: 'stradario_EPSG3003',
190                     type: "png",
191                     background: "#4682B4",
192                     maxExtent: new OpenLayers.Bounds(1159976, 4299800, 1570920, 4577800),
193                     tileOrigin: new OpenLayers.LonLat(1159976, 4299800),
194                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
195                     candidateBaseLayer: true,
196                     //metadata: 'http://www.regione.sardegna.it/',
197                     serviceVersion: ''
198                 },
199                 {
200                     layername: 'stradtrasp_EPSG3003',
201                     type: "png",
202                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
203                     background: "#DCDFE9",
204                     maxExtent: new OpenLayers.Bounds(1159976, 4299800, 1570920, 4577800),
205                     tileOrigin: new OpenLayers.LonLat(1159976, 4299800),
206                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
207                     candidateBaseLayer: false,
208                     serviceVersion: ''
209                 },
210                 {
211                     layername: 'ortofoto2008_EPSG3003',
212                     type: "jpg",
213                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
214                     background: "#FFFFFF",
215                     maxExtent: new OpenLayers.Bounds(1425343.527, 4300509.945, 1570593.527, 4574254.445),
216                     tileOrigin: new OpenLayers.LonLat(1425343.527, 4300509.945),
217                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
218                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12716&idEnte=1',
219                     candidateBaseLayer: true,
220                     serviceVersion: ''
221                 },
222                 {
223                     layername: 'ortofoto2006_EPSG3003',
224                     type: "jpg",
225                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
226                     background: "#1c1f4c",
227                     maxExtent: new OpenLayers.Bounds(1422280.00, 4300042.99999999068677, 1570760.00, 4577639.99999999068677),
228                     tileOrigin: new OpenLayers.LonLat(1422280.00, 4300042.99999999068677),
229                     attribution: 'Dati cartografici © Terraitaly',
230                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12261&idEnte=1',
231                     candidateBaseLayer: true,
232                     serviceVersion: ''
233                 },
234                 {
235                     layername: 'ikonos2005_EPSG3003',
236                     type: "jpg",
237                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
238                     background: "#000000",
239                     maxExtent: new OpenLayers.Bounds(1426044.799, 4299991.199, 1571674.399, 4575017.599),
240                     tileOrigin: new OpenLayers.LonLat(1426044.799, 4299991.199),
241                     attribution: 'Dati cartografici © Planetek',
242                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12717&idEnte=1',
243                     candidateBaseLayer: true,
244                     serviceVersion: ''
245                 },
246                 {
247                     layername: 'ortofoto2003_EPSG3003',
248                     type: "png",
249                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
250                     background: "#000000",
251                     maxExtent: new OpenLayers.Bounds(1422120, 4299800, 1570920, 4577800),
252                     tileOrigin: new OpenLayers.LonLat(1422120, 4299800),
253                     attribution: 'Dati cartografici © AGEA',
254                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=11002&idEnte=1',
255                     candidateBaseLayer: true,
256                     serviceVersion: ''
257                 },
258                 {
259                     layername: 'ortofoto2000_EPSG3003',
260                     type: "jpg",
261                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
262                     background: "#1c1f4c",
263                     maxExtent: new OpenLayers.Bounds(1422279.15999999991618, 4299995.33000000007451, 1570756.15999999991618, 4577630.33000000007451),
264                     tileOrigin: new OpenLayers.LonLat(1422279.15999999991618, 4299995.33000000007451),
265                     attribution: 'Dati cartografici © Terraitaly',
266                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12731&idEnte=1',
267                     candidateBaseLayer: true,
268                     serviceVersion: ''
269                 },
270                 {
271                     layername: 'ortofoto1977_EPSG3003',
272                     type: "png",
273                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
274                     background: "#ffffff",
275                     maxExtent: new OpenLayers.Bounds(1422331.039, 4300026.71, 1570716.539, 4577589.21),
276                     tileOrigin: new OpenLayers.LonLat(1422331.039, 4300026.71),
277                     attribution: 'Dati cartografici © Terraitaly',
278                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12371&idEnte=1',
279                     candidateBaseLayer: true,
280                     serviceVersion: ''
281                 },
282                 {
283                     layername: 'ortofoto1954_EPSG3003',
284                     type: "png",
285                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
286                     background: "#232323",
287                     maxExtent: new OpenLayers.Bounds(1415120.5, 4279652.5, 1595120.5, 4578652.5),
288                     tileOrigin: new OpenLayers.LonLat(1415120.5, 4279652.5),
289                     attribution: 'Dati cartografici © Istituto Geografico Militare Italiano',
290                     metadata: 'http://www.sardegnageoportale.it/webgis/catalogodati/metadatiISO?idMetadato=12328&idEnte=1',
291                     candidateBaseLayer: true,
292                     serviceVersion: ''
293                 },
294                 {
295                     layername: 'ortofoto1943_EPSG3003',
296                     type: "png",
297                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
298                     background: "#FFFFFF",
299                     maxExtent: new OpenLayers.Bounds(1438813.25, 4293386.75, 1554810.25, 4577645.75),
300                     tileOrigin: new OpenLayers.LonLat(1438813.25, 4293386.75),
301                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
302                     candidateBaseLayer: true,
303                     serviceVersion: ''
304                 },
305                 {
306                     layername: 'sfondoRegioneLight_EPSG3003',
307                     type: "png",
308                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
309                     background: "#DCDFE9",
310                     maxExtent: new OpenLayers.Bounds(1159976, 4299800, 1570920, 4577800),
311                     tileOrigin: new OpenLayers.LonLat(1159976, 4299800),
312                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
313                     candidateBaseLayer: true,
314                     serviceVersion: ''
315                 },
316                 {
317                     layername: 'DTM10m_altimetria3003',
318                     type: "png",
319                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
320                     background: "#FFFFFF",
321                     maxExtent: new OpenLayers.Bounds(1425928.945,4300767.46,1570758.410,4573753.030),
322                     tileOrigin: new OpenLayers.LonLat(1425928.945,4300767.46),
323                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
324                     candidateBaseLayer: true,
325                     serviceVersion: ''
326                 },
327                 {
328                     layername: 'DTM10m_acclivita3003',
329                     type: "png",
330                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
331                     background: "#FFFFFF",
332                     maxExtent: new OpenLayers.Bounds(1426374.072,4301533.085,1571012.016,4574157.651),
333                     tileOrigin: new OpenLayers.LonLat(1426374.072,4301533.085),
334                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
335                     candidateBaseLayer: true,
336                     serviceVersion: ''
337                 },
338                 {
339                     layername: 'DTM10m_esposizione3003',
340                     type: "png",
341                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
342                     background: "#FFFFFF",
343                     maxExtent: new OpenLayers.Bounds(1426374.072,4301533.085,1571012.016,4574157.651),
344                     tileOrigin: new OpenLayers.LonLat(1426374.072,4301533.085),
345                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
346                     candidateBaseLayer: true,
347                     serviceVersion: ''
348                 },
349                 {
350                     layername: 'DTM10m_ombreggiatura3003',
351                     type: "png",
352                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1,0.5,0.25,0.125],
353                     background: "#FFFFFF",
354                     maxExtent: new OpenLayers.Bounds(1426374.072,4301533.085,1571012.016,4574157.651),
355                     tileOrigin: new OpenLayers.LonLat(1426374.072,4301533.085),
356                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
357                     candidateBaseLayer: true,
358                     serviceVersion: ''
359                 }
360                 /*,
361                 {
362                     layername: 'ppr2006_3003',
363                     type: "png",
364                     resolutions:[2048,1024,512,256,128,64,32,16,8,4,2,1],
365                     background: "#FFFFFF",
366                     maxExtent: new OpenLayers.Bounds(1414701.23698671930470, 4294342.54731805995107, 1571833.23698671930470, 4583282.54731805995107),
367                     tileOrigin: new OpenLayers.LonLat(1414701.23698671930470, 4294342.54731805995107),
368                     attribution: 'Dati cartografici © Regione Autonoma Sardegna',
369                     candidateBaseLayer: true,
370                     serviceVersion: ''
371                 }*/
372                 );
373 
374                 layers = [
375                     new OpenLayers.Layer.TMS('Stradario', this.urltms, options[0]),
376                     new OpenLayers.Layer.TMS('Stradario Trasparente', this.urltms, options[1]),
377                     new OpenLayers.Layer.TMS('Ortofoto 2008 costa', this.urltms, options[2]),
378                     new OpenLayers.Layer.TMS('Ortofoto 2006', this.urltms, options[3]),
379                     new OpenLayers.Layer.TMS('Satellitari 2005', this.urltms, options[4]),
380                     new OpenLayers.Layer.TMS('Ortofoto 2003', this.urltms, options[5]),
381                     new OpenLayers.Layer.TMS('Ortofoto 2000', this.urltms, options[6]),
382                     new OpenLayers.Layer.TMS('Ortofoto 1977', this.urltms, options[7]),
383                     new OpenLayers.Layer.TMS('Ortofoto 1954', this.urltms, options[8]),
384                     new OpenLayers.Layer.TMS('Ortofoto 1943', this.urltms, options[9]),
385                     new OpenLayers.Layer.TMS('Sfondo regione', this.urltms, options[10]),
386                     new OpenLayers.Layer.TMS('Altimetria (10m)', this.urltms, options[11]),
387                     new OpenLayers.Layer.TMS('Acclivita percentuale (10m)', this.urltms, options[12]),
388                     new OpenLayers.Layer.TMS('Esposizione (10m)', this.urltms, options[13]),
389                     new OpenLayers.Layer.TMS('Ombreggiatura (10m)', this.urltms, options[14])
390                     //new OpenLayers.Layer.TMS('Piano paesaggistico sardo', this.urltms, options[15])
391                 ];   
392         
393         }
394         
395         for (var i=0; i<options.length; i++) {
396           new framework.plugins.ClickableAttribution({
397             layer: layers[i],
398             params: options[i],
399             text: options[i].attribution,
400             listeners: {
401               click: function(layer, params) {
402                 var popup = new framework.plugins.InfoMetaPopup({
403                   titolo: layer.name,
404                   copyright: params.attribution,
405                   metadata: params.metadata,
406                   width: 240,
407                   height: 'auto'
408                 });
409                 popup.show();
410               }, scope: this
411             }
412           });
413         }
414         this.store = new GeoExt.data.LayerStore({
415             layers: layers,
416             fields: [
417                 {name: "name", type: "string"},
418                 {name: "source", type: "string"},
419                 {name: "group", type: "string"},
420                 {name: "fixed", type: "boolean"},
421                 {name: "selected", type: "boolean"},
422                 {name: "type", type: "string"},
423                 {name: "args"}
424             ]
425         });
426         this.store.each(function(l) {
427             l.set("group", "background");
428         });
429         this.fireEvent("ready", this);
430 
431     },
432     
433      /** Create a layer record given the config.
434     * @public
435     * @param {Object} config The application config for this layer
436     * @returns {GeoExt.data.LayerRecord} 
437     */  
438     createLayerRecord: function(config) {
439         var record;      
440         var index = this.store.findExact("name", config.name);
441         if (index > -1) {
442 
443             record = this.store.getAt(index).copy(Ext.data.Record.id({}));
444             var layer = record.getLayer().clone();
445 
446             // set layer title from config
447             if (config.title) {
448                 /**
449                  * Because the layer title data is duplicated, we have
450                  * to set it in both places.  After records have been
451                  * added to the store, the store handles this
452                  * synchronization.
453                  */
454                 layer.setName(config.title);
455                 record.set("title", config.title);
456             }
457 
458             // set visibility from config
459             if ("visibility" in config) {
460                 layer.visibility = config.visibility;
461             }
462 
463             record.set("selected", config.selected || false);
464             record.set("source", config.source);
465             record.set("name", config.name);
466             if ("group" in config) {
467                 record.set("group", config.group);
468             }
469 
470             record.data.layer = layer;
471             
472             var recordNT;
473             var indexNT = this.storeNT.findExact("name", record.data.layer.layername);
474             if (indexNT > -1) {
475                 recordNT = this.storeNT.getAt(indexNT).copy(Ext.data.Record.id({}));
476                 var layerNT = recordNT.getLayer().clone();
477                 record.data.layer.layerNT = layerNT;
478             }
479                 
480             record.commit();
481             
482         }
483         return record;
484     }
485 
486 });
487 
488 Ext.preg(framework.plugins.RASSource.prototype.ptype, framework.plugins.RASSource);
489