Anchored popups now take an 'anchor' item instead of simply an 'anchorSize'. The anchor item should have both a size *and* an offset. Basically it should be an OpenLayers.Icon. If none is passed in, defaults to (0,0) size and offset. Update placement calculation to adjust for size AND offset.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@442 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-29 09:55:04 +00:00
parent b8d6aaed64
commit 5a95469ef0
2 changed files with 23 additions and 8 deletions

View File

@@ -11,8 +11,10 @@ OpenLayers.Popup.Anchored.prototype =
* @type String */
relativePosition: null,
/** @type OpenLayers.Size */
anchorSize: null,
/** Object which must have expose a 'size' (OpenLayers.Size) and
* 'offset' (OpenLayers.Pixel)
* @type Object */
anchor: null,
/**
* @constructor
@@ -21,13 +23,18 @@ OpenLayers.Popup.Anchored.prototype =
* @param {OpenLayers.LonLat} lonlat
* @param {OpenLayers.Size} size
* @param {String} contentHTML
* @param {Object} anchor Object which must expose a
* - 'size' (OpenLayers.Size) and
* - 'offset' (OpenLayers.Pixel)
* (this is generally an OpenLayers.Icon)
*/
initialize:function(id, lonlat, size, contentHTML, anchorSize) {
initialize:function(id, lonlat, size, contentHTML, anchor) {
var newArguments = new Array(id, lonlat, size, contentHTML);
OpenLayers.Popup.prototype.initialize.apply(this, newArguments);
this.anchorSize = (anchorSize != null) ? anchorSize
: new OpenLayers.Size(0,0);
this.anchor = (anchor != null) ? anchor
: { size: new OpenLayers.Size(0,0),
offset: new OpenLayers.Pixel(0,0)};
},
/**
@@ -102,11 +109,15 @@ OpenLayers.Popup.Anchored.prototype =
calculateNewPx:function(px) {
var newPx = px.copyOf();
//adjust for offset
newPx.add(this.anchor.offset.x, this.anchor.offset.y);
var top = (this.relativePosition.charAt(0) == 't');
newPx.y += (top) ? -(this.size.h + this.anchorSize.h) : this.anchorSize.h;
newPx.y += (top) ? -this.size.h : this.anchor.size.h;
var left = (this.relativePosition.charAt(1) == 'l');
newPx.x += (left) ? -(this.size.w + this.anchorSize.w) : this.anchorSize.w;
newPx.x += (left) ? -this.size.w : this.anchor.size.w;
return newPx;
},

View File

@@ -22,8 +22,12 @@ OpenLayers.Popup.AnchoredBubble.prototype =
* @param {OpenLayers.LonLat} lonlat
* @param {OpenLayers.Size} size
* @param {String} contentHTML
* @param {Object} anchor Object which must expose a
* - 'size' (OpenLayers.Size) and
* - 'offset' (OpenLayers.Pixel)
* (this is generally an OpenLayers.Icon)
*/
initialize:function(id, lonlat, size, contentHTML, anchorSize) {
initialize:function(id, lonlat, size, contentHTML, anchor) {
OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
},