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. */
7
* @requires OpenLayers/Control.js
11
* Class: OpenLayers.Control.MousePosition
14
* - <OpenLayers.Control>
16
OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
31
* APIProperty: separator
43
* APIProperty: numDigits
49
* APIProperty: granularity
56
* {<OpenLayers.LonLat>}
61
* APIProperty: displayProjection
62
* {<OpenLayers.Projection>} A projection that the
63
* mousecontrol will display.
65
displayProjection: null,
68
* Constructor: OpenLayers.Control.MousePosition
71
* options - {DOMElement} Options for control.
73
initialize: function(options) {
74
OpenLayers.Control.prototype.initialize.apply(this, arguments);
82
this.map.events.unregister('mousemove', this, this.redraw);
84
OpenLayers.Control.prototype.destroy.apply(this, arguments);
92
OpenLayers.Control.prototype.draw.apply(this, arguments);
97
this.element = this.div;
107
redraw: function(evt) {
112
lonLat = new OpenLayers.LonLat(0, 0);
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)
118
this.lastXy = evt.xy;
122
lonLat = this.map.getLonLatFromPixel(evt.xy);
124
// map has not yet been properly initialized
127
if (this.displayProjection) {
128
lonLat.transform(this.map.getProjectionObject(),
129
this.displayProjection );
131
this.lastXy = evt.xy;
135
var newHtml = this.formatOutput(lonLat);
137
if (newHtml != this.element.innerHTML) {
138
this.element.innerHTML = newHtml;
143
* Method: formatOutput
144
* Override to provide custom display output
147
* lonLat - {<OpenLayers.LonLat>} Location to display
149
formatOutput: function(lonLat) {
150
var digits = parseInt(this.numDigits);
153
lonLat.lon.toFixed(digits) +
155
lonLat.lat.toFixed(digits) +
164
OpenLayers.Control.prototype.setMap.apply(this, arguments);
165
this.map.events.register( 'mousemove', this, this.redraw);
168
CLASS_NAME: "OpenLayers.Control.MousePosition"