Perform ol.Map#setTarget string-to-Element conversion in event handler
With this change, ol.Map#setTarget no longer changes the type of the value passed to it.
This commit is contained in:
@@ -220,6 +220,12 @@ ol.Map = function(options) {
|
|||||||
this.viewport_.className = 'ol-touch';
|
this.viewport_.className = 'ol-touch';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
* @type {Element}
|
||||||
|
*/
|
||||||
|
this.target_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {Element}
|
* @type {Element}
|
||||||
@@ -451,10 +457,11 @@ ol.Map.prototype.getRenderer = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the element in which this map is rendered.
|
* Get the element in which this map is rendered.
|
||||||
* @return {Element|undefined} Target.
|
* @return {Element|string|undefined} Target.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.getTarget = function() {
|
ol.Map.prototype.getTarget = function() {
|
||||||
return /** @type {Element|undefined} */ (this.get(ol.MapProperty.TARGET));
|
return /** @type {Element|string|undefined} */ (
|
||||||
|
this.get(ol.MapProperty.TARGET));
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
ol.Map.prototype,
|
ol.Map.prototype,
|
||||||
@@ -743,15 +750,20 @@ ol.Map.prototype.handleSizeChanged_ = function() {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.handleTargetChanged_ = function() {
|
ol.Map.prototype.handleTargetChanged_ = function() {
|
||||||
// target may be undefined, null or an Element. If it's not
|
// target may be undefined, null, a string or an Element.
|
||||||
// an Element we remove the viewport from the DOM. If it's
|
// If it's a string we convert it to an Element before proceeding.
|
||||||
// an Element we append the viewport element to it.
|
// If it's not now an Element we remove the viewport from the DOM.
|
||||||
|
// If it's an Element we append the viewport element to it.
|
||||||
var target = this.getTarget();
|
var target = this.getTarget();
|
||||||
if (!goog.dom.isElement(target)) {
|
if (goog.isDef(target)) {
|
||||||
|
this.target_ = goog.dom.getElement(target);
|
||||||
|
} else {
|
||||||
|
this.target_ = null;
|
||||||
|
}
|
||||||
|
if (goog.isNull(this.target_)) {
|
||||||
goog.dom.removeNode(this.viewport_);
|
goog.dom.removeNode(this.viewport_);
|
||||||
} else {
|
} else {
|
||||||
goog.asserts.assert(goog.isDefAndNotNull(target));
|
goog.dom.appendChild(this.target_, this.viewport_);
|
||||||
goog.dom.appendChild(target, this.viewport_);
|
|
||||||
}
|
}
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
// updateSize calls setSize, so no need to call this.render
|
// updateSize calls setSize, so no need to call this.render
|
||||||
@@ -1025,9 +1037,6 @@ goog.exportProperty(
|
|||||||
* @param {Element|string|undefined} target Target.
|
* @param {Element|string|undefined} target Target.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.setTarget = function(target) {
|
ol.Map.prototype.setTarget = function(target) {
|
||||||
if (goog.isDef(target)) {
|
|
||||||
target = goog.dom.getElement(target);
|
|
||||||
}
|
|
||||||
this.set(ol.MapProperty.TARGET, target);
|
this.set(ol.MapProperty.TARGET, target);
|
||||||
};
|
};
|
||||||
goog.exportProperty(
|
goog.exportProperty(
|
||||||
@@ -1065,12 +1074,11 @@ ol.Map.prototype.unfreezeRendering = function() {
|
|||||||
* third-party code changes the size of the map viewport.
|
* third-party code changes the size of the map viewport.
|
||||||
*/
|
*/
|
||||||
ol.Map.prototype.updateSize = function() {
|
ol.Map.prototype.updateSize = function() {
|
||||||
var target = this.getTarget();
|
if (goog.isNull(this.target_)) {
|
||||||
if (goog.isDef(target)) {
|
|
||||||
var size = goog.style.getSize(target);
|
|
||||||
this.setSize([size.width, size.height]);
|
|
||||||
} else {
|
|
||||||
this.setSize(undefined);
|
this.setSize(undefined);
|
||||||
|
} else {
|
||||||
|
var size = goog.style.getSize(this.target_);
|
||||||
|
this.setSize([size.width, size.height]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user