diff --git a/externs/olx.js b/externs/olx.js index d58a126bb3..7decb05bfa 100644 --- a/externs/olx.js +++ b/externs/olx.js @@ -802,6 +802,7 @@ olx.control; * tipLabel: (string|undefined), * label: (string|undefined), * collapseLabel: (string|undefined), + * render: (function(ol.MapEvent)|undefined), * target: (Element|undefined)}} * @api */ @@ -865,8 +866,19 @@ olx.control.AttributionOptions.prototype.label; */ 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), + * render: (function(ol.MapEvent)|undefined), * target: (Element|string|undefined)}} * @api stable */ @@ -882,6 +894,15 @@ olx.control.ControlOptions; 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 * viewport. @@ -997,6 +1018,7 @@ olx.control.FullScreenOptions.prototype.target; * @typedef {{className: (string|undefined), * coordinateFormat: (ol.CoordinateFormatType|undefined), * projection: ol.proj.ProjectionLike, + * render: (function(ol.MapEvent)|undefined), * target: (Element|undefined), * undefinedHTML: (string|undefined)}} * @api stable @@ -1028,6 +1050,15 @@ olx.control.MousePositionOptions.prototype.coordinateFormat; 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. * @type {Element|undefined} @@ -1050,6 +1081,7 @@ olx.control.MousePositionOptions.prototype.undefinedHTML; * collapsible: (boolean|undefined), * label: (string|undefined), * layers: (Array.|ol.Collection|undefined), + * render: (function(ol.MapEvent)|undefined), * target: (Element|undefined), * tipLabel: (string|undefined)}} * @api @@ -1099,6 +1131,15 @@ olx.control.OverviewMapOptions.prototype.label; 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 * viewport. @@ -1119,6 +1160,7 @@ olx.control.OverviewMapOptions.prototype.tipLabel; /** * @typedef {{className: (string|undefined), * minWidth: (number|undefined), + * render: (function(ol.MapEvent)|undefined), * target: (Element|undefined), * units: (ol.control.ScaleLineUnits|string|undefined)}} * @api stable @@ -1142,6 +1184,15 @@ olx.control.ScaleLineOptions.prototype.className; 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. * @type {Element|undefined} @@ -1164,6 +1215,7 @@ olx.control.ScaleLineOptions.prototype.units; * label: (string|undefined), * tipLabel: (string|undefined), * target: (Element|undefined), + * render: (function(ol.MapEvent)|undefined), * autoHide: (boolean|undefined)}} * @api stable */ @@ -1210,6 +1262,15 @@ olx.control.RotateOptions.prototype.duration; 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. * @type {Element|undefined} @@ -1299,8 +1360,9 @@ olx.control.ZoomOptions.prototype.target; /** * @typedef {{className: (string|undefined), * maxResolution: (number|undefined), - * minResolution: (number|undefined)}} - * @api stable + * minResolution: (number|undefined), + * render: (function(ol.MapEvent)|undefined)}} + * @api */ olx.control.ZoomSliderOptions; @@ -1329,6 +1391,15 @@ olx.control.ZoomSliderOptions.prototype.maxResolution; 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), * target: (Element|undefined), diff --git a/src/ol/control/attributioncontrol.js b/src/ol/control/attributioncontrol.js index 6953af7843..224f4dc167 100644 --- a/src/ol/control/attributioncontrol.js +++ b/src/ol/control/attributioncontrol.js @@ -113,8 +113,12 @@ ol.control.Attribution = function(opt_options) { var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, this.ulElement_, button); + var render = goog.isDef(options.render) ? + options.render : ol.control.Attribution.render; + goog.base(this, { element: element, + render: render, 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); }; diff --git a/src/ol/control/control.js b/src/ol/control/control.js index 1695780971..73ce0e112e 100644 --- a/src/ol/control/control.js +++ b/src/ol/control/control.js @@ -66,6 +66,11 @@ ol.control.Control = function(options) { */ this.listenerKeys = []; + /** + * @type {function(ol.MapEvent)} + */ + this.render = goog.isDef(options.render) ? options.render : goog.nullFunction; + }; 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. * 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_) ? this.target_ : map.getOverlayContainerStopEvent(); goog.dom.appendChild(target, this.element); - if (this.handleMapPostrender !== goog.nullFunction) { + if (this.render !== goog.nullFunction) { this.listenerKeys.push(goog.events.listen(map, - ol.MapEventType.POSTRENDER, this.handleMapPostrender, false, this)); + ol.MapEventType.POSTRENDER, this.render, false, this)); } map.render(); } diff --git a/src/ol/control/mousepositioncontrol.js b/src/ol/control/mousepositioncontrol.js index 110f59a58e..ef558344aa 100644 --- a/src/ol/control/mousepositioncontrol.js +++ b/src/ol/control/mousepositioncontrol.js @@ -47,8 +47,12 @@ ol.control.MousePosition = function(opt_options) { 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, { element: element, + render: render, 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; if (goog.isNull(frameState)) { this.mapProjection_ = null; diff --git a/src/ol/control/overviewmapcontrol.js b/src/ol/control/overviewmapcontrol.js index a7b5abcdae..628bdc77a1 100644 --- a/src/ol/control/overviewmapcontrol.js +++ b/src/ol/control/overviewmapcontrol.js @@ -136,8 +136,12 @@ ol.control.OverviewMap = function(opt_options) { var element = goog.dom.createDom(goog.dom.TagName.DIV, cssClasses, ovmapDiv, button); + var render = goog.isDef(options.render) ? + options.render : ol.control.OverviewMap.render; + goog.base(this, { element: element, + render: render, target: options.target }); }; @@ -201,12 +205,11 @@ ol.control.OverviewMap.prototype.bindView_ = function() { /** - * Function called on each map render. Executes in a requestAnimationFrame - * callback. Manage the extent of the overview map accordingly, - * then update the overview map box. - * @param {goog.events.Event} event Event. + * @param {ol.MapEvent} mapEvent Map event. + * @this {ol.control.OverviewMap} + * @api */ -ol.control.OverviewMap.prototype.handleMapPostrender = function(event) { +ol.control.OverviewMap.render = function(mapEvent) { this.validateExtent_(); this.updateBox_(); }; diff --git a/src/ol/control/rotatecontrol.js b/src/ol/control/rotatecontrol.js index 8f70495f83..4073063fe7 100644 --- a/src/ol/control/rotatecontrol.js +++ b/src/ol/control/rotatecontrol.js @@ -62,8 +62,12 @@ ol.control.Rotate = function(opt_options) { ol.css.CLASS_CONTROL; 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, { element: element, + render: render, 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; if (goog.isNull(frameState)) { return; diff --git a/src/ol/control/scalelinecontrol.js b/src/ol/control/scalelinecontrol.js index cf2777df2b..6ef6e4cc28 100644 --- a/src/ol/control/scalelinecontrol.js +++ b/src/ol/control/scalelinecontrol.js @@ -112,8 +112,12 @@ ol.control.ScaleLine = function(opt_options) { */ this.toEPSG4326_ = null; + var render = goog.isDef(options.render) ? + options.render : ol.control.ScaleLine.render; + goog.base(this, { element: this.element_, + render: render, 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; if (goog.isNull(frameState)) { this.viewState_ = null; diff --git a/src/ol/control/zoomslidercontrol.js b/src/ol/control/zoomslidercontrol.js index 2bac8ca4c0..a2fb2162f5 100644 --- a/src/ol/control/zoomslidercontrol.js +++ b/src/ol/control/zoomslidercontrol.js @@ -100,8 +100,12 @@ ol.control.ZoomSlider = function(opt_options) { goog.events.listen(thumbElement, goog.events.EventType.CLICK, goog.events.Event.stopPropagation); + var render = goog.isDef(options.render) ? + options.render : ol.control.ZoomSlider.render; + goog.base(this, { - element: containerElement + element: containerElement, + render: render }); }; 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)) { return; }