diff --git a/examples/select-feature.html b/examples/select-feature.html
index 02f23c285d..442ced04c5 100644
--- a/examples/select-feature.html
+++ b/examples/select-feature.html
@@ -23,7 +23,6 @@
var vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wmsLayer, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
- map.addControl(new OpenLayers.Control.MousePosition());
drawControls = {
point: new OpenLayers.Control.DrawFeature(
@@ -44,6 +43,14 @@
multipleKey: "shiftKey", // shift key adds to selection
box: true
}
+ ),
+ selecthover: new OpenLayers.Control.SelectFeature(
+ vectors,
+ {
+ multiple: false, hover: true,
+ toggleKey: "ctrlKey", // ctrl key removes from selection
+ multipleKey: "shiftKey" // shift key adds to selection
+ }
)
};
@@ -106,6 +113,11 @@
onclick="toggleControl(this);" />
+
+
+
+
@@ -121,11 +133,6 @@
name="clickout" onchange="update()" />
-
-
-
-
diff --git a/lib/OpenLayers/Control/SelectFeature.js b/lib/OpenLayers/Control/SelectFeature.js
index 8c4d3e2616..92f8a80f1a 100644
--- a/lib/OpenLayers/Control/SelectFeature.js
+++ b/lib/OpenLayers/Control/SelectFeature.js
@@ -128,12 +128,16 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function(layer, options) {
OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.layer = layer;
- this.callbacks = OpenLayers.Util.extend({
- click: this.clickFeature,
- clickout: this.clickoutFeature,
- over: this.overFeature,
- out: this.outFeature
- }, this.callbacks);
+ var callbacks = {
+ click: this.clickFeature,
+ clickout: this.clickoutFeature
+ };
+ if (this.hover) {
+ callbacks.over = this.overFeature;
+ callbacks.out = this.outFeature;
+ }
+
+ this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks);
this.handlers = {
feature: new OpenLayers.Handler.Feature(
this, layer, this.callbacks, {geometryTypes: this.geometryTypes}
diff --git a/lib/OpenLayers/Handler/Feature.js b/lib/OpenLayers/Handler/Feature.js
index 769f8e6d8d..15c956fa2a 100644
--- a/lib/OpenLayers/Handler/Feature.js
+++ b/lib/OpenLayers/Handler/Feature.js
@@ -176,6 +176,9 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean}
*/
mousemove: function(evt) {
+ if (!this.callbacks['over'] && !this.callbacks['out']) {
+ return false;
+ }
this.handle(evt);
return true;
},
diff --git a/tests/Handler/Feature.html b/tests/Handler/Feature.html
index 15d4f6fbc5..819deb522e 100644
--- a/tests/Handler/Feature.html
+++ b/tests/Handler/Feature.html
@@ -177,6 +177,11 @@
evtPx.type = "click";
map.events.triggerEvent('click', evtPx);
+ layer.getFeatureFromEvent = function(evt) { t.fail("mousemove called getFeatureFromEvent without any mousemove callbacks"); };
+ evtPx.type = "mousemove";
+ map.events.triggerEvent('mousemove', evtPx);
+ layer.getFeatureFromEvent = function(evt) { return newFeature; };
+
// test over a new feature
// only 'over' callback should be called
handler.feature = null;