SelectFeature control - highlightOnly and toggle don't play well together, p=me, r=bartvde (closes #2812)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11633 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Éric Lemoine
2011-03-07 07:57:14 +00:00
parent e8a3885d27
commit 1f58346772
2 changed files with 125 additions and 2 deletions

View File

@@ -463,8 +463,23 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
*/
unhighlight: function(feature) {
var layer = feature.layer;
feature._lastHighlighter = feature._prevHighlighter;
delete feature._prevHighlighter;
// three cases:
// 1. there's no other highlighter, in that case _prev is undefined,
// and we just need to undef _last
// 2. another control highlighted the feature after we did it, in
// that case _last references this other control, and we just
// need to undef _prev
// 3. another control highlighted the feature before we did it, in
// that case _prev references this other control, and we need to
// set _last to _prev and undef _prev
if(feature._prevHighlighter == undefined) {
delete feature._lastHighlighter;
} else if(feature._prevHighlighter == this.id) {
delete feature._prevHighlighter;
} else {
feature._lastHighlighter = feature._prevHighlighter;
delete feature._prevHighlighter;
}
layer.drawFeature(feature, feature.style || feature.layer.style ||
"default");
this.events.triggerEvent("featureunhighlighted", {feature : feature});

View File

@@ -373,6 +373,114 @@
map.events.triggerEvent("click", evt);
}
// test for http://trac.openlayers.org/ticket/2812
function test_highlightOnly_toggle(t) {
t.plan(8);
/*
* setup
*/
var map, layer, ctrl1, ctrl2, _feature, feature, evt, _style;
map = new OpenLayers.Map("map");
layer = new OpenLayers.Layer.Vector("name", {isBaseLayer: true});
map.addLayer(layer);
ctrl1 = new OpenLayers.Control.SelectFeature(layer, {
highlightOnly: false,
hover: false,
clickout: false,
toggle: true
});
map.addControl(ctrl1);
ctrl2 = new OpenLayers.Control.SelectFeature(layer, {
highlightOnly: true,
hover: true
});
map.addControl(ctrl2);
ctrl2.activate();
ctrl1.activate();
feature = new OpenLayers.Feature.Vector();
feature.layer = layer;
// override the layer's getFeatureFromEvent func so that it always
// returns the feature referenced to by _feature
layer.getFeatureFromEvent = function(evt) { return _feature; };
evt = {xy: new OpenLayers.Pixel(Math.random(), Math.random())};
map.zoomToMaxExtent();
/*
* tests
*/
// with renderIntent
ctrl1.renderIntent = "select";
ctrl2.renderIntent = "temporary";
// mouse over feature, feature is drawn with "temporary"
_feature = feature;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "temporary",
"feature drawn with expected render intent after \"mouseover\"");
// click in feature, feature is drawn with "select"
_feature = feature;
evt.type = "click";
map.events.triggerEvent("click", evt);
t.eq(feature.renderIntent, "select",
"feature drawn with expected render intent after \"clickin\"");
// mouse out of feature, feature is still drawn with "select"
_feature = null;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "select",
"feature drawn with expected render intent after \"mouseout\"");
// mouse over feature again, feature is drawn with "temporary"
_feature = feature;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "temporary",
"feature drawn with expected render intent after \"mouseover\"");
// click in feature again, feature is drawn with "default"
_feature = feature;
evt.type = "click";
map.events.triggerEvent("click", evt);
t.eq(feature.renderIntent, "default",
"feature drawn with expected render intent after \"clickin\"");
// mouse out of feature again, feature is still drawn with "default"
_feature = null;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "default",
"feature drawn with expected render intent after \"mouseout\"");
// mouse over feature again, feature is drawn with "temporary"
_feature = feature;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "temporary",
"feature drawn with expected render intent after \"mouseover\"");
// mouse out of feature again, feature is still drawn with "default"
_feature = null;
evt.type = "mousemove";
map.events.triggerEvent("mousemove", evt);
t.eq(feature.renderIntent, "default",
"feature drawn with expected render intent after \"mouseout\"");
}
function test_setLayer(t) {
t.plan(5);
var map = new OpenLayers.Map("map");