From 5a95469ef0116cc52b8ee5480b2063d166e93442 Mon Sep 17 00:00:00 2001 From: euzuro Date: Mon, 29 May 2006 09:55:04 +0000 Subject: [PATCH] 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 --- lib/OpenLayers/Popup/Anchored.js | 25 ++++++++++++++++++------- lib/OpenLayers/Popup/AnchoredBubble.js | 6 +++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/lib/OpenLayers/Popup/Anchored.js b/lib/OpenLayers/Popup/Anchored.js index 543c3ec413..9202721be3 100644 --- a/lib/OpenLayers/Popup/Anchored.js +++ b/lib/OpenLayers/Popup/Anchored.js @@ -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; }, diff --git a/lib/OpenLayers/Popup/AnchoredBubble.js b/lib/OpenLayers/Popup/AnchoredBubble.js index 12385ab01e..ccef8a9729 100644 --- a/lib/OpenLayers/Popup/AnchoredBubble.js +++ b/lib/OpenLayers/Popup/AnchoredBubble.js @@ -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); },