From fa884d3df06eef887b60074063b0f8b6891d5af1 Mon Sep 17 00:00:00 2001 From: Bart van den Eijnden Date: Wed, 21 Mar 2012 13:21:45 +0100 Subject: [PATCH] incorporate review from @ahocevar and @chrismayer --- lib/GeoExt/widgets/Popup.js | 78 ++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/lib/GeoExt/widgets/Popup.js b/lib/GeoExt/widgets/Popup.js index 86bdd38a..a16d329a 100644 --- a/lib/GeoExt/widgets/Popup.js +++ b/lib/GeoExt/widgets/Popup.js @@ -154,6 +154,8 @@ GeoExt.Popup = Ext.extend(Ext.Window, { this.location = this.location.getBounds().getCenterLonLat(); } else if (this.location instanceof OpenLayers.Pixel) { this.location = this.map.getLonLatFromViewPortPx(this.location); + } else { + this.anchored = false; } var mapExtent = this.map.getExtent(); @@ -243,48 +245,46 @@ GeoExt.Popup = Ext.extend(Ext.Window, { * Positions the popup relative to its location */ position: function() { - if (this.location) { - if(this._mapMove === true) { - this.insideViewport = this.map.getExtent().containsLonLat(this.location); - if(this.insideViewport !== this.isVisible()) { - this.setVisible(this.insideViewport); - } + if(this._mapMove === true) { + this.insideViewport = this.map.getExtent().containsLonLat(this.location); + if(this.insideViewport !== this.isVisible()) { + this.setVisible(this.insideViewport); + } + } + + if(this.isVisible()) { + var locationPx = this.map.getPixelFromLonLat(this.location), + mapBox = Ext.fly(this.map.div).getBox(true), + top = locationPx.y + mapBox.y, + left = locationPx.x + mapBox.x, + elSize = this.el.getSize(), + ancSize = this.anc.getSize(), + ancPos = this.anchorPosition; + + if (ancPos.indexOf("right") > -1 || locationPx.x > mapBox.width / 2) { + // right + this.anc.addClass("right"); + var ancRight = this.el.getX(true) + elSize.width - + this.anc.getX(true) - ancSize.width; + left -= elSize.width - ancRight - ancSize.width / 2; + } else { + // left + this.anc.removeClass("right"); + var ancLeft = this.anc.getLeft(true); + left -= ancLeft + ancSize.width / 2; } - if(this.isVisible()) { - var locationPx = this.map.getPixelFromLonLat(this.location), - mapBox = Ext.fly(this.map.div).getBox(true), - top = locationPx.y + mapBox.y, - left = locationPx.x + mapBox.x, - elSize = this.el.getSize(), - ancSize = this.anc.getSize(), - ancPos = this.anchorPosition; - - if (ancPos.indexOf("right") > -1 || locationPx.x > mapBox.width / 2) { - // right - this.anc.addClass("right"); - var ancRight = this.el.getX(true) + elSize.width - - this.anc.getX(true) - ancSize.width; - left -= elSize.width - ancRight - ancSize.width / 2; - } else { - // left - this.anc.removeClass("right"); - var ancLeft = this.anc.getLeft(true); - left -= ancLeft + ancSize.width / 2; - } - - if (ancPos.indexOf("bottom") > -1 || locationPx.y > mapBox.height / 2) { - // bottom - this.anc.removeClass("top"); - top -= elSize.height + ancSize.height; - } else { - // top - this.anc.addClass("top"); - top += ancSize.height; // ok - } - - this.setPosition(left, top); + if (ancPos.indexOf("bottom") > -1 || locationPx.y > mapBox.height / 2) { + // bottom + this.anc.removeClass("top"); + top -= elSize.height + ancSize.height; + } else { + // top + this.anc.addClass("top"); + top += ancSize.height; // ok } + + this.setPosition(left, top); } },