Trigger feature related events with feature information and layer related events with layer information. Also adding events.on and events.un convenience methods. r=crschmidt (closes #1343)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6149 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-08 23:31:27 +00:00
parent 464fb30589
commit f27833f1db
20 changed files with 326 additions and 118 deletions
+18 -9
View File
@@ -5,13 +5,17 @@
function test_ModifyFeature_constructor(t) {
t.plan(3);
var layer = "foo";
var layer = {
events: {
on: function() {}
}
};
var options = {
geometryTypes: "bar"
};
var control = new OpenLayers.Control.ModifyFeature(layer, options);
t.eq(control.layer, "foo",
t.ok(control.layer == layer,
"constructor sets layer correctly");
t.eq(control.selectControl.geometryTypes, "bar",
"constructor sets options correctly on feature handler");
@@ -72,7 +76,12 @@
* In the future, feature deletion may be added to the control.
*/
var control = new OpenLayers.Control.ModifyFeature({style: null});
var control = new OpenLayers.Control.ModifyFeature({
style: null,
events: {
on: function() {}
}
});
var delKey = 46;
var dKey = 100;
control.deleteCodes = [delKey, dKey];
@@ -197,7 +206,7 @@
layer.destroyFeatures = function(verts) {
t.ok(verts == 'b', "Virtual verts destroyed correctly");
}
control.unselectFeature(fakeFeature);
control.unselectFeature({feature: fakeFeature});
t.eq(control.feature, null, "feature is set to null");
}
function test_ModifyFeature_selectFeature(t) {
@@ -216,7 +225,7 @@
var fakeFeature = {'id':'myFakeFeature','geometry':{'CLASS_NAME':'OpenLayers.Geometry.Point'}};
// Points don't call collectVertices
control.selectFeature(fakeFeature);
control.selectFeature({feature: fakeFeature});
control.collectVertices = function() {
t.ok(true, "collectVertices called");
@@ -232,7 +241,7 @@
fakeFeature.geometry.CLASS_NAME='OpenLayers.Geometry.Polygon';
// OnSelect calls collectVertices and passes features to layer
control.selectFeature(fakeFeature);
control.selectFeature({feature: fakeFeature});
control.vertices = ['a'];
control.virtualVertices = ['b'];
@@ -244,7 +253,7 @@
}
// Features are removed whenever they exist
control.selectFeature(fakeFeature);
control.selectFeature({feature: fakeFeature});
}
@@ -389,7 +398,7 @@
t.eq(feature.id, testFeature.id,
"onModificationStart called with the right feature");
};
control.selectFeature(testFeature);
control.selectFeature({feature: testFeature});
}
function test_ModifyFeature_onModification(t) {
@@ -450,7 +459,7 @@
t.eq(feature.id, testFeature.id,
"onModificationEnd called with the right feature");
};
control.unselectFeature(testFeature);
control.unselectFeature({feature: testFeature});
}
+4 -1
View File
@@ -78,7 +78,10 @@
// mock up layer
var layer = {
selectedFeatures: [],
drawFeature: function() {}
drawFeature: function() {},
events: {
triggerEvent: function() {}
}
};
// mock up active control
var control = new OpenLayers.Control.SelectFeature(layer);
+2 -1
View File
@@ -499,7 +499,8 @@
events: {
unregister: function(name, obj, func) {
g_unregistered[name] = [obj, func];
}
},
un: OpenLayers.Events.prototype.un
}
}
+12 -9
View File
@@ -205,19 +205,22 @@
eventTypes = ["something"];
events = new OpenLayers.Events(null, null, eventTypes);
var instance = {id: Math.random()};
var listener = function() {
var listener = function(obj) {
t.eq(this.id, instance.id,
"listener called with proper scope");
t.eq(arguments[0].id, evt.id,
"listener called with evt as first arg");
t.eq(arguments[1], "arg1",
"listener called with correct extra arg1");
t.eq(arguments[2], "arg2",
"listener called with correct extra arg2");
t.eq(arguments.length, 1,
"listener called with a single argument");
t.eq(typeof arguments, "object",
"listener called with an object");
t.eq(obj.foo, evt.foo,
"foo property set on the layer");
};
events.register("something", instance, listener);
var evt = {id: Math.random()};
events.triggerEvent("something", evt, ["arg1", "arg2", "arg3"]);
var evt = {
id: Math.random(),
"foo": "bar"
};
events.triggerEvent("something", evt);
events.unregister("something", instance, listener);
// test return from triggerEvent