~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/MousePosition.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.MousePosition
 
12
 *
 
13
 * Inherits from:
 
14
 *  - <OpenLayers.Control>
 
15
 */
 
16
OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
 
17
    
 
18
    /** 
 
19
     * Property: element
 
20
     * {DOMElement} 
 
21
     */
 
22
    element: null,
 
23
    
 
24
    /** 
 
25
     * APIProperty: prefix
 
26
     * {String}
 
27
     */
 
28
    prefix: '',
 
29
    
 
30
    /** 
 
31
     * APIProperty: separator
 
32
     * {String}
 
33
     */
 
34
    separator: ', ',
 
35
    
 
36
    /** 
 
37
     * APIProperty: suffix
 
38
     * {String}
 
39
     */
 
40
    suffix: '',
 
41
    
 
42
    /** 
 
43
     * APIProperty: numDigits
 
44
     * {Integer}
 
45
     */
 
46
    numDigits: 5,
 
47
    
 
48
    /** 
 
49
     * APIProperty: granularity
 
50
     * {Integer} 
 
51
     */
 
52
    granularity: 10,
 
53
    
 
54
    /** 
 
55
     * Property: lastXy
 
56
     * {<OpenLayers.LonLat>}
 
57
     */
 
58
    lastXy: null,
 
59
 
 
60
    /**
 
61
     * APIProperty: displayProjection
 
62
     * {<OpenLayers.Projection>} A projection that the 
 
63
     * mousecontrol will display.
 
64
     */
 
65
    displayProjection: null, 
 
66
    
 
67
    /**
 
68
     * Constructor: OpenLayers.Control.MousePosition
 
69
     * 
 
70
     * Parameters:
 
71
     * options - {DOMElement} Options for control.
 
72
     */
 
73
    initialize: function(options) {
 
74
        OpenLayers.Control.prototype.initialize.apply(this, arguments);
 
75
    },
 
76
 
 
77
    /**
 
78
     * Method: destroy
 
79
     */
 
80
     destroy: function() {
 
81
         if (this.map) {
 
82
             this.map.events.unregister('mousemove', this, this.redraw);
 
83
         }
 
84
         OpenLayers.Control.prototype.destroy.apply(this, arguments);
 
85
     },
 
86
 
 
87
    /**
 
88
     * Method: draw
 
89
     * {DOMElement}
 
90
     */    
 
91
    draw: function() {
 
92
        OpenLayers.Control.prototype.draw.apply(this, arguments);
 
93
 
 
94
        if (!this.element) {
 
95
            this.div.left = "";
 
96
            this.div.top = "";
 
97
            this.element = this.div;
 
98
        }
 
99
        
 
100
        this.redraw();
 
101
        return this.div;
 
102
    },
 
103
   
 
104
    /**
 
105
     * Method: redraw  
 
106
     */
 
107
    redraw: function(evt) {
 
108
 
 
109
        var lonLat;
 
110
 
 
111
        if (evt == null) {
 
112
            lonLat = new OpenLayers.LonLat(0, 0);
 
113
        } else {
 
114
            if (this.lastXy == null ||
 
115
                Math.abs(evt.xy.x - this.lastXy.x) > this.granularity ||
 
116
                Math.abs(evt.xy.y - this.lastXy.y) > this.granularity)
 
117
            {
 
118
                this.lastXy = evt.xy;
 
119
                return;
 
120
            }
 
121
 
 
122
            lonLat = this.map.getLonLatFromPixel(evt.xy);
 
123
            if (!lonLat) { 
 
124
                // map has not yet been properly initialized
 
125
                return;
 
126
            }    
 
127
            if (this.displayProjection) {
 
128
                lonLat.transform(this.map.getProjectionObject(), 
 
129
                                 this.displayProjection );
 
130
            }      
 
131
            this.lastXy = evt.xy;
 
132
            
 
133
        }
 
134
        
 
135
        var newHtml = this.formatOutput(lonLat);
 
136
 
 
137
        if (newHtml != this.element.innerHTML) {
 
138
            this.element.innerHTML = newHtml;
 
139
        }
 
140
    },
 
141
 
 
142
    /**
 
143
     * Method: formatOutput
 
144
     * Override to provide custom display output
 
145
     *
 
146
     * Parameters:
 
147
     * lonLat - {<OpenLayers.LonLat>} Location to display
 
148
     */
 
149
    formatOutput: function(lonLat) {
 
150
        var digits = parseInt(this.numDigits);
 
151
        var newHtml =
 
152
            this.prefix +
 
153
            lonLat.lon.toFixed(digits) +
 
154
            this.separator + 
 
155
            lonLat.lat.toFixed(digits) +
 
156
            this.suffix;
 
157
        return newHtml;
 
158
     },
 
159
 
 
160
    /** 
 
161
     * Method: setMap
 
162
     */
 
163
    setMap: function() {
 
164
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
 
165
        this.map.events.register( 'mousemove', this, this.redraw);
 
166
    },     
 
167
 
 
168
    CLASS_NAME: "OpenLayers.Control.MousePosition"
 
169
});