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
12
* The MousePosition control displays geographic coordinates of the mouse
13
* pointer, as it is moved about the map.
16
* - <OpenLayers.Control>
18
OpenLayers.Control.MGRSMousePosition = OpenLayers.Class(OpenLayers.Control, {
33
* APIProperty: separator
45
* APIProperty: numDigits
51
* APIProperty: granularity
58
* {<OpenLayers.Pixel>}
63
* APIProperty: displayProjection
64
* {<OpenLayers.Projection>} The projection in which the
65
* mouse position is displayed
67
displayProjection: null,
70
* Constructor: OpenLayers.Control.MousePosition
73
* options - {Object} Options for control.
75
initialize: function(options) {
76
OpenLayers.Control.prototype.initialize.apply(this, arguments);
84
this.map.events.unregister('mousemove', this, this.redraw);
86
OpenLayers.Control.prototype.destroy.apply(this, arguments);
94
OpenLayers.Control.prototype.draw.apply(this, arguments);
99
this.element = this.div;
109
redraw: function(evt) {
114
lonLat = new OpenLayers.LonLat(0, 0);
116
if (this.lastXy == null ||
117
Math.abs(evt.xy.x - this.lastXy.x) > this.granularity ||
118
Math.abs(evt.xy.y - this.lastXy.y) > this.granularity)
120
this.lastXy = evt.xy;
124
lonLat = this.map.getLonLatFromPixel(evt.xy);
126
// map has not yet been properly initialized
129
if (this.displayProjection) {
130
lonLat.transform(this.map.getProjectionObject(),
131
this.displayProjection );
133
this.lastXy = evt.xy;
137
var newHtml = this.formatOutput(lonLat);
139
if (newHtml != this.element.innerHTML) {
140
this.element.innerHTML = newHtml;
145
* Method: formatOutput
146
* Override to provide custom display output
149
* lonLat - {<OpenLayers.LonLat>} Location to display
151
formatOutput: function(lonLat) {
152
var inches=OpenLayers.INCHES_PER_UNIT;
153
var metersPerPixel = this.map.getResolution()*(inches[this.map.getUnits()]*(1/inches['m']));
154
var mgdigits = parseInt(6-Math.ceil(Math.log(metersPerPixel)/2.302585092994046));
155
var digits = parseInt(this.numDigits);
156
var mgrs = new USNG2();
157
if ((lonLat.lat > -80) && (lonLat.lat < 80)) {
158
var mgrsStr = mgrs.fromLonLat(lonLat, mgdigits-1);
160
var mgrsStr = 'undefined';
164
lonLat.lon.toFixed(digits) +
166
lonLat.lat.toFixed(digits) +
167
" / MGRS: " + mgrsStr +
176
OpenLayers.Control.prototype.setMap.apply(this, arguments);
177
this.map.events.register( 'mousemove', this, this.redraw);
180
CLASS_NAME: "OpenLayers.Control.MousePosition"