Skip to content

Commit

Permalink
incorporate review from @ahocevar and @chrismayer
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van den Eijnden committed Mar 21, 2012
1 parent 87d2d4d commit fa884d3
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions lib/GeoExt/widgets/Popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
},

Expand Down

0 comments on commit fa884d3

Please # to comment.