* KML Examples broken (Closes #1001) * drag handler doesn't reset properties on left or improperly modified mousedown (Closes #1003) * Text nodes limited to 4096 in length (Closes #1006) * KML/GML Attribute CDATA Parsing (Closes #1007) * Control.MousePosition (Closes #1008) git-svn-id: http://svn.openlayers.org/branches/openlayers/2.5@4432 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
137 lines
3.0 KiB
JavaScript
137 lines
3.0 KiB
JavaScript
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under a modified BSD license.
|
|
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
|
* for the full text of the license. */
|
|
|
|
|
|
/**
|
|
* @requires OpenLayers/Control.js
|
|
*
|
|
* Class: OpenLayers.Control.MousePosition
|
|
*/
|
|
OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
|
|
|
/**
|
|
* Property: element
|
|
* {DOMElement}
|
|
*/
|
|
element: null,
|
|
|
|
/**
|
|
* APIProperty: prefix
|
|
*/
|
|
prefix: '',
|
|
|
|
/**
|
|
* APIProperty: separator
|
|
* {String}
|
|
*/
|
|
separator: ', ',
|
|
|
|
/**
|
|
* APIProperty: suffix
|
|
* {String}
|
|
*/
|
|
suffix: '',
|
|
|
|
/**
|
|
* APIProperty: numDigits
|
|
* {Integer}
|
|
*/
|
|
numdigits: 5,
|
|
|
|
/**
|
|
* APIProperty: granularity
|
|
* {Integer}
|
|
*/
|
|
granularity: 10,
|
|
|
|
/**
|
|
* Property: lastXy
|
|
* {<OpenLayers.LonLat>}
|
|
*/
|
|
lastXy: null,
|
|
|
|
/**
|
|
* Constructor: OpenLayers.Control.MousePosition
|
|
*
|
|
* Parameters:
|
|
* options - {DOMElement} Options for control.
|
|
*/
|
|
initialize: function(options) {
|
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: destroy
|
|
*/
|
|
destroy: function() {
|
|
if (this.map) {
|
|
this.map.events.unregister('mousemove', this, this.redraw);
|
|
}
|
|
OpenLayers.Control.prototype.destroy.apply(this, arguments);
|
|
},
|
|
|
|
/**
|
|
* Method: draw
|
|
* {DOMElement}
|
|
*/
|
|
draw: function() {
|
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
|
|
|
if (!this.element) {
|
|
this.div.left = "";
|
|
this.div.top = "";
|
|
this.div.className = this.displayClass;
|
|
this.element = this.div;
|
|
}
|
|
|
|
this.redraw();
|
|
return this.div;
|
|
},
|
|
|
|
/**
|
|
* Method: redraw
|
|
*/
|
|
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;
|
|
}
|
|
},
|
|
|
|
/**
|
|
* Method: setMap
|
|
*/
|
|
setMap: function() {
|
|
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
|
this.map.events.register( 'mousemove', this, this.redraw);
|
|
},
|
|
|
|
CLASS_NAME: "OpenLayers.Control.MousePosition"
|
|
});
|