~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/Scale.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
/**
 
7
 * @requires OpenLayers/Control.js
 
8
 */
 
9
 
 
10
/**
 
11
 * Class: OpenLayers.Control.Scale
 
12
 * Display a small scale indicator on the map.
 
13
 *
 
14
 * Inherits from:
 
15
 *  - <OpenLayers.Control>
 
16
 */
 
17
OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, {
 
18
    
 
19
    /**
 
20
     * Parameter: element
 
21
     * {DOMElement}
 
22
     */
 
23
    element: null,
 
24
    
 
25
    /**
 
26
     * Constructor: OpenLayers.Control.Scale
 
27
     * 
 
28
     * Parameters:
 
29
     * element - {DOMElement} 
 
30
     * options - {Object} 
 
31
     */
 
32
    initialize: function(element, options) {
 
33
        OpenLayers.Control.prototype.initialize.apply(this, [options]);
 
34
        this.element = OpenLayers.Util.getElement(element);        
 
35
    },
 
36
 
 
37
    /**
 
38
     * Method: draw
 
39
     * 
 
40
     * Returns:
 
41
     * {DOMElement}
 
42
     */    
 
43
    draw: function() {
 
44
        OpenLayers.Control.prototype.draw.apply(this, arguments);
 
45
        if (!this.element) {
 
46
            this.element = document.createElement("div");
 
47
            this.div.appendChild(this.element);
 
48
        }
 
49
        this.map.events.register( 'moveend', this, this.updateScale);
 
50
        this.updateScale();
 
51
        return this.div;
 
52
    },
 
53
   
 
54
    /**
 
55
     * Method: updateScale
 
56
     */
 
57
    updateScale: function() {
 
58
        var scale = this.map.getScale();
 
59
        if (!scale) {
 
60
            return;
 
61
        }
 
62
 
 
63
        if (scale >= 9500 && scale <= 950000) {
 
64
            scale = Math.round(scale / 1000) + "K";
 
65
        } else if (scale >= 950000) {
 
66
            scale = Math.round(scale / 1000000) + "M";
 
67
        } else {
 
68
            scale = Math.round(scale);
 
69
        }    
 
70
        
 
71
        this.element.innerHTML = OpenLayers.i18n("scale", {'scaleDenom':scale});
 
72
    }, 
 
73
 
 
74
    CLASS_NAME: "OpenLayers.Control.Scale"
 
75
});
 
76