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.MousePosition = 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 digits = parseInt(this.numDigits);
155 lonLat.lon.toFixed(digits) +
157 lonLat.lat.toFixed(digits) +
166 OpenLayers.Control.prototype.setMap.apply(this, arguments);
167 this.map.events.register( 'mousemove', this, this.redraw);
170 CLASS_NAME: "OpenLayers.Control.MousePosition"