diff --git a/externs/oli.js b/externs/oli.js
index 16f5a8a201..903fd6e893 100644
--- a/externs/oli.js
+++ b/externs/oli.js
@@ -137,22 +137,6 @@ oli.control.Control.prototype.setMap = function(map) {};
oli.interaction;
-
-/**
- * @interface
- */
-oli.interaction.Interaction = function() {};
-
-/**
- * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
- * @return {boolean} Whether the map browser event should continue
- * through the chain of interactions. `false` means stop, `true`
- * means continue.
- */
-oli.interaction.Interaction.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {};
-
-
/**
* @interface
*/
diff --git a/externs/olx.js b/externs/olx.js
index 7decb05bfa..4370a7602f 100644
--- a/externs/olx.js
+++ b/externs/olx.js
@@ -172,6 +172,25 @@ olx.GraticuleOptions.prototype.strokeStyle;
olx.GraticuleOptions.prototype.targetSize;
+/**
+ * Object literal with config options for interactions.
+ * @typedef {{handleEvent: function(ol.MapBrowserEvent):boolean}}
+ * @api
+ */
+olx.interaction.InteractionOptions;
+
+
+/**
+ * Method called by the map to notify the interaction that a browser event was
+ * dispatched to the map. The function may return `false` to prevent the
+ * propagation of the event to other interactions in the map's interactions
+ * chain. Required.
+ * @type {function(ol.MapBrowserEvent):boolean}
+ * @api
+ */
+olx.interaction.InteractionOptions.prototype.handleEvent;
+
+
/**
* Object literal with config options for the map.
* @typedef {{controls: (ol.Collection.
|Array.|undefined),
@@ -2410,6 +2429,24 @@ olx.interaction.PinchZoomOptions;
olx.interaction.PinchZoomOptions.prototype.duration;
+/**
+ * @typedef {{handleEvent: function(ol.MapBrowserEvent):boolean}}
+ * @api
+ */
+olx.interaction.PointerOptions;
+
+
+/**
+ * Method called by the map to notify the interaction that a browser event was
+ * dispatched to the map. The function may return `false` to prevent the
+ * propagation of the event to other interactions in the map's interactions
+ * chain.
+ * @type {function(ol.MapBrowserEvent):boolean}
+ * @api
+ */
+olx.interaction.PointerOptions.prototype.handleEvent;
+
+
/**
* @typedef {{addCondition: (ol.events.ConditionType|undefined),
* condition: (ol.events.ConditionType|undefined),
diff --git a/src/ol/interaction/doubleclickzoominteraction.js b/src/ol/interaction/doubleclickzoominteraction.js
index e840045e8d..a01d7ba25c 100644
--- a/src/ol/interaction/doubleclickzoominteraction.js
+++ b/src/ol/interaction/doubleclickzoominteraction.js
@@ -26,7 +26,9 @@ ol.interaction.DoubleClickZoom = function(opt_options) {
*/
this.delta_ = goog.isDef(options.delta) ? options.delta : 1;
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.DoubleClickZoom.handleEvent
+ });
/**
* @private
@@ -39,10 +41,12 @@ goog.inherits(ol.interaction.DoubleClickZoom, ol.interaction.Interaction);
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.DoubleClickZoom}
+ * @api
*/
-ol.interaction.DoubleClickZoom.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
var browserEvent = mapBrowserEvent.browserEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) {
diff --git a/src/ol/interaction/draganddropinteraction.js b/src/ol/interaction/draganddropinteraction.js
index 382e27d8ea..3769fa094b 100644
--- a/src/ol/interaction/draganddropinteraction.js
+++ b/src/ol/interaction/draganddropinteraction.js
@@ -29,7 +29,9 @@ ol.interaction.DragAndDrop = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {};
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.DragAndDrop.handleEvent
+ });
/**
* @private
@@ -133,10 +135,12 @@ ol.interaction.DragAndDrop.prototype.handleResult_ = function(file, result) {
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.DragAndDrop}
+ * @api
*/
-ol.interaction.DragAndDrop.prototype.handleMapBrowserEvent =
- goog.functions.TRUE;
+ol.interaction.DragAndDrop.handleEvent = goog.functions.TRUE;
/**
diff --git a/src/ol/interaction/drawinteraction.js b/src/ol/interaction/drawinteraction.js
index 5ce00a70d0..94354c66bc 100644
--- a/src/ol/interaction/drawinteraction.js
+++ b/src/ol/interaction/drawinteraction.js
@@ -85,7 +85,9 @@ goog.inherits(ol.DrawEvent, goog.events.Event);
*/
ol.interaction.Draw = function(options) {
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.Draw.handleEvent
+ });
/**
* @type {ol.Pixel}
@@ -236,20 +238,23 @@ ol.interaction.Draw.prototype.setMap = function(map) {
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.Draw}
+ * @api
*/
-ol.interaction.Draw.prototype.handleMapBrowserEvent = function(event) {
- var map = event.map;
+ol.interaction.Draw.handleEvent = function(mapBrowserEvent) {
+ var map = mapBrowserEvent.map;
if (!map.isDef()) {
return true;
}
var pass = true;
- if (event.type === ol.MapBrowserEvent.EventType.POINTERMOVE) {
- pass = this.handlePointerMove_(event);
- } else if (event.type === ol.MapBrowserEvent.EventType.DBLCLICK) {
+ if (mapBrowserEvent.type === ol.MapBrowserEvent.EventType.POINTERMOVE) {
+ pass = this.handlePointerMove_(mapBrowserEvent);
+ } else if (mapBrowserEvent.type === ol.MapBrowserEvent.EventType.DBLCLICK) {
pass = false;
}
- return (goog.base(this, 'handleMapBrowserEvent', event) && pass);
+ return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) && pass;
};
diff --git a/src/ol/interaction/interaction.js b/src/ol/interaction/interaction.js
index 76b15d261b..3db0a9c405 100644
--- a/src/ol/interaction/interaction.js
+++ b/src/ol/interaction/interaction.js
@@ -32,11 +32,11 @@ ol.interaction.InteractionProperty = {
* vectors and so are visible on the screen.
*
* @constructor
+ * @param {olx.interaction.InteractionOptions} options Options.
* @extends {ol.Object}
- * @implements {oli.interaction.Interaction}
* @api
*/
-ol.interaction.Interaction = function() {
+ol.interaction.Interaction = function(options) {
goog.base(this);
@@ -48,6 +48,11 @@ ol.interaction.Interaction = function() {
this.setActive(true);
+ /**
+ * @type {function(ol.MapBrowserEvent):boolean}
+ */
+ this.handleEvent = options.handleEvent;
+
};
goog.inherits(ol.interaction.Interaction, ol.Object);
@@ -76,22 +81,6 @@ ol.interaction.Interaction.prototype.getMap = function() {
};
-/**
- * Method called by the map to notify the interaction that a browser
- * event was dispatched on the map. If the interaction wants to handle
- * that event it can return `false` to prevent the propagation of the
- * event to other interactions in the map's interactions chain.
- * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
- * @return {boolean} Whether the map browser event should continue
- * through the chain of interactions. `false` means stop, `true`
- * means continue.
- * @function
- * @api
- */
-ol.interaction.Interaction.prototype.handleMapBrowserEvent =
- goog.abstractMethod;
-
-
/**
* Activate or deactivate the interaction.
* @param {boolean} active Active.
diff --git a/src/ol/interaction/keyboardpaninteraction.js b/src/ol/interaction/keyboardpaninteraction.js
index 62dab76038..9cfee2d707 100644
--- a/src/ol/interaction/keyboardpaninteraction.js
+++ b/src/ol/interaction/keyboardpaninteraction.js
@@ -31,7 +31,9 @@ goog.require('ol.interaction.Interaction');
*/
ol.interaction.KeyboardPan = function(opt_options) {
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.KeyboardPan.handleEvent
+ });
var options = goog.isDef(opt_options) ? opt_options : {};
@@ -54,10 +56,12 @@ goog.inherits(ol.interaction.KeyboardPan, ol.interaction.Interaction);
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.KeyboardPan}
+ * @api
*/
-ol.interaction.KeyboardPan.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
var keyEvent = /** @type {goog.events.KeyEvent} */
diff --git a/src/ol/interaction/keyboardzoominteraction.js b/src/ol/interaction/keyboardzoominteraction.js
index a629ae8ff8..b76f8a0587 100644
--- a/src/ol/interaction/keyboardzoominteraction.js
+++ b/src/ol/interaction/keyboardzoominteraction.js
@@ -27,7 +27,9 @@ goog.require('ol.interaction.Interaction');
*/
ol.interaction.KeyboardZoom = function(opt_options) {
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.KeyboardZoom.handleEvent
+ });
var options = goog.isDef(opt_options) ? opt_options : {};
@@ -55,10 +57,12 @@ goog.inherits(ol.interaction.KeyboardZoom, ol.interaction.Interaction);
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.KeyboardZoom}
+ * @api
*/
-ol.interaction.KeyboardZoom.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.KeyboardZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
var keyEvent = /** @type {goog.events.KeyEvent} */
diff --git a/src/ol/interaction/modifyinteraction.js b/src/ol/interaction/modifyinteraction.js
index 210bff3f68..c8a41d91e9 100644
--- a/src/ol/interaction/modifyinteraction.js
+++ b/src/ol/interaction/modifyinteraction.js
@@ -47,8 +47,9 @@ ol.interaction.SegmentDataType;
*/
ol.interaction.Modify = function(options) {
- goog.base(this);
-
+ goog.base(this, {
+ handleEvent: ol.interaction.Modify.handleEvent
+ });
/**
* @type {ol.events.ConditionType}
@@ -481,10 +482,12 @@ ol.interaction.Modify.prototype.handlePointerUp = function(evt) {
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.Modify}
+ * @api
*/
-ol.interaction.Modify.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
var handled;
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
@@ -496,7 +499,8 @@ ol.interaction.Modify.prototype.handleMapBrowserEvent =
goog.asserts.assertInstanceof(geometry, ol.geom.Point);
handled = this.removeVertex_();
}
- return goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent) && !handled;
+ return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
+ !handled;
};
diff --git a/src/ol/interaction/mousewheelzoominteraction.js b/src/ol/interaction/mousewheelzoominteraction.js
index 0e0f713d18..547ccb577f 100644
--- a/src/ol/interaction/mousewheelzoominteraction.js
+++ b/src/ol/interaction/mousewheelzoominteraction.js
@@ -21,9 +21,11 @@ goog.require('ol.interaction.Interaction');
*/
ol.interaction.MouseWheelZoom = function(opt_options) {
- var options = goog.isDef(opt_options) ? opt_options : {};
+ goog.base(this, {
+ handleEvent: ol.interaction.MouseWheelZoom.handleEvent
+ });
- goog.base(this);
+ var options = goog.isDef(opt_options) ? opt_options : {};
/**
* @private
@@ -60,10 +62,12 @@ goog.inherits(ol.interaction.MouseWheelZoom, ol.interaction.Interaction);
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.MouseWheelZoom}
+ * @api
*/
-ol.interaction.MouseWheelZoom.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
var stopEvent = false;
if (mapBrowserEvent.type ==
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {
diff --git a/src/ol/interaction/pointerinteraction.js b/src/ol/interaction/pointerinteraction.js
index 13123412e5..38ed96fdd6 100644
--- a/src/ol/interaction/pointerinteraction.js
+++ b/src/ol/interaction/pointerinteraction.js
@@ -17,11 +17,19 @@ goog.require('ol.interaction.Interaction');
* instantiated in apps.
*
* @constructor
+ * @param {olx.interaction.PointerOptions=} opt_options Options.
* @extends {ol.interaction.Interaction}
*/
-ol.interaction.Pointer = function() {
+ol.interaction.Pointer = function(opt_options) {
- goog.base(this);
+ var options = goog.isDef(opt_options) ? opt_options : {};
+
+ var handleEvent = goog.isDef(options.handleEvent) ?
+ options.handleEvent : ol.interaction.Pointer.handleEvent;
+
+ goog.base(this, {
+ handleEvent: handleEvent
+ });
/**
* @type {boolean}
@@ -124,10 +132,12 @@ ol.interaction.Pointer.prototype.handlePointerDown = goog.functions.FALSE;
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.Pointer}
+ * @api
*/
-ol.interaction.Pointer.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.Pointer.handleEvent = function(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
return true;
}
diff --git a/src/ol/interaction/selectinteraction.js b/src/ol/interaction/selectinteraction.js
index 86f322f1ef..240d262aea 100644
--- a/src/ol/interaction/selectinteraction.js
+++ b/src/ol/interaction/selectinteraction.js
@@ -28,7 +28,9 @@ goog.require('ol.style.Style');
*/
ol.interaction.Select = function(opt_options) {
- goog.base(this);
+ goog.base(this, {
+ handleEvent: ol.interaction.Select.handleEvent
+ });
var options = goog.isDef(opt_options) ? opt_options : {};
@@ -115,10 +117,12 @@ ol.interaction.Select.prototype.getFeatures = function() {
/**
- * @inheritDoc
+ * @param {ol.MapBrowserEvent} mapBrowserEvent Map browser event.
+ * @return {boolean} `false` to stop event propagation.
+ * @this {ol.interaction.Select}
+ * @api
*/
-ol.interaction.Select.prototype.handleMapBrowserEvent =
- function(mapBrowserEvent) {
+ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
if (!this.condition_(mapBrowserEvent)) {
return true;
}
diff --git a/src/ol/map.js b/src/ol/map.js
index 6905e65eae..4ee6642c5f 100644
--- a/src/ol/map.js
+++ b/src/ol/map.js
@@ -870,7 +870,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
if (!interaction.getActive()) {
continue;
}
- var cont = interaction.handleMapBrowserEvent(mapBrowserEvent);
+ var cont = interaction.handleEvent(mapBrowserEvent);
if (!cont) {
break;
}
diff --git a/test/spec/ol/interaction/interaction.test.js b/test/spec/ol/interaction/interaction.test.js
index 1de7d915bf..bff9c9ee13 100644
--- a/test/spec/ol/interaction/interaction.test.js
+++ b/test/spec/ol/interaction/interaction.test.js
@@ -6,7 +6,7 @@ describe('ol.interaction.Interaction', function() {
var interaction;
beforeEach(function() {
- interaction = new ol.interaction.Interaction();
+ interaction = new ol.interaction.Interaction({});
});
it('creates a new interaction', function() {
@@ -24,13 +24,13 @@ describe('ol.interaction.Interaction', function() {
it('retrieves the associated map', function() {
var map = new ol.Map({});
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('returns null if no map', function() {
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
expect(interaction.getMap()).to.be(null);
});
@@ -40,13 +40,13 @@ describe('ol.interaction.Interaction', function() {
it('allows a map to be set', function() {
var map = new ol.Map({});
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
interaction.setMap(map);
expect(interaction.getMap()).to.be(map);
});
it('accepts null', function() {
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
interaction.setMap(null);
expect(interaction.getMap()).to.be(null);
});
diff --git a/test/spec/ol/map.test.js b/test/spec/ol/map.test.js
index 4aedaf1464..ef6a658606 100644
--- a/test/spec/ol/map.test.js
+++ b/test/spec/ol/map.test.js
@@ -23,7 +23,7 @@ describe('ol.Map', function() {
describe('#addInteraction()', function() {
it('adds an interaction to the map', function() {
var map = new ol.Map({});
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
var before = map.getInteractions().getLength();
map.addInteraction(interaction);
@@ -36,7 +36,7 @@ describe('ol.Map', function() {
describe('#removeInteraction()', function() {
it('removes an interaction from the map', function() {
var map = new ol.Map({});
- var interaction = new ol.interaction.Interaction();
+ var interaction = new ol.interaction.Interaction({});
var before = map.getInteractions().getLength();
map.addInteraction(interaction);