[OpenLayers-Commits] r11633 - in trunk/openlayers:
lib/OpenLayers/Control tests/Control
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Mon Mar 7 02:57:21 EST 2011
Author: erilem
Date: 2011-03-06 23:57:14 -0800 (Sun, 06 Mar 2011)
New Revision: 11633
Modified:
trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js
trunk/openlayers/tests/Control/SelectFeature.html
Log:
SelectFeature control - highlightOnly and toggle don't play well together, p=me, r=bartvde (closes #2812)
Modified: trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js 2011-03-07 05:38:51 UTC (rev 11632)
+++ trunk/openlayers/lib/OpenLayers/Control/SelectFeature.js 2011-03-07 07:57:14 UTC (rev 11633)
@@ -463,8 +463,23 @@
*/
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});
Modified: trunk/openlayers/tests/Control/SelectFeature.html
===================================================================
--- trunk/openlayers/tests/Control/SelectFeature.html 2011-03-07 05:38:51 UTC (rev 11632)
+++ trunk/openlayers/tests/Control/SelectFeature.html 2011-03-07 07:57:14 UTC (rev 11633)
@@ -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");
More information about the Commits
mailing list