Merge pull request #3032 from elemoine/custom-components

Extension points for custom controls and interactions
This commit is contained in:
Éric Lemoine
2014-12-15 13:41:56 +01:00
23 changed files with 270 additions and 117 deletions

View File

@@ -137,22 +137,6 @@ oli.control.Control.prototype.setMap = function(map) {};
oli.interaction; 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 * @interface
*/ */

View File

@@ -172,6 +172,25 @@ olx.GraticuleOptions.prototype.strokeStyle;
olx.GraticuleOptions.prototype.targetSize; 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. * Object literal with config options for the map.
* @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined), * @typedef {{controls: (ol.Collection.<ol.control.Control>|Array.<ol.control.Control>|undefined),
@@ -802,6 +821,7 @@ olx.control;
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* label: (string|undefined), * label: (string|undefined),
* collapseLabel: (string|undefined), * collapseLabel: (string|undefined),
* render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined)}} * target: (Element|undefined)}}
* @api * @api
*/ */
@@ -865,8 +885,19 @@ olx.control.AttributionOptions.prototype.label;
*/ */
olx.control.AttributionOptions.prototype.collapseLabel; olx.control.AttributionOptions.prototype.collapseLabel;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.AttributionOptions.prototype.render;
/** /**
* @typedef {{element: (Element|undefined), * @typedef {{element: (Element|undefined),
* render: (function(ol.MapEvent)|undefined),
* target: (Element|string|undefined)}} * target: (Element|string|undefined)}}
* @api stable * @api stable
*/ */
@@ -882,6 +913,15 @@ olx.control.ControlOptions;
olx.control.ControlOptions.prototype.element; olx.control.ControlOptions.prototype.element;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.ControlOptions.prototype.render;
/** /**
* Specify a target if you want the control to be rendered outside of the map's * Specify a target if you want the control to be rendered outside of the map's
* viewport. * viewport.
@@ -997,6 +1037,7 @@ olx.control.FullScreenOptions.prototype.target;
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* coordinateFormat: (ol.CoordinateFormatType|undefined), * coordinateFormat: (ol.CoordinateFormatType|undefined),
* projection: ol.proj.ProjectionLike, * projection: ol.proj.ProjectionLike,
* render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* undefinedHTML: (string|undefined)}} * undefinedHTML: (string|undefined)}}
* @api stable * @api stable
@@ -1028,6 +1069,15 @@ olx.control.MousePositionOptions.prototype.coordinateFormat;
olx.control.MousePositionOptions.prototype.projection; olx.control.MousePositionOptions.prototype.projection;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.MousePositionOptions.prototype.render;
/** /**
* Target. * Target.
* @type {Element|undefined} * @type {Element|undefined}
@@ -1050,6 +1100,7 @@ olx.control.MousePositionOptions.prototype.undefinedHTML;
* collapsible: (boolean|undefined), * collapsible: (boolean|undefined),
* label: (string|undefined), * label: (string|undefined),
* layers: (Array.<ol.layer.Layer>|ol.Collection|undefined), * layers: (Array.<ol.layer.Layer>|ol.Collection|undefined),
* render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* tipLabel: (string|undefined)}} * tipLabel: (string|undefined)}}
* @api * @api
@@ -1099,6 +1150,15 @@ olx.control.OverviewMapOptions.prototype.label;
olx.control.OverviewMapOptions.prototype.layers; olx.control.OverviewMapOptions.prototype.layers;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.OverviewMapOptions.prototype.render;
/** /**
* Specify a target if you want the control to be rendered outside of the map's * Specify a target if you want the control to be rendered outside of the map's
* viewport. * viewport.
@@ -1119,6 +1179,7 @@ olx.control.OverviewMapOptions.prototype.tipLabel;
/** /**
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* minWidth: (number|undefined), * minWidth: (number|undefined),
* render: (function(ol.MapEvent)|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* units: (ol.control.ScaleLineUnits|string|undefined)}} * units: (ol.control.ScaleLineUnits|string|undefined)}}
* @api stable * @api stable
@@ -1142,6 +1203,15 @@ olx.control.ScaleLineOptions.prototype.className;
olx.control.ScaleLineOptions.prototype.minWidth; olx.control.ScaleLineOptions.prototype.minWidth;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.ScaleLineOptions.prototype.render;
/** /**
* Target. * Target.
* @type {Element|undefined} * @type {Element|undefined}
@@ -1164,6 +1234,7 @@ olx.control.ScaleLineOptions.prototype.units;
* label: (string|undefined), * label: (string|undefined),
* tipLabel: (string|undefined), * tipLabel: (string|undefined),
* target: (Element|undefined), * target: (Element|undefined),
* render: (function(ol.MapEvent)|undefined),
* autoHide: (boolean|undefined)}} * autoHide: (boolean|undefined)}}
* @api stable * @api stable
*/ */
@@ -1210,6 +1281,15 @@ olx.control.RotateOptions.prototype.duration;
olx.control.RotateOptions.prototype.autoHide; olx.control.RotateOptions.prototype.autoHide;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.RotateOptions.prototype.render;
/** /**
* Target. * Target.
* @type {Element|undefined} * @type {Element|undefined}
@@ -1299,8 +1379,9 @@ olx.control.ZoomOptions.prototype.target;
/** /**
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* maxResolution: (number|undefined), * maxResolution: (number|undefined),
* minResolution: (number|undefined)}} * minResolution: (number|undefined),
* @api stable * render: (function(ol.MapEvent)|undefined)}}
* @api
*/ */
olx.control.ZoomSliderOptions; olx.control.ZoomSliderOptions;
@@ -1329,6 +1410,15 @@ olx.control.ZoomSliderOptions.prototype.maxResolution;
olx.control.ZoomSliderOptions.prototype.minResolution; olx.control.ZoomSliderOptions.prototype.minResolution;
/**
* Function called when the control should be re-rendered. This is called
* in a requestAnimationFrame callback.
* @type {function(ol.MapEvent)|undefined}
* @api
*/
olx.control.ZoomSliderOptions.prototype.render;
/** /**
* @typedef {{className: (string|undefined), * @typedef {{className: (string|undefined),
* target: (Element|undefined), * target: (Element|undefined),
@@ -2339,6 +2429,24 @@ olx.interaction.PinchZoomOptions;
olx.interaction.PinchZoomOptions.prototype.duration; 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), * @typedef {{addCondition: (ol.events.ConditionType|undefined),
* condition: (ol.events.ConditionType|undefined), * condition: (ol.events.ConditionType|undefined),

View File

@@ -113,8 +113,12 @@ ol.control.Attribution = function(opt_options) {
var element = goog.dom.createDom(goog.dom.TagName.DIV, var element = goog.dom.createDom(goog.dom.TagName.DIV,
cssClasses, this.ulElement_, button); cssClasses, this.ulElement_, button);
var render = goog.isDef(options.render) ?
options.render : ol.control.Attribution.render;
goog.base(this, { goog.base(this, {
element: element, element: element,
render: render,
target: options.target target: options.target
}); });
@@ -192,9 +196,11 @@ ol.control.Attribution.prototype.getSourceAttributions = function(frameState) {
/** /**
* @inheritDoc * @param {ol.MapEvent} mapEvent Map event.
* @this {ol.control.Attribution}
* @api
*/ */
ol.control.Attribution.prototype.handleMapPostrender = function(mapEvent) { ol.control.Attribution.render = function(mapEvent) {
this.updateElement_(mapEvent.frameState); this.updateElement_(mapEvent.frameState);
}; };

