Jeff Dege contributed a MousePosition Control, which this commit adds to trunk.

Reviewed by Erik on Trac and in person. 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@1665 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2006-10-06 19:20:23 +00:00
parent 185fd44437
commit 4aef16e1bd
7 changed files with 150 additions and 1 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
rm ../doc/reference.html rm ../doc/reference.html
CLASSES="Map Layer Layer.HTTPRequest Layer.Grid Layer.WMS Layer.KaMap Layer.EventPane Layer.Google Layer.VirtualEarth Layer.Markers Layer.Text Layer.GeoRSS Layer.Boxes Icon Marker Marker.Box Tile Tile.Image Tile.WFS Control Control.LayerSwitcher Control.MouseDefaults Control.MouseToolbar Control.PanZoom Control.PanZoomBar Control.Permalink Control.Scale LonLat Size Pixel Bounds Util" CLASSES="Map Layer Layer.HTTPRequest Layer.Grid Layer.WMS Layer.KaMap Layer.EventPane Layer.Google Layer.VirtualEarth Layer.Markers Layer.Text Layer.GeoRSS Layer.Boxes Icon Marker Marker.Box Tile Tile.Image Tile.WFS Control Control.LayerSwitcher Control.MouseDefaults Control.MousePosition Control.MouseToolbar Control.PanZoom Control.PanZoomBar Control.Permalink Control.Scale LonLat Size Pixel Bounds Util"
echo "<html> echo "<html>
<head> <head>
<title>OpenLayers Class Reference Documentation</title> <title>OpenLayers Class Reference Documentation</title>

View File

@@ -0,0 +1,32 @@
OpenLayers.Control.MousePosition
A small control which displays the Longitude and Latitude of the current mouse position, by defualt in the lower right of the map viewport.
* Constructor
OpenLayers.Control.MousePosition({Object|options}) -- Creates a new MousePosition control.
* Parameters
element -- if not null, div in which to display the MousePosition
prefix -- html to precede the longitude value (default: '')
separator -- html to separate the longitude and latitude values (default: '<br />')
suffix -- html to follow the latitude value (default: '')
numdigits -- number of digits to the right of the decimal (default: 5)
granularity -- a change of how many pixels is considered a mouse move (default: 1)
prefix, separator, and suffix are used to format the lon/lat values.
With:
prefix = 'Lon:&nbsp;'
suffix = '<br />Lat:&nbsp;'
suffix = ''
nudigits = 3
Lon/Lat is displayed as:
Lon: 95.123
Lat: 35.456
If the mouse has never been over the map, Lon/Lat will equal 0/0. If the mouse is over the map, Lon/Lat will equal the current mouse position. If the mouse has been moved off the map, Lon/Lat will equal the value displayed at the time the mouse was moved off the map.
If the mouse is moving slowly, the Lon/Lat will refresh continuously. If the mouse is moving rapidly, the refresh of Lon/Lat will be suspended until the mouse has slowed down or stopped. (Trying to update the Lon/Lat value while the mouse is in rapid movemement makes the movement of the mouse unacceptably jerky.)

View File

@@ -10,6 +10,7 @@ Patch contributors
------------------ ------------------
Corey Puffault Corey Puffault
Tim Schaub Tim Schaub
Jeff Dege
OpenLayers is graciously supported by MetaCarta, Inc. OpenLayers is graciously supported by MetaCarta, Inc.
<http://www.metacarta.com>. <http://www.metacarta.com>.

View File

@@ -18,6 +18,7 @@
map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false})); map.addControl(new OpenLayers.Control.LayerSwitcher({'ascending':false}));
map.addControl(new OpenLayers.Control.Permalink()); map.addControl(new OpenLayers.Control.Permalink());
map.addControl(new OpenLayers.Control.Permalink($('permalink'))); map.addControl(new OpenLayers.Control.Permalink($('permalink')));
map.addControl(new OpenLayers.Control.MousePosition());
var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS", var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
"http://labs.metacarta.com/wms/vmap0", "http://labs.metacarta.com/wms/vmap0",
{layers: 'basic'} ); {layers: 'basic'} );

View File

@@ -89,6 +89,7 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
"OpenLayers/Control.js", "OpenLayers/Control.js",
"OpenLayers/Control/MouseDefaults.js", "OpenLayers/Control/MouseDefaults.js",
"OpenLayers/Control/MouseToolbar.js", "OpenLayers/Control/MouseToolbar.js",
"OpenLayers/Control/MousePosition.js",
"OpenLayers/Control/KeyboardDefaults.js", "OpenLayers/Control/KeyboardDefaults.js",
"OpenLayers/Control/PanZoom.js", "OpenLayers/Control/PanZoom.js",
"OpenLayers/Control/PanZoomBar.js", "OpenLayers/Control/PanZoomBar.js",

View File

@@ -0,0 +1,106 @@
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
* See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
* text of the license. */
/**
* @class
*
* @requires OpenLayers/Control.js
*/
OpenLayers.Control.MousePosition = OpenLayers.Class.create();
OpenLayers.Control.MousePosition.prototype =
OpenLayers.Class.inherit( OpenLayers.Control, {
/** @type DOMElement */
element: null,
/** @type String */
prefix: '',
/** @type String */
separator: ', ',
/** @type String */
suffix: '',
/** @type int */
numdigits: 5,
/** @type int */
granularity: 1,
/** @type OpenLayers.LonLat */
lastXy: null,
/**
* @constructor
*
* @param {DOMElement} options Options for control.
*/
initialize: function(options) {
OpenLayers.Control.prototype.initialize.apply(this, arguments);
},
/**
* @type DOMElement
*/
draw: function() {
OpenLayers.Control.prototype.draw.apply(this, arguments);
if (!this.element) {
this.div.left = "";
this.div.top = "";
this.div.className = "olControlMousePosition";
this.element = this.div;
}
this.redraw();
return this.div;
},
/**
*
*/
redraw: function(evt) {
var lonLat;
if (evt == null) {
lonLat = new OpenLayers.LonLat(0, 0);
} else {
if (this.lastXy == null ||
Math.abs(evt.xy.x - this.lastXy.x) > this.granularity ||
Math.abs(evt.xy.y - this.lastXy.y) > this.granularity)
{
this.lastXy = evt.xy;
return;
}
lonLat = this.map.getLonLatFromPixel(evt.xy);
this.lastXy = evt.xy;
}
var digits = parseInt(this.numdigits);
var newHtml =
this.prefix +
lonLat.lon.toFixed(digits) +
this.separator +
lonLat.lat.toFixed(digits) +
this.suffix;
if (newHtml != this.element.innerHTML) {
this.element.innerHTML = newHtml;
}
},
/**
*
*/
setMap: function() {
OpenLayers.Control.prototype.draw.apply(this, arguments);
this.map.events.register( 'mousemove', this, this.mousemove);
},
/** @final @type String */
CLASS_NAME: "OpenLayers.Control.MousePosition"
});

View File

@@ -18,3 +18,11 @@
left: 2px; left: 2px;
bottom: 15px; bottom: 15px;
} }
div.olControlMousePosition {
bottom: 0em;
right: 3px;
display: block;
position: absolute;
font-family: Arial;
font-size: smaller;
}