"MousePosition control should support mouseOut event", r=bartvde,

initial patch cmoullet, (Closes #2404)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@10127 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2010-03-19 13:34:14 +00:00
parent cca74e7635
commit 3304c6cb0e
2 changed files with 26 additions and 20 deletions

View File

@@ -52,6 +52,13 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
* {Integer} * {Integer}
*/ */
granularity: 10, granularity: 10,
/**
* APIProperty: emptyString
* {String} Set this to some value to set when the mouse is outside the
* map.
*/
emptyString: null,
/** /**
* Property: lastXy * Property: lastXy
@@ -111,7 +118,8 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
var lonLat; var lonLat;
if (evt == null) { if (evt == null) {
lonLat = new OpenLayers.LonLat(0, 0); this.reset();
return;
} else { } else {
if (this.lastXy == null || if (this.lastXy == null ||
Math.abs(evt.xy.x - this.lastXy.x) > this.granularity || Math.abs(evt.xy.x - this.lastXy.x) > this.granularity ||
@@ -141,6 +149,15 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
} }
}, },
/**
* Method: reset
*/
reset: function(evt) {
if (this.emptyString != null) {
this.element.innerHTML = this.emptyString;
}
},
/** /**
* Method: formatOutput * Method: formatOutput
* Override to provide custom display output * Override to provide custom display output
@@ -165,6 +182,7 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
setMap: function() { setMap: function() {
OpenLayers.Control.prototype.setMap.apply(this, arguments); OpenLayers.Control.prototype.setMap.apply(this, arguments);
this.map.events.register( 'mousemove', this, this.redraw); this.map.events.register( 'mousemove', this, this.redraw);
this.map.events.register( 'mouseout', this, this.reset);
}, },
CLASS_NAME: "OpenLayers.Control.MousePosition" CLASS_NAME: "OpenLayers.Control.MousePosition"

View File

@@ -10,21 +10,6 @@
t.ok( control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control returns object" ); t.ok( control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control returns object" );
t.eq( control.displayClass, "olControlMousePosition", "displayClass is correct" ); t.eq( control.displayClass, "olControlMousePosition", "displayClass is correct" );
} }
function test_redraw_noLayer_displayProjection(t) {
t.plan(2);
control = new OpenLayers.Control.MousePosition({'displayProjection': new OpenLayers.Projection("WGS84")});
map = new OpenLayers.Map('map');
map.addControl(control);
control.redraw({'xy': new OpenLayers.Pixel(10,10)});
control.redraw({'xy': new OpenLayers.Pixel(12,12)});
t.eq(control.div.innerHTML, "", "innerHTML set correctly");
l = new OpenLayers.Layer('name', {'isBaseLayer': true});
map.addLayer(l);
map.zoomToMaxExtent();
control.redraw({'xy': new OpenLayers.Pixel(10,10)});
control.redraw({'xy': new OpenLayers.Pixel(12,12)});
t.eq(control.div.innerHTML, "-175.78125, 85.78125", "innerHTML set correctly when triggered.");
}
function test_destroy(t) { function test_destroy(t) {
t.plan(1); t.plan(1);
@@ -52,14 +37,17 @@
map.destroy(); map.destroy();
} }
function test_redraw_noLayer_displayProjection(t) { function test_redraw_noLayer_displayProjection(t) {
t.plan(3); t.plan(4);
var control = new OpenLayers.Control.MousePosition(); var control = new OpenLayers.Control.MousePosition({'emptyString':''});
var map = new OpenLayers.Map('map'); var map = new OpenLayers.Map('map');
map.addControl(control); map.addControl(control);
t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly"); var control2 = new OpenLayers.Control.MousePosition();
map.addControl(control2);
t.eq(control2.emptyString, null, "Emptystring is null");
t.eq(control.div.innerHTML, "", "innerHTML set correctly");
control.redraw({'xy': new OpenLayers.Pixel(10,10)}); control.redraw({'xy': new OpenLayers.Pixel(10,10)});
control.redraw({'xy': new OpenLayers.Pixel(12,12)}); control.redraw({'xy': new OpenLayers.Pixel(12,12)});
t.eq(control.div.innerHTML, "0.00000, 0.00000", "innerHTML set correctly"); t.eq(control.div.innerHTML, "", "innerHTML set correctly");
var l = new OpenLayers.Layer('name', {'isBaseLayer': true}); var l = new OpenLayers.Layer('name', {'isBaseLayer': true});
map.addLayer(l); map.addLayer(l);
map.zoomToMaxExtent(); map.zoomToMaxExtent();