diff --git a/examples/teleport.js b/examples/teleport.js index a83e50308b..c6b942bd12 100644 --- a/examples/teleport.js +++ b/examples/teleport.js @@ -23,6 +23,6 @@ map.setTarget('map1'); var teleportButton = document.getElementById('teleport'); teleportButton.addEventListener('click', function() { - var target = map.getTarget().id === 'map1' ? 'map2' : 'map1'; + var target = map.getTarget() === 'map1' ? 'map2' : 'map1'; map.setTarget(target); }, false); diff --git a/src/ol/control/fullscreencontrol.js b/src/ol/control/fullscreencontrol.js index 60f7fee4e6..45c2f0b7c8 100644 --- a/src/ol/control/fullscreencontrol.js +++ b/src/ol/control/fullscreencontrol.js @@ -80,7 +80,9 @@ ol.control.FullScreen.prototype.handleClick_ = function(browserEvent) { if (goog.dom.fullscreen.isFullScreen()) { goog.dom.fullscreen.exitFullScreen(); } else { - var element = map.getTarget(); + var target = map.getTarget(); + goog.asserts.assert(goog.isDefAndNotNull(target)); + var element = goog.dom.getElement(target); goog.asserts.assert(goog.isDefAndNotNull(element)); if (this.keys_) { goog.dom.fullscreen.requestFullScreenWithKeys(element); diff --git a/src/ol/map.js b/src/ol/map.js index fb59c77adb..f5246fc397 100644 --- a/src/ol/map.js +++ b/src/ol/map.js @@ -220,6 +220,12 @@ ol.Map = function(options) { this.viewport_.className = 'ol-touch'; } + /** + * @private + * @type {Element} + */ + this.target_ = null; + /** * @private * @type {Element} @@ -438,10 +444,11 @@ ol.Map.prototype.getRenderer = function() { /** * Get the element in which this map is rendered. - * @return {Element|undefined} Target. + * @return {Element|string|undefined} Target. */ 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( ol.Map.prototype, @@ -730,15 +737,20 @@ ol.Map.prototype.handleSizeChanged_ = function() { * @private */ ol.Map.prototype.handleTargetChanged_ = function() { - // target may be undefined, null or an Element. If it's not - // an Element we remove the viewport from the DOM. If it's - // an Element we append the viewport element to it. + // target may be undefined, null, a string or an Element. + // 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 an Element we append the viewport element to it. 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_); } else { - goog.asserts.assert(goog.isDefAndNotNull(target)); - goog.dom.appendChild(target, this.viewport_); + goog.dom.appendChild(this.target_, this.viewport_); } this.updateSize(); // updateSize calls setSize, so no need to call this.render @@ -1012,9 +1024,6 @@ goog.exportProperty( * @param {Element|string|undefined} target Target. */ ol.Map.prototype.setTarget = function(target) { - if (goog.isDef(target)) { - target = goog.dom.getElement(target); - } this.set(ol.MapProperty.TARGET, target); }; goog.exportProperty( @@ -1052,12 +1061,11 @@ ol.Map.prototype.unfreezeRendering = function() { * third-party code changes the size of the map viewport. */ ol.Map.prototype.updateSize = function() { - var target = this.getTarget(); - if (goog.isDef(target)) { - var size = goog.style.getSize(target); - this.setSize([size.width, size.height]); - } else { + if (goog.isNull(this.target_)) { this.setSize(undefined); + } else { + var size = goog.style.getSize(this.target_); + this.setSize([size.width, size.height]); } };