Add a "render" control option
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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_();
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user