1 /*************************************** 2 * Copyright 2011, 2012 GlobWeb contributors. 3 * 4 * This file is part of GlobWeb. 5 * 6 * GlobWeb is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Lesser General Public License as published by 8 * the Free Software Foundation, version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * GlobWeb is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with GlobWeb. If not, see <http://www.gnu.org/licenses/>. 18 ***************************************/ 19 20 define( function() { 21 22 /**************************************************************************************************************/ 23 24 /** 25 * @class Manage the attributions 26 @constructor 27 Function constructor for AttributionHandler 28 29 @param globe 30 @param options Configuration properties 31 <ul> 32 <li>element : the HTML element to show attributions, can be a string (the ID) or the DOM element itself</li> 33 </ul> 34 */ 35 36 var AttributionHandler = function(globe, options) 37 { 38 globe.attributionHandler = this; 39 40 var elt = options ? options['element'] : undefined; 41 if ( elt ) 42 { 43 if (typeof elt == "string") 44 { 45 this.element = document.getElementById(elt); 46 } 47 else 48 { 49 this.element = elt; 50 } 51 } 52 } 53 54 /**************************************************************************************************************/ 55 56 /** 57 * Remove attribution from HTML 58 * @param layer Selected layer 59 */ 60 AttributionHandler.prototype.removeAttribution = function( layer ) 61 { 62 var div = document.getElementById( "attribution_"+layer.id ); 63 if ( div ) 64 this.element.removeChild( div ); 65 } 66 67 /**************************************************************************************************************/ 68 69 /** 70 * Add attribution in HTML 71 * @param layer Selected layer 72 */ 73 AttributionHandler.prototype.addAttribution = function(layer) 74 { 75 var div = document.createElement('div'); 76 div.innerHTML = layer.attribution; 77 div.id = "attribution_"+layer.id; 78 79 if(layer.id == 0) 80 { 81 // Background layer 82 this.element.insertBefore( div, this.element.firstChild ); 83 } 84 else 85 { 86 this.element.appendChild( div ); 87 } 88 89 90 } 91 92 /**************************************************************************************************************/ 93 94 return AttributionHandler; 95 96 }); 97