"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:
@@ -52,6 +52,13 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
||||
* {Integer}
|
||||
*/
|
||||
granularity: 10,
|
||||
|
||||
/**
|
||||
* APIProperty: emptyString
|
||||
* {String} Set this to some value to set when the mouse is outside the
|
||||
* map.
|
||||
*/
|
||||
emptyString: null,
|
||||
|
||||
/**
|
||||
* Property: lastXy
|
||||
@@ -111,7 +118,8 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
||||
var lonLat;
|
||||
|
||||
if (evt == null) {
|
||||
lonLat = new OpenLayers.LonLat(0, 0);
|
||||
this.reset();
|
||||
return;
|
||||
} else {
|
||||
if (this.lastXy == null ||
|
||||
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
|
||||
* Override to provide custom display output
|
||||
@@ -165,6 +182,7 @@ OpenLayers.Control.MousePosition = OpenLayers.Class(OpenLayers.Control, {
|
||||
setMap: function() {
|
||||
OpenLayers.Control.prototype.setMap.apply(this, arguments);
|
||||
this.map.events.register( 'mousemove', this, this.redraw);
|
||||
this.map.events.register( 'mouseout', this, this.reset);
|
||||
},
|
||||
|
||||
CLASS_NAME: "OpenLayers.Control.MousePosition"
|
||||
|
||||
@@ -10,21 +10,6 @@
|
||||
t.ok( control instanceof OpenLayers.Control.MousePosition, "new OpenLayers.Control returns object" );
|
||||
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) {
|
||||
t.plan(1);
|
||||
|
||||
@@ -52,14 +37,17 @@
|
||||
map.destroy();
|
||||
}
|
||||
function test_redraw_noLayer_displayProjection(t) {
|
||||
t.plan(3);
|
||||
var control = new OpenLayers.Control.MousePosition();
|
||||
t.plan(4);
|
||||
var control = new OpenLayers.Control.MousePosition({'emptyString':''});
|
||||
var map = new OpenLayers.Map('map');
|
||||
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(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});
|
||||
map.addLayer(l);
|
||||
map.zoomToMaxExtent();
|
||||
|
||||
Reference in New Issue
Block a user