1 /* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3 * text of the license. */
4 // @require: OpenLayers/Popup.js
\r
9 OpenLayers.Popup.Anchored = Class.create();
\r
10 OpenLayers.Popup.Anchored.prototype =
\r
11 Object.extend( new OpenLayers.Popup(), {
\r
13 /** "lr", "ll", "tr", "tl" - relative position of the popup.
\r
15 relativePosition: null,
\r
17 /** Object which must have expose a 'size' (OpenLayers.Size) and
\r
18 * 'offset' (OpenLayers.Pixel)
\r
25 * @param {String} id
\r
26 * @param {OpenLayers.LonLat} lonlat
\r
27 * @param {OpenLayers.Size} size
\r
28 * @param {String} contentHTML
\r
29 * @param {Object} anchor Object which must expose a
\r
30 * - 'size' (OpenLayers.Size) and
\r
31 * - 'offset' (OpenLayers.Pixel)
\r
32 * (this is generally an OpenLayers.Icon)
\r
34 initialize:function(id, lonlat, size, contentHTML, anchor) {
\r
35 var newArguments = new Array(id, lonlat, size, contentHTML);
\r
36 OpenLayers.Popup.prototype.initialize.apply(this, newArguments);
\r
38 this.anchor = (anchor != null) ? anchor
\r
39 : { size: new OpenLayers.Size(0,0),
\r
40 offset: new OpenLayers.Pixel(0,0)};
\r
44 * @param {OpenLayers.Pixel} px
\r
46 * @returns Reference to a div that contains the drawn popup
\r
49 draw: function(px) {
\r
51 if ((this.lonlat != null) && (this.map != null)) {
\r
52 px = this.map.getLayerPxFromLonLat(this.lonlat);
\r
56 //calculate relative position
\r
57 this.relativePosition = this.calculateRelativePosition(px);
\r
59 return OpenLayers.Popup.prototype.draw.apply(this, arguments);
\r
65 * @param {OpenLayers.Pixel} px
\r
67 * @returns The relative position ("br" "tr" "tl "bl") at which the popup
\r
71 calculateRelativePosition:function(px) {
\r
72 var lonlat = this.map.getLonLatFromLayerPx(px);
\r
74 var extent = this.map.getExtent();
\r
75 var quadrant = extent.determineQuadrant(lonlat);
\r
77 return OpenLayers.Bounds.oppositeQuadrant(quadrant);
\r
81 * @param {OpenLayers.Pixel} px
\r
83 moveTo: function(px) {
\r
85 var newPx = this.calculateNewPx(px);
\r
87 var newArguments = new Array(newPx);
\r
88 OpenLayers.Popup.prototype.moveTo.apply(this, newArguments);
\r
92 * @param {OpenLayers.Size} size
\r
94 setSize:function(size) {
\r
95 OpenLayers.Popup.prototype.setSize.apply(this, arguments);
\r
97 if ((this.lonlat) && (this.map)) {
\r
98 var px = this.map.getLayerPxFromLonLat(this.lonlat);
\r
106 * @param {OpenLayers.Pixel} px
\r
108 * @returns The the new px position of the popup on the screen
\r
109 * relative to the passed-in px
\r
110 * @type OpenLayers.Pixel
\r
112 calculateNewPx:function(px) {
\r
113 var newPx = px.offset(this.anchor.offset);
\r
115 var top = (this.relativePosition.charAt(0) == 't');
\r
116 newPx.y += (top) ? -this.size.h : this.anchor.size.h;
\r
118 var left = (this.relativePosition.charAt(1) == 'l');
\r
119 newPx.x += (left) ? -this.size.w : this.anchor.size.w;
\r
124 CLASS_NAME: "OpenLayers.Popup.Anchored"
\r