No need for ol.Map#target_

This commit is contained in:
Éric Lemoine
2013-09-04 12:08:15 +02:00
parent 9c28d0c112
commit fe1f10e797
+20 -15
View File
@@ -220,12 +220,6 @@ 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}
@@ -741,16 +735,19 @@ ol.Map.prototype.handleTargetChanged_ = function() {
// If it's a string we convert it to an Element before proceeding. // If it's a string we convert it to an Element before proceeding.
// If it's not now an Element we remove the viewport from the DOM. // 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. // If it's an Element we append the viewport element to it.
var target = this.getTarget(); var target = this.getTarget();
if (goog.isDef(target)) {
this.target_ = goog.dom.getElement(target); /**
} else { * @type {Element}
this.target_ = null; */
} var targetElement = goog.isDef(target) ?
if (goog.isNull(this.target_)) { goog.dom.getElement(target) : null;
if (goog.isNull(targetElement)) {
goog.dom.removeNode(this.viewport_); goog.dom.removeNode(this.viewport_);
} else { } else {
goog.dom.appendChild(this.target_, this.viewport_); goog.dom.appendChild(targetElement, 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
@@ -1061,10 +1058,18 @@ 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() {
if (goog.isNull(this.target_)) { var target = this.getTarget();
/**
* @type {Element}
*/
var targetElement = goog.isDef(target) ?
goog.dom.getElement(target) : null;
if (goog.isNull(targetElement)) {
this.setSize(undefined); this.setSize(undefined);
} else { } else {
var size = goog.style.getSize(this.target_); var size = goog.style.getSize(targetElement);
this.setSize([size.width, size.height]); this.setSize([size.width, size.height]);
} }
}; };