Fix for Feature handler uses getFeatureFromEvent on mousemove even without

hover callbacks; r=ahocevar (Closes #1655) 

This means that On the SelectFeature control hover can no longer be set on the
SelectFeature control after the control has been initialized: must be passed at
initialize time. Example has been updated. 


git-svn-id: http://svn.openlayers.org/trunk/openlayers@7682 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-08-03 02:06:31 +00:00
parent f0e9c1c6a5
commit 693e6d07e3
4 changed files with 31 additions and 12 deletions
+13 -6
View File
@@ -23,7 +23,6 @@
var vectors = new OpenLayers.Layer.Vector("Vector Layer"); var vectors = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayers([wmsLayer, vectors]); map.addLayers([wmsLayer, vectors]);
map.addControl(new OpenLayers.Control.LayerSwitcher()); map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.MousePosition());
drawControls = { drawControls = {
point: new OpenLayers.Control.DrawFeature( point: new OpenLayers.Control.DrawFeature(
@@ -44,6 +43,14 @@
multipleKey: "shiftKey", // shift key adds to selection multipleKey: "shiftKey", // shift key adds to selection
box: true 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);" /> onclick="toggleControl(this);" />
<label for="polygonToggle">draw polygon</label> <label for="polygonToggle">draw polygon</label>
</li> </li>
<li>
<input type="radio" name="type" value="selecthover" id="selecthoverToggle"
onclick="toggleControl(this);" />
<label for="selecthoverToggle">Select features on hover</label>
</li>
<li> <li>
<input type="radio" name="type" value="select" id="selectToggle" <input type="radio" name="type" value="select" id="selectToggle"
onclick="toggleControl(this);" /> onclick="toggleControl(this);" />
@@ -121,11 +133,6 @@
name="clickout" onchange="update()" /> name="clickout" onchange="update()" />
<label for="clickout">click out to unselect features</label> <label for="clickout">click out to unselect features</label>
</li> </li>
<li>
<input id="hover" type="checkbox"
name="hover" onchange="update()" />
<label for="hover">hover to select features</label>
</li>
</ul> </ul>
</li> </li>
</ul> </ul>
+10 -6
View File
@@ -128,12 +128,16 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
initialize: function(layer, options) { initialize: function(layer, options) {
OpenLayers.Control.prototype.initialize.apply(this, [options]); OpenLayers.Control.prototype.initialize.apply(this, [options]);
this.layer = layer; this.layer = layer;
this.callbacks = OpenLayers.Util.extend({ var callbacks = {
click: this.clickFeature, click: this.clickFeature,
clickout: this.clickoutFeature, clickout: this.clickoutFeature
over: this.overFeature, };
out: this.outFeature if (this.hover) {
}, this.callbacks); callbacks.over = this.overFeature;
callbacks.out = this.outFeature;
}
this.callbacks = OpenLayers.Util.extend(callbacks, this.callbacks);
this.handlers = { this.handlers = {
feature: new OpenLayers.Handler.Feature( feature: new OpenLayers.Handler.Feature(
this, layer, this.callbacks, {geometryTypes: this.geometryTypes} this, layer, this.callbacks, {geometryTypes: this.geometryTypes}
+3
View File
@@ -176,6 +176,9 @@ OpenLayers.Handler.Feature = OpenLayers.Class(OpenLayers.Handler, {
* {Boolean} * {Boolean}
*/ */
mousemove: function(evt) { mousemove: function(evt) {
if (!this.callbacks['over'] && !this.callbacks['out']) {
return false;
}
this.handle(evt); this.handle(evt);
return true; return true;
}, },
+5
View File
@@ -177,6 +177,11 @@
evtPx.type = "click"; evtPx.type = "click";
map.events.triggerEvent('click', evtPx); 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 // test over a new feature
// only 'over' callback should be called // only 'over' callback should be called
handler.feature = null; handler.feature = null;