git-svn-id: http://svn.openlayers.org/branches/openlayers/2.2@1786 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
129 lines
3.8 KiB
JavaScript
129 lines
3.8 KiB
JavaScript
/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license.
|
|
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
|
|
* for the full text of the license. */
|
|
|
|
|
|
/**
|
|
* @class
|
|
*
|
|
* @requires OpenLayers/Popup.js
|
|
*/
|
|
OpenLayers.Popup.Anchored = OpenLayers.Class.create();
|
|
OpenLayers.Popup.Anchored.prototype =
|
|
OpenLayers.Class.inherit( OpenLayers.Popup, {
|
|
|
|
/** "lr", "ll", "tr", "tl" - relative position of the popup.
|
|
* @type String */
|
|
relativePosition: null,
|
|
|
|
/** Object which must have expose a 'size' (OpenLayers.Size) and
|
|
* 'offset' (OpenLayers.Pixel)
|
|
* @type Object */
|
|
anchor: null,
|
|
|
|
/**
|
|
* @constructor
|
|
*
|
|
* @param {String} id
|
|
* @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)
|
|
* @param {Boolean} closeBox
|
|
*/
|
|
initialize:function(id, lonlat, size, contentHTML, anchor, closeBox) {
|
|
var newArguments = new Array(id, lonlat, size, contentHTML, closeBox);
|
|
OpenLayers.Popup.prototype.initialize.apply(this, newArguments);
|
|
|
|
this.anchor = (anchor != null) ? anchor
|
|
: { size: new OpenLayers.Size(0,0),
|
|
offset: new OpenLayers.Pixel(0,0)};
|
|
},
|
|
|
|
/**
|
|
* @param {OpenLayers.Pixel} px
|
|
*
|
|
* @returns Reference to a div that contains the drawn popup
|
|
* @type DOMElement
|
|
*/
|
|
draw: function(px) {
|
|
if (px == null) {
|
|
if ((this.lonlat != null) && (this.map != null)) {
|
|
px = this.map.getLayerPxFromLonLat(this.lonlat);
|
|
}
|
|
}
|
|
|
|
//calculate relative position
|
|
this.relativePosition = this.calculateRelativePosition(px);
|
|
|
|
return OpenLayers.Popup.prototype.draw.apply(this, arguments);
|
|
},
|
|
|
|
/**
|
|
* @private
|
|
*
|
|
* @param {OpenLayers.Pixel} px
|
|
*
|
|
* @returns The relative position ("br" "tr" "tl "bl") at which the popup
|
|
* should be placed
|
|
* @type String
|
|
*/
|
|
calculateRelativePosition:function(px) {
|
|
var lonlat = this.map.getLonLatFromLayerPx(px);
|
|
|
|
var extent = this.map.getExtent();
|
|
var quadrant = extent.determineQuadrant(lonlat);
|
|
|
|
return OpenLayers.Bounds.oppositeQuadrant(quadrant);
|
|
},
|
|
|
|
/**
|
|
* @param {OpenLayers.Pixel} px
|
|
*/
|
|
moveTo: function(px) {
|
|
|
|
var newPx = this.calculateNewPx(px);
|
|
|
|
var newArguments = new Array(newPx);
|
|
OpenLayers.Popup.prototype.moveTo.apply(this, newArguments);
|
|
},
|
|
|
|
/**
|
|
* @param {OpenLayers.Size} size
|
|
*/
|
|
setSize:function(size) {
|
|
OpenLayers.Popup.prototype.setSize.apply(this, arguments);
|
|
|
|
if ((this.lonlat) && (this.map)) {
|
|
var px = this.map.getLayerPxFromLonLat(this.lonlat);
|
|
this.moveTo(px);
|
|
}
|
|
},
|
|
|
|
/**
|
|
* @private
|
|
*
|
|
* @param {OpenLayers.Pixel} px
|
|
*
|
|
* @returns The the new px position of the popup on the screen
|
|
* relative to the passed-in px
|
|
* @type OpenLayers.Pixel
|
|
*/
|
|
calculateNewPx:function(px) {
|
|
var newPx = px.offset(this.anchor.offset);
|
|
|
|
var top = (this.relativePosition.charAt(0) == 't');
|
|
newPx.y += (top) ? -this.size.h : this.anchor.size.h;
|
|
|
|
var left = (this.relativePosition.charAt(1) == 'l');
|
|
newPx.x += (left) ? -this.size.w : this.anchor.size.w;
|
|
|
|
return newPx;
|
|
},
|
|
|
|
CLASS_NAME: "OpenLayers.Popup.Anchored"
|
|
});
|