Adding eventListeners property to layer, control, and map. Setting this property at construction registers the given listeners based on event type key. r=elemoine (closes #1404)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@6435 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -104,6 +104,15 @@ OpenLayers.Control = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
handler: null,
|
handler: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: eventListeners
|
||||||
|
* {Object} If set as an option at construction, the eventListeners
|
||||||
|
* object will be registered with <OpenLayers.Events.on>. Object
|
||||||
|
* structure must be a listeners object as shown in the example for
|
||||||
|
* the events.on method.
|
||||||
|
*/
|
||||||
|
eventListeners: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: events
|
* Property: events
|
||||||
* {<OpenLayers.Events>} Events instance for triggering control specific
|
* {<OpenLayers.Events>} Events instance for triggering control specific
|
||||||
@@ -155,6 +164,9 @@ OpenLayers.Control = OpenLayers.Class({
|
|||||||
OpenLayers.Util.extend(this, options);
|
OpenLayers.Util.extend(this, options);
|
||||||
|
|
||||||
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
|
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
|
||||||
|
if(this.eventListeners instanceof Object) {
|
||||||
|
this.events.on(this.eventListeners);
|
||||||
|
}
|
||||||
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
|
this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME + "_");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -651,6 +651,9 @@ OpenLayers.Events = OpenLayers.Class({
|
|||||||
}
|
}
|
||||||
evt.object = this.object;
|
evt.object = this.object;
|
||||||
evt.element = this.element;
|
evt.element = this.element;
|
||||||
|
if(!evt.type) {
|
||||||
|
evt.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
// execute all callbacks registered for specified type
|
// execute all callbacks registered for specified type
|
||||||
// get a clone of the listeners array to
|
// get a clone of the listeners array to
|
||||||
|
|||||||
@@ -138,6 +138,15 @@ OpenLayers.Layer = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
options: null,
|
options: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: eventListeners
|
||||||
|
* {Object} If set as an option at construction, the eventListeners
|
||||||
|
* object will be registered with <OpenLayers.Events.on>. Object
|
||||||
|
* structure must be a listeners object as shown in the example for
|
||||||
|
* the events.on method.
|
||||||
|
*/
|
||||||
|
eventListeners: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* APIProperty: gutter
|
* APIProperty: gutter
|
||||||
* {Integer} Determines the width (in pixels) of the gutter around image
|
* {Integer} Determines the width (in pixels) of the gutter around image
|
||||||
@@ -272,6 +281,10 @@ OpenLayers.Layer = OpenLayers.Class({
|
|||||||
|
|
||||||
this.events = new OpenLayers.Events(this, this.div,
|
this.events = new OpenLayers.Events(this, this.div,
|
||||||
this.EVENT_TYPES);
|
this.EVENT_TYPES);
|
||||||
|
if(this.eventListeners instanceof Object) {
|
||||||
|
this.events.on(this.eventListeners);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.wrapDateLine) {
|
if (this.wrapDateLine) {
|
||||||
|
|||||||
@@ -336,6 +336,15 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
*/
|
*/
|
||||||
panTween: null,
|
panTween: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* APIProperty: eventListeners
|
||||||
|
* {Object} If set as an option at construction, the eventListeners
|
||||||
|
* object will be registered with <OpenLayers.Events.on>. Object
|
||||||
|
* structure must be a listeners object as shown in the example for
|
||||||
|
* the events.on method.
|
||||||
|
*/
|
||||||
|
eventListeners: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Property: panMethod
|
* Property: panMethod
|
||||||
* {Function} The Easing function to be used for tweening. Default is
|
* {Function} The Easing function to be used for tweening. Default is
|
||||||
@@ -408,6 +417,9 @@ OpenLayers.Map = OpenLayers.Class({
|
|||||||
this.EVENT_TYPES,
|
this.EVENT_TYPES,
|
||||||
this.fallThrough);
|
this.fallThrough);
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
|
if(this.eventListeners instanceof Object) {
|
||||||
|
this.events.on(this.eventListeners);
|
||||||
|
}
|
||||||
|
|
||||||
// update the map size and location before the map moves
|
// update the map size and location before the map moves
|
||||||
this.events.register("movestart", this, this.updateSize);
|
this.events.register("movestart", this, this.updateSize);
|
||||||
|
|||||||
@@ -29,6 +29,31 @@
|
|||||||
t.eq( control.title, titleText, "control.title set correctly" );
|
t.eq( control.title, titleText, "control.title set correctly" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_eventListeners(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var method = OpenLayers.Events.prototype.on;
|
||||||
|
// test that events.on is called at control construction
|
||||||
|
var options = {
|
||||||
|
eventListeners: {foo: "bar"}
|
||||||
|
};
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
|
||||||
|
}
|
||||||
|
var control = new OpenLayers.Control(options);
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
control.destroy();
|
||||||
|
|
||||||
|
// if events.on is called again, this will fail due to an extra test
|
||||||
|
// test control without eventListeners
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.fail("events.on called without eventListeners");
|
||||||
|
}
|
||||||
|
var control2 = new OpenLayers.Control();
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
control2.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
function test_Control_destroy(t) {
|
function test_Control_destroy(t) {
|
||||||
t.plan(3);
|
t.plan(3);
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,31 @@
|
|||||||
t.eq(layer.numZoomLevels, numZoomLevels, "numZoomLevels set correctly");
|
t.eq(layer.numZoomLevels, numZoomLevels, "numZoomLevels set correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_eventListeners(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var method = OpenLayers.Events.prototype.on;
|
||||||
|
// test that events.on is called at layer construction
|
||||||
|
var options = {
|
||||||
|
eventListeners: {foo: "bar"}
|
||||||
|
};
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
|
||||||
|
}
|
||||||
|
var layer = new OpenLayers.Layer("test", options);
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
layer.destroy();
|
||||||
|
|
||||||
|
// if events.on is called again, this will fail due to an extra test
|
||||||
|
// test layer without eventListeners
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.fail("events.on called without eventListeners");
|
||||||
|
}
|
||||||
|
var layer2 = new OpenLayers.Layer("test");
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
layer2.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
function test_Layer_initResolutions(t) {
|
function test_Layer_initResolutions(t) {
|
||||||
t.plan(12);
|
t.plan(12);
|
||||||
var map = new OpenLayers.Map("map");
|
var map = new OpenLayers.Map("map");
|
||||||
|
|||||||
@@ -85,6 +85,32 @@
|
|||||||
t.eq( map.theme, 'foo', "map theme set correctly." );
|
t.eq( map.theme, 'foo', "map theme set correctly." );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function test_eventListeners(t) {
|
||||||
|
t.plan(1);
|
||||||
|
|
||||||
|
var method = OpenLayers.Events.prototype.on;
|
||||||
|
// test that events.on is called at map construction
|
||||||
|
var options = {
|
||||||
|
eventListeners: {foo: "bar"},
|
||||||
|
controls: []
|
||||||
|
};
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.eq(obj, options.eventListeners, "events.on called with eventListeners");
|
||||||
|
}
|
||||||
|
var map = new OpenLayers.Map('map', options);
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
map.destroy();
|
||||||
|
|
||||||
|
// if events.on is called again, this will fail due to an extra test
|
||||||
|
// test map without eventListeners
|
||||||
|
OpenLayers.Events.prototype.on = function(obj) {
|
||||||
|
t.fail("events.on called without eventListeners");
|
||||||
|
}
|
||||||
|
var map2 = new OpenLayers.Map("map", {controls: []});
|
||||||
|
OpenLayers.Events.prototype.on = method;
|
||||||
|
map2.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
function test_05_Map_center(t) {
|
function test_05_Map_center(t) {
|
||||||
t.plan(4);
|
t.plan(4);
|
||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
|
|||||||
Reference in New Issue
Block a user