]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Control/Attribution.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Control / Attribution.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5 /**
6  * @requires OpenLayers/Control.js
7  */
8
9 /**
10  * Class: OpenLayers.Control.Attribution
11  * The attribution control adds attribution from layers to the map display. 
12  * It uses 'attribution' property of each layer.
13  *
14  * Inherits from:
15  *  - <OpenLayers.Control>
16  */
17 OpenLayers.Control.Attribution = 
18   OpenLayers.Class(OpenLayers.Control, {
19     
20     /**
21      * APIProperty: seperator
22      * {String} String used to seperate layers.
23      */
24     separator: ", ",
25        
26     /**
27      * Constructor: OpenLayers.Control.Attribution 
28      * 
29      * Parameters:
30      * options - {Object} Options for control.
31      */
32     initialize: function(options) {
33         OpenLayers.Control.prototype.initialize.apply(this, arguments);
34     },
35
36     /** 
37      * Method: destroy
38      * Destroy control.
39      */
40     destroy: function() {
41         this.map.events.un({
42             "removelayer": this.updateAttribution,
43             "addlayer": this.updateAttribution,
44             "changelayer": this.updateAttribution,
45             "changebaselayer": this.updateAttribution,
46             scope: this
47         });
48         
49         OpenLayers.Control.prototype.destroy.apply(this, arguments);
50     },    
51     
52     /**
53      * Method: draw
54      * Initialize control.
55      * 
56      * Returns: 
57      * {DOMElement} A reference to the DIV DOMElement containing the control
58      */    
59     draw: function() {
60         OpenLayers.Control.prototype.draw.apply(this, arguments);
61         
62         this.map.events.on({
63             'changebaselayer': this.updateAttribution,
64             'changelayer': this.updateAttribution,
65             'addlayer': this.updateAttribution,
66             'removelayer': this.updateAttribution,
67             scope: this
68         });
69         this.updateAttribution();
70         
71         return this.div;    
72     },
73
74     /**
75      * Method: updateAttribution
76      * Update attribution string.
77      */
78     updateAttribution: function() {
79         var attributions = [];
80         if (this.map && this.map.layers) {
81             for(var i=0, len=this.map.layers.length; i<len; i++) {
82                 var layer = this.map.layers[i];
83                 if (layer.attribution && layer.getVisibility()) {
84                     attributions.push( layer.attribution );
85                 }
86             }  
87             this.div.innerHTML = attributions.join(this.separator);
88         }
89     },
90
91     CLASS_NAME: "OpenLayers.Control.Attribution"
92 });