~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to gis/dhis-gis-geostat/mfbase/openlayers/lib/OpenLayers/Control/Attribution.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * Add attribution from layers to the map display. Uses 'attribution' property
 
12
 * 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
});