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:
@@ -11,8 +11,10 @@ OpenLayers.Popup.Anchored.prototype =
|
|||||||
* @type String */
|
* @type String */
|
||||||
relativePosition: null,
|
relativePosition: null,
|
||||||
|
|
||||||
/** @type OpenLayers.Size */
|
/** Object which must have expose a 'size' (OpenLayers.Size) and
|
||||||
anchorSize: null,
|
* 'offset' (OpenLayers.Pixel)
|
||||||
|
* @type Object */
|
||||||
|
anchor: null,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
@@ -21,13 +23,18 @@ OpenLayers.Popup.Anchored.prototype =
|
|||||||
* @param {OpenLayers.LonLat} lonlat
|
* @param {OpenLayers.LonLat} lonlat
|
||||||
* @param {OpenLayers.Size} size
|
* @param {OpenLayers.Size} size
|
||||||
* @param {String} contentHTML
|
* @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);
|
var newArguments = new Array(id, lonlat, size, contentHTML);
|
||||||
OpenLayers.Popup.prototype.initialize.apply(this, newArguments);
|
OpenLayers.Popup.prototype.initialize.apply(this, newArguments);
|
||||||
|
|
||||||
this.anchorSize = (anchorSize != null) ? anchorSize
|
this.anchor = (anchor != null) ? anchor
|
||||||
: new OpenLayers.Size(0,0);
|
: { size: new OpenLayers.Size(0,0),
|
||||||
|
offset: new OpenLayers.Pixel(0,0)};
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,11 +109,15 @@ OpenLayers.Popup.Anchored.prototype =
|
|||||||
calculateNewPx:function(px) {
|
calculateNewPx:function(px) {
|
||||||
var newPx = px.copyOf();
|
var newPx = px.copyOf();
|
||||||
|
|
||||||
|
//adjust for offset
|
||||||
|
newPx.add(this.anchor.offset.x, this.anchor.offset.y);
|
||||||
|
|
||||||
|
|
||||||
var top = (this.relativePosition.charAt(0) == 't');
|
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');
|
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;
|
return newPx;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -22,8 +22,12 @@ OpenLayers.Popup.AnchoredBubble.prototype =
|
|||||||
* @param {OpenLayers.LonLat} lonlat
|
* @param {OpenLayers.LonLat} lonlat
|
||||||
* @param {OpenLayers.Size} size
|
* @param {OpenLayers.Size} size
|
||||||
* @param {String} contentHTML
|
* @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);
|
OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user