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 var __attributionMap = new Object(); 16 17 /** 18 * Provides a control to add attribution data that is also clickable 19 * @name_ ClickableAttribution 20 * @class ClickableAttribution 21 * @constructor 22 * @extends <a target="_blank" href="http://gxp.opengeo.org/master/doc/lib/plugins/Tool.html">gxp.plugins.Tool</a> 23 */ 24 framework.plugins.ClickableAttribution = Ext.extend(gxp.plugins.Tool, 25 /** 26 * @lends framework.plugins.ClickableAttribution.prototype 27 */ 28 { 29 /** 30 * @cfg {OpenLayers.Layer} layer 31 * The {@link OpenLayers.Layer} to bind this ClickableAttribution to. 32 */ 33 /** 34 * @cfg {String} text 35 * The text to show as attribution data 36 */ 37 /** 38 * @cfg {String} params 39 * Additional parameters to send to click event 40 */ 41 /** 42 * plugin type. 43 * @public 44 * @type String 45 */ 46 ptype: "framework_clickableattribution", 47 /** 48 * Text to show in attribution 49 * @private 50 * @type String 51 */ 52 _text: null, 53 /** 54 * Layer associated to this attribution 55 * @private 56 * @type OpenLayers.Layer 57 */ 58 _layer: null, 59 /** 60 * Additional parameters to send to event 61 * @private 62 * @type Object 63 */ 64 _additionalParameters: null, 65 /** 66 * @private 67 * @param {Object} config configuration. 68 */ 69 constructor: function(config) { 70 this._layer = config.layer; 71 this._text = config.text; 72 this._additionalParameters = config.params; 73 __attributionMap[this._layer.id] = this; 74 //now we will build the clickable object 75 this._layer.attribution = this.encapsulate(); 76 this.addEvents('click'); 77 78 // Copy configured listeners into *this* object so 79 // that the base class's constructor will add them. 80 this.listeners = config.listeners; 81 82 // Call our superclass constructor to complete 83 // construction process. 84 framework.plugins.ClickableAttribution.superclass.constructor.apply(this, arguments); 85 }, 86 /** 87 * Encapsulates attribution text with html to manage click event 88 * @private 89 * @param {String} text attribution text 90 * @return {String} text encapsulated with event calling 91 */ 92 encapsulate: function() { 93 var ris = '<i><span style="cursor: pointer;" onclick="'; 94 ris += "__attributionOnClick('" + this._layer.id + "'"; 95 if (Ext.isDefined(this._additionalParameters)) { 96 var sParam = Ext.util.JSON.encode(this._additionalParameters); 97 sParam = sParam.replace(/"/g, "\\'"); 98 ris += ", '" + sParam +"'"; 99 } 100 ris += ');">' + this._text + '</span></i>'; 101 return ris; 102 } 103 104 }); 105 106 Ext.preg(framework.plugins.ClickableAttribution.prototype.ptype, framework.plugins.ClickableAttribution); 107 108 /** 109 * Manage events for registered objects 110 * @param {int} layerId layer used to identify attribution control to call 111 * @param {Object} parameters parameters to send to event manager 112 * @private 113 */ 114 function __attributionOnClick(layerId, parameters) { 115 var clickableAtt = __attributionMap[layerId]; 116 if (Ext.isDefined(clickableAtt)) { 117 //send event 118 clickableAtt.fireEvent('click', clickableAtt._layer, Ext.util.JSON.decode(parameters)); 119 } 120 }