diff --git a/lib/OpenLayers/Control/SelectFeature.js b/lib/OpenLayers/Control/SelectFeature.js index 24da9406ac..d0772df9f8 100644 --- a/lib/OpenLayers/Control/SelectFeature.js +++ b/lib/OpenLayers/Control/SelectFeature.js @@ -111,7 +111,7 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, { * {Object} The scope to use with the onBeforeSelect, onSelect, onUnselect * callbacks. If null the scope will be this control. */ - scope: this, + scope: null, /** * APIProperty: geometryTypes @@ -178,6 +178,10 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, { OpenLayers.Control.prototype.EVENT_TYPES ); OpenLayers.Control.prototype.initialize.apply(this, [options]); + + if(this.scope === null) { + this.scope = this; + } if(layers instanceof Array) { this.layers = layers; this.layer = new OpenLayers.Layer.Vector.RootContainer( diff --git a/tests/Control/SelectFeature.html b/tests/Control/SelectFeature.html index 8aa50eea5b..e38eaee4bf 100644 --- a/tests/Control/SelectFeature.html +++ b/tests/Control/SelectFeature.html @@ -68,7 +68,7 @@ } function test_Control_SelectFeature_clickFeature(t) { - t.plan(4); + t.plan(6); // mock up layer var layer = { selectedFeatures: [], @@ -100,6 +100,7 @@ "onSelect called with proper feature (" + feature.index + ")"); t.eq(feature.tested, feature.test, "onSelect called only once for feature (" + feature.index + ")"); + t.ok(this == control, "onSelect called in the scope of the control if control.scope is not provided"); } // test that onUnselect gets called properly @@ -109,9 +110,10 @@ "onUnselect called with proper feature (" + feature.index + ")"); t.eq(feature.tested, feature.test, "onUnselect called only once for feature (" + feature.index + ")"); + t.ok(this == control, "onUnselect called in the scope of the control if control.scope is not provided"); } - // mock up first click on first feature (runs 2 tests from onSelect) + // mock up first click on first feature (runs 3 tests from onSelect) var feature = features[0]; feature.index = 0; feature.test = 1; @@ -121,7 +123,7 @@ control.toggle = false; control.clickFeature(feature); - // mock up second click on first feature (runs 2 tests from onUnselect) + // mock up second click on first feature (runs 3 tests from onUnselect) control.toggle = true; feature.test = 2; control.clickFeature(feature);