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.plugins 12 */ 13 Ext.namespace("framework.plugins"); 14 15 /** 16 * Plugin for removing a selected layer from the map. 17 * TODO Make this plural - selected layers 18 * @name_ RASAddLayers 19 * @class Plugin for removing a selected layer from the map. 20 * @constructor 21 * @extends <a target="_blank" href="http://gxp.opengeo.org/master/doc/lib/plugins/AddLayers.html">gxp.plugins.AddLayers</a> 22 */ 23 framework.plugins.RASAddLayers = Ext.extend(gxp.plugins.AddLayers, 24 /** 25 * @lends framework.plugins.RASAddLayers.prototype 26 */ 27 { 28 /** 29 * framework_rasaddlayers plugin type. 30 * @public 31 * @type String 32 */ 33 ptype: "framework_rasaddlayers", 34 35 /** Create the object with events 36 * @public 37 * @param {Object} config object configuration 38 */ 39 constructor: function(config) { 40 this.addEvents( 41 /** api: event[sourceselected] 42 * Fired when a new source is selected. 43 * 44 * Listener arguments: 45 * 46 * * tool - :class:`framework.plugins.RASAddLayers` This tool. 47 * * source - :class:`gxp.plugins.LayerSource` The selected source. 48 */ 49 "sourceselected", 50 "externalclick" 51 ); 52 this.addListener("externalclick",this.showCapabilitiesGrid); 53 framework.plugins.RASAddLayers.superclass.constructor.apply(this, arguments); 54 }, 55 56 /** Add layers to the map 57 * @public 58 * @param {Array} records the layer records to add 59 * @param {boolean} isUpload Do the layers to add come from an upload? 60 */ 61 addLayers: function(records, isUpload) { 62 var source = this.selectedSource; 63 var layerStore = this.target.mapPanel.layers, 64 extent, record, layer; 65 for (var i=0, ii=records.length; i<ii; ++i) { 66 // If the source is lazy, then createLayerRecord will not return 67 // a record, and we take the preconfigured record. 68 record = source.createLayerRecord({ 69 name: records[i].get("name"), 70 source: source.id 71 }) || records[i]; 72 if (record) { 73 layer = record.getLayer(); 74 if (layer.maxExtent) { 75 if (!extent) { 76 extent = record.getLayer().maxExtent.clone(); 77 } else { 78 extent.extend(record.getLayer().maxExtent); 79 } 80 } 81 if (record.get("group") === "background") { 82 // layer index 0 is the invisible base layer, so we insert 83 // at position 1. 84 layerStore.insert(1, [record]); 85 86 //IMPOSTAZIONE SFONDO LAYER DI BASE 87 var container = Ext.get(record.data.layer.map.getViewport()); 88 if (record.data.layer.background) 89 container.setStyle('background-color', record.data.layer.background); 90 else 91 container.setStyle('background-color', "FFFFFF"); 92 93 } else { 94 layerStore.add([record]); 95 } 96 } 97 } 98 // if (extent) { 99 // //enable automatic layer zoom extent 100 // //this.target.mapPanel.map.zoomToExtent(extent); 101 // } 102 if (records.length === 1 && record) { 103 // select the added layer 104 this.target.selectLayer(record); 105 if (isUpload && this.postUploadAction) { 106 // show LayerProperties dialog if just one layer was uploaded 107 var outputConfig, 108 actionPlugin = this.postUploadAction; 109 if (!Ext.isString(actionPlugin)) { 110 outputConfig = actionPlugin.outputConfig; 111 actionPlugin = actionPlugin.plugin; 112 } 113 this.target.tools[actionPlugin].addOutput(outputConfig); 114 } 115 } 116 } 117 118 }); 119 120 Ext.preg(framework.plugins.RASAddLayers.prototype.ptype, framework.plugins.RASAddLayers); 121