View File

@@ -66,6 +66,11 @@ ol.control.Control = function(options) {
*/ */
this.listenerKeys = []; this.listenerKeys = [];
/**
* @type {function(ol.MapEvent)}
*/
this.render = goog.isDef(options.render) ? options.render : goog.nullFunction;
}; };
goog.inherits(ol.control.Control, ol.Object); goog.inherits(ol.control.Control, ol.Object);
@@ -89,15 +94,6 @@ ol.control.Control.prototype.getMap = function() {
}; };
/**
* Function called on each map render. Executes in a requestAnimationFrame
* callback. Can be implemented in sub-classes to re-render the control's
* UI.
* @param {ol.MapEvent} mapEvent Map event.
*/
ol.control.Control.prototype.handleMapPostrender = goog.nullFunction;
/** /**
* Remove the control from its current map and attach it to the new map. * Remove the control from its current map and attach it to the new map.
* Subclasses may set up event handlers to get notified about changes to * Subclasses may set up event handlers to get notified about changes to
@@ -118,9 +114,9 @@ ol.control.Control.prototype.setMap = function(map) {
var target = !goog.isNull(this.target_) ? var target = !goog.isNull(this.target_) ?
this.target_ : map.getOverlayContainerStopEvent(); this.target_ : map.getOverlayContainerStopEvent();
goog.dom.appendChild(target, this.element); goog.dom.appendChild(target, this.element);
if (this.handleMapPostrender !== goog.nullFunction) { if (this.render !== goog.nullFunction) {
this.listenerKeys.push(goog.events.listen(map, this.listenerKeys.push(goog.events.listen(map,
ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this)); ol.MapEventType.POSTRENDER, this.render, false, this));
} }
map.render(); map.render();
} }

View File

@@ -47,8 +47,12 @@ ol.control.MousePosition = function(opt_options) {
var element = goog.dom.createDom(goog.dom.TagName.DIV, className); var element = goog.dom.createDom(goog.dom.TagName.DIV, className);
var render = goog.isDef(options.render) ?
options.render : ol.control.MousePosition.render;
goog.base(this, { goog.base(this, {
element: element, element: element,
render: render,
target: options.target target: options.target
}); });
@@ -99,9 +103,11 @@ goog.inherits(ol.control.MousePosition, ol.control.Control);
/** /**
* @inheritDoc * @param {ol.MapEvent} mapEvent Map event.
* @this {ol.control.MousePosition}
* @api
*/ */
ol.control.MousePosition.prototype.handleMapPostrender = function(mapEvent) { ol.control.MousePosition.render = function(mapEvent) {
var frameState = mapEvent.frameState; var frameState = mapEvent.frameState;
if (goog.isNull(frameState)) { if (goog.isNull(frameState)) {
this.mapProjection_ = null; this.mapProjection_ = null;

View File

@@ -136,8 +136,12 @@ ol.control.OverviewMap = function(opt_options) {
var element = goog.dom.createDom(goog.dom.TagName.DIV, var element = goog.dom.createDom(goog.dom.TagName.DIV,
cssClasses, ovmapDiv, button); cssClasses, ovmapDiv, button);
var render = goog.isDef(options.render) ?
options.render : ol.control.OverviewMap.render;
goog.base(this, { goog.base(this, {
element: element, element: element,
render: render,
target: options.target target: options.target
}); });
}; };
@@ -201,12 +205,11 @@ ol.control.OverviewMap.prototype.bindView_ = function() {
/** /**
* Function called on each map render. Executes in a requestAnimationFrame * @param {ol.MapEvent} mapEvent Map event.
* callback. Manage the extent of the overview map accordingly, * @this {ol.control.OverviewMap}
* then update the overview map box. * @api
* @param {goog.events.Event} event Event.
*/ */
ol.control.OverviewMap.prototype.handleMapPostrender = function(event) { ol.control.OverviewMap.render = function(mapEvent) {
this.validateExtent_(); this.validateExtent_();
this.updateBox_(); this.updateBox_();
}; };

View File

@@ -62,8 +62,12 @@ ol.control.Rotate = function(opt_options) {
ol.css.CLASS_CONTROL; ol.css.CLASS_CONTROL;
var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, button); var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, button);
var render = goog.isDef(options.render) ?
options.render : ol.control.Rotate.render;
goog.base(this, { goog.base(this, {
element: element, element: element,
render: render,
target: options.target target: options.target
}); });
@@ -135,9 +139,11 @@ ol.control.Rotate.prototype.resetNorth_ = function() {
/** /**
* @inheritDoc * @param {ol.MapEvent} mapEvent Map event.
* @this {ol.control.Rotate}
* @api
*/ */
ol.control.Rotate.prototype.handleMapPostrender = function(mapEvent) { ol.control.Rotate.render = function(mapEvent) {
var frameState = mapEvent.frameState; var frameState = mapEvent.frameState;
if (goog.isNull(frameState)) { if (goog.isNull(frameState)) {
return; return;

View File

@@ -112,8 +112,12 @@ ol.control.ScaleLine = function(opt_options) {
*/ */
this.toEPSG4326_ = null; this.toEPSG4326_ = null;
var render = goog.isDef(options.render) ?
options.render : ol.control.ScaleLine.render;
goog.base(this, { goog.base(this, {
element: this.element_, element: this.element_,
render: render,
target: options.target target: options.target
}); });
@@ -152,9 +156,11 @@ goog.exportProperty(
/** /**
* @inheritDoc * @param {ol.MapEvent} mapEvent Map event.
* @this {ol.control.ScaleLine}
* @api
*/ */
ol.control.ScaleLine.prototype.handleMapPostrender = function(mapEvent) { ol.control.ScaleLine.render = function(mapEvent) {
var frameState = mapEvent.frameState; var frameState = mapEvent.frameState;
if (goog.isNull(frameState)) { if (goog.isNull(frameState)) {
this.viewState_ = null; this.viewState_ = null;

View File

@@ -100,8 +100,12 @@ ol.control.ZoomSlider = function(opt_options) {
goog.events.listen(thumbElement, goog.events.EventType.CLICK, goog.events.listen(thumbElement, goog.events.EventType.CLICK,
goog.events.Event.stopPropagation); goog.events.Event.stopPropagation);
var render = goog.isDef(options.render) ?
options.render : ol.control.ZoomSlider.render;
goog.base(this, { goog.base(this, {
element: containerElement element: containerElement,
render: render
}); });
}; };
goog.inherits(ol.control.ZoomSlider, ol.control.Control); goog.inherits(ol.control.ZoomSlider, ol.control.Control);
@@ -166,9 +170,11 @@ ol.control.ZoomSlider.prototype.initSlider_ = function() {
/** /**
* @inheritDoc * @param {ol.MapEvent} mapEvent Map event.
* @this {ol.control.ZoomSlider}
* @api
*/ */
ol.control.ZoomSlider.prototype.handleMapPostrender = function(mapEvent) { ol.control.ZoomSlider.render = function(mapEvent) {
if (goog.isNull(mapEvent.frameState)) { if (goog.isNull(mapEvent.frameState)) {
return; return;
} }

View File

@@ -26,7 +26,9 @@ ol.interaction.DoubleClickZoom = function(opt_options) {
*/ */
this.delta_ = goog.isDef(options.delta) ? options.delta : 1; this.delta_ = goog.isDef(options.delta) ? options.delta : 1;
goog.base(this); goog.base(this, {
handleEvent: ol.interaction.DoubleClickZoom.handleEvent
});
/** /**
* @private * @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 = ol.interaction.DoubleClickZoom.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
var stopEvent = false; var stopEvent = false;
var browserEvent = mapBrowserEvent.browserEvent; var browserEvent = mapBrowserEvent.browserEvent;
if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) { if (mapBrowserEvent.type == ol.MapBrowserEvent.EventType.DBLCLICK) {

View File

@@ -29,7 +29,9 @@ ol.interaction.DragAndDrop = function(opt_options) {
var options = goog.isDef(opt_options) ? opt_options : {}; var options = goog.isDef(opt_options) ? opt_options : {};
goog.base(this); goog.base(this, {
handleEvent: ol.interaction.DragAndDrop.handleEvent
});
/** /**
* @private * @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 = ol.interaction.DragAndDrop.handleEvent = goog.functions.TRUE;
goog.functions.TRUE;
/** /**

View File

@@ -85,7 +85,9 @@ goog.inherits(ol.DrawEvent, goog.events.Event);
*/ */
ol.interaction.Draw = function(options) { ol.interaction.Draw = function(options) {
goog.base(this); goog.base(this, {
handleEvent: ol.interaction.Draw.handleEvent
});
/** /**
* @type {ol.Pixel} * @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) { ol.interaction.Draw.handleEvent = function(mapBrowserEvent) {
var map = event.map; var map = mapBrowserEvent.map;
if (!map.isDef()) { if (!map.isDef()) {
return true; return true;
} }
var pass = true; var pass = true;
if (event.type === ol.MapBrowserEvent.EventType.POINTERMOVE) { if (mapBrowserEvent.type === ol.MapBrowserEvent.EventType.POINTERMOVE) {
pass = this.handlePointerMove_(event); pass = this.handlePointerMove_(mapBrowserEvent);
} else if (event.type === ol.MapBrowserEvent.EventType.DBLCLICK) { } else if (mapBrowserEvent.type === ol.MapBrowserEvent.EventType.DBLCLICK) {
pass = false; pass = false;
} }
return (goog.base(this, 'handleMapBrowserEvent', event) && pass); return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) && pass;
}; };

View File

@@ -32,11 +32,11 @@ ol.interaction.InteractionProperty = {
* vectors and so are visible on the screen. * vectors and so are visible on the screen.
* *
* @constructor * @constructor
* @param {olx.interaction.InteractionOptions} options Options.
* @extends {ol.Object} * @extends {ol.Object}
* @implements {oli.interaction.Interaction}
* @api * @api
*/ */
ol.interaction.Interaction = function() { ol.interaction.Interaction = function(options) {
goog.base(this); goog.base(this);
@@ -48,6 +48,11 @@ ol.interaction.Interaction = function() {
this.setActive(true); this.setActive(true);
/**
* @type {function(ol.MapBrowserEvent):boolean}
*/
this.handleEvent = options.handleEvent;
}; };
goog.inherits(ol.interaction.Interaction, ol.Object); 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. * Activate or deactivate the interaction.
* @param {boolean} active Active. * @param {boolean} active Active.

View File

@@ -31,7 +31,9 @@ goog.require('ol.interaction.Interaction');
*/ */
ol.interaction.KeyboardPan = function(opt_options) { 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 : {}; 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 = ol.interaction.KeyboardPan.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
var stopEvent = false; var stopEvent = false;
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) { if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
var keyEvent = /** @type {goog.events.KeyEvent} */ var keyEvent = /** @type {goog.events.KeyEvent} */

View File

@@ -27,7 +27,9 @@ goog.require('ol.interaction.Interaction');
*/ */
ol.interaction.KeyboardZoom = function(opt_options) { 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 : {}; 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 = ol.interaction.KeyboardZoom.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
var stopEvent = false; var stopEvent = false;
if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) { if (mapBrowserEvent.type == goog.events.KeyHandler.EventType.KEY) {
var keyEvent = /** @type {goog.events.KeyEvent} */ var keyEvent = /** @type {goog.events.KeyEvent} */

View File

@@ -47,8 +47,9 @@ ol.interaction.SegmentDataType;
*/ */
ol.interaction.Modify = function(options) { ol.interaction.Modify = function(options) {
goog.base(this); goog.base(this, {
handleEvent: ol.interaction.Modify.handleEvent
});
/** /**
* @type {ol.events.ConditionType} * @type {ol.events.ConditionType}
@@ -485,10 +486,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 = ol.interaction.Modify.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
var handled; var handled;
if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] && if (!mapBrowserEvent.map.getView().getHints()[ol.ViewHint.INTERACTING] &&
mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) { mapBrowserEvent.type == ol.MapBrowserEvent.EventType.POINTERMOVE) {
@@ -500,7 +503,8 @@ ol.interaction.Modify.prototype.handleMapBrowserEvent =
goog.asserts.assertInstanceof(geometry, ol.geom.Point); goog.asserts.assertInstanceof(geometry, ol.geom.Point);
handled = this.removeVertex_(); handled = this.removeVertex_();
} }
return goog.base(this, 'handleMapBrowserEvent', mapBrowserEvent) && !handled; return ol.interaction.Pointer.handleEvent.call(this, mapBrowserEvent) &&
!handled;
}; };

View File

@@ -21,9 +21,11 @@ goog.require('ol.interaction.Interaction');
*/ */
ol.interaction.MouseWheelZoom = function(opt_options) { 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 * @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 = ol.interaction.MouseWheelZoom.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
var stopEvent = false; var stopEvent = false;
if (mapBrowserEvent.type == if (mapBrowserEvent.type ==
goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) { goog.events.MouseWheelHandler.EventType.MOUSEWHEEL) {

View File

@@ -17,11 +17,19 @@ goog.require('ol.interaction.Interaction');
* instantiated in apps. * instantiated in apps.
* *
* @constructor * @constructor
* @param {olx.interaction.PointerOptions=} opt_options Options.
* @extends {ol.interaction.Interaction} * @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} * @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 = ol.interaction.Pointer.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) { if (!(mapBrowserEvent instanceof ol.MapBrowserPointerEvent)) {
return true; return true;
} }

View File

@@ -28,7 +28,9 @@ goog.require('ol.style.Style');
*/ */
ol.interaction.Select = function(opt_options) { 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 : {}; 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 = ol.interaction.Select.handleEvent = function(mapBrowserEvent) {
function(mapBrowserEvent) {
if (!this.condition_(mapBrowserEvent)) { if (!this.condition_(mapBrowserEvent)) {
return true; return true;
} }

View File

@@ -870,7 +870,7 @@ ol.Map.prototype.handleMapBrowserEvent = function(mapBrowserEvent) {
if (!interaction.getActive()) { if (!interaction.getActive()) {
continue; continue;
} }
var cont = interaction.handleMapBrowserEvent(mapBrowserEvent); var cont = interaction.handleEvent(mapBrowserEvent);
if (!cont) { if (!cont) {
break; break;
} }

View File

@@ -256,7 +256,7 @@ ol.Overlay.prototype.handleMapChanged = function() {
var map = this.getMap(); var map = this.getMap();
if (goog.isDefAndNotNull(map)) { if (goog.isDefAndNotNull(map)) {
this.mapPostrenderListenerKey_ = goog.events.listen(map, this.mapPostrenderListenerKey_ = goog.events.listen(map,
ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this); ol.MapEventType.POSTRENDER, this.render, false, this);
this.updatePixelPosition_(); this.updatePixelPosition_();
var container = this.stopEvent_ ? var container = this.stopEvent_ ?
map.getOverlayContainerStopEvent() : map.getOverlayContainer(); map.getOverlayContainerStopEvent() : map.getOverlayContainer();
@@ -273,7 +273,7 @@ ol.Overlay.prototype.handleMapChanged = function() {
/** /**
* @protected * @protected
*/ */
ol.Overlay.prototype.handleMapPostrender = function() { ol.Overlay.prototype.render = function() {
this.updatePixelPosition_(); this.updatePixelPosition_();
}; };

View File

@@ -6,7 +6,7 @@ describe('ol.interaction.Interaction', function() {
var interaction; var interaction;
beforeEach(function() { beforeEach(function() {
interaction = new ol.interaction.Interaction(); interaction = new ol.interaction.Interaction({});
}); });
it('creates a new interaction', function() { it('creates a new interaction', function() {
@@ -24,13 +24,13 @@ describe('ol.interaction.Interaction', function() {
it('retrieves the associated map', function() { it('retrieves the associated map', function() {
var map = new ol.Map({}); var map = new ol.Map({});
var interaction = new ol.interaction.Interaction(); var interaction = new ol.interaction.Interaction({});
interaction.setMap(map); interaction.setMap(map);
expect(interaction.getMap()).to.be(map); expect(interaction.getMap()).to.be(map);
}); });
it('returns null if no map', function() { 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); expect(interaction.getMap()).to.be(null);
}); });
@@ -40,13 +40,13 @@ describe('ol.interaction.Interaction', function() {
it('allows a map to be set', function() { it('allows a map to be set', function() {
var map = new ol.Map({}); var map = new ol.Map({});
var interaction = new ol.interaction.Interaction(); var interaction = new ol.interaction.Interaction({});
interaction.setMap(map); interaction.setMap(map);
expect(interaction.getMap()).to.be(map); expect(interaction.getMap()).to.be(map);
}); });
it('accepts null', function() { it('accepts null', function() {
var interaction = new ol.interaction.Interaction(); var interaction = new ol.interaction.Interaction({});
interaction.setMap(null); interaction.setMap(null);
expect(interaction.getMap()).to.be(null); expect(interaction.getMap()).to.be(null);
}); });

View File

@@ -23,7 +23,7 @@ describe('ol.Map', function() {
describe('#addInteraction()', function() { describe('#addInteraction()', function() {
it('adds an interaction to the map', function() { it('adds an interaction to the map', function() {
var map = new ol.Map({}); var map = new ol.Map({});
var interaction = new ol.interaction.Interaction(); var interaction = new ol.interaction.Interaction({});
var before = map.getInteractions().getLength(); var before = map.getInteractions().getLength();
map.addInteraction(interaction); map.addInteraction(interaction);
@@ -36,7 +36,7 @@ describe('ol.Map', function() {
describe('#removeInteraction()', function() { describe('#removeInteraction()', function() {
it('removes an interaction from the map', function() { it('removes an interaction from the map', function() {
var map = new ol.Map({}); var map = new ol.Map({});
var interaction = new ol.interaction.Interaction(); var interaction = new ol.interaction.Interaction({});
var before = map.getInteractions().getLength(); var before = map.getInteractions().getLength();
map.addInteraction(interaction); map.addInteraction(interaction);