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/Anchored.js
\r
9 OpenLayers.Popup.AnchoredBubble = Class.create();
\r
11 //Border space for the rico corners
\r
12 OpenLayers.Popup.AnchoredBubble.CORNER_SIZE = 5;
\r
14 OpenLayers.Popup.AnchoredBubble.prototype =
\r
15 Object.extend( new OpenLayers.Popup.Anchored(), {
\r
17 /** @type DOMElement */
\r
24 * @param {String} id
\r
25 * @param {OpenLayers.LonLat} lonlat
\r
26 * @param {OpenLayers.Size} size
\r
27 * @param {String} contentHTML
\r
28 * @param {Object} anchor Object which must expose a
\r
29 * - 'size' (OpenLayers.Size) and
\r
30 * - 'offset' (OpenLayers.Pixel)
\r
31 * (this is generally an OpenLayers.Icon)
\r
33 initialize:function(id, lonlat, size, contentHTML, anchor) {
\r
34 OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
\r
38 * @param {OpenLayers.Pixel} px
\r
40 * @returns Reference to a div that contains the drawn popup
\r
43 draw: function(px) {
\r
45 OpenLayers.Popup.Anchored.prototype.draw.apply(this, arguments);
\r
47 // make the content Div
\r
48 var contentSize = this.size.copyOf();
\r
49 contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE);
\r
51 var id = this.div.id + "-contentDiv";
\r
52 this.contentDiv = OpenLayers.Util.createDiv(id, null, contentSize,
\r
53 null, "relative", null,
\r
55 this.div.appendChild(this.contentDiv);
\r
56 this.setContentHTML();
\r
58 this.setRicoCorners(true);
\r
60 //set the popup color and opacity
\r
61 this.setBackgroundColor();
\r
68 * @param {OpenLayers.Size} size
\r
70 setSize:function(size) {
\r
71 OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments);
\r
73 if (this.contentDiv != null) {
\r
75 var contentSize = this.size.copyOf();
\r
76 contentSize.h -= (2 * OpenLayers.Popup.AnchoredBubble.CORNER_SIZE);
\r
78 this.contentDiv.style.height = contentSize.h + "px";
\r
80 //size has changed - must redo corners
\r
81 this.setRicoCorners(false);
\r
86 * @param {String} color
\r
88 setBackgroundColor:function(color) {
\r
89 if (color != undefined) {
\r
90 this.backgroundColor = color;
\r
93 if (this.div != null) {
\r
94 if (this.contentDiv != null) {
\r
95 this.div.style.background = "transparent";
\r
96 Rico.Corner.changeColor(this.contentDiv, this.backgroundColor);
\r
102 * @param {float} opacity
\r
104 setOpacity:function(opacity) {
\r
105 if (opacity != undefined) {
\r
106 this.opacity = opacity;
\r
109 if (this.div != null) {
\r
110 if (this.contentDiv != null) {
\r
111 Rico.Corner.changeOpacity(this.contentDiv, this.opacity);
\r
116 /** Bubble Popups can not have a border
\r
118 * @param {int} border
\r
120 setBorder:function(border) {
\r
125 * @param {String} contentHTML
\r
127 setContentHTML:function(contentHTML) {
\r
128 if (contentHTML != null) {
\r
129 this.contentHTML = contentHTML;
\r
132 if (this.contentDiv != null) {
\r
133 this.contentDiv.innerHTML = this.contentHTML;
\r
140 * @param {Boolean} firstTime Is this the first time the corners are being
\r
143 * update the rico corners according to the popup's
\r
144 * current relative postion
\r
146 setRicoCorners:function(firstTime) {
\r
148 var corners = this.getCornersToRound(this.relativePosition);
\r
149 var options = {corners: corners,
\r
150 color: this.backgroundColor,
\r
151 bgColor: "transparent",
\r
155 Rico.Corner.round(this.div, options);
\r
157 Rico.Corner.reRound(this.contentDiv, options);
\r
158 //set the popup color and opacity
\r
159 this.setBackgroundColor();
\r
167 * @returns The proper corners string ("tr tl bl br") for rico
\r
171 getCornersToRound:function() {
\r
173 var corners = ['tl', 'tr', 'bl', 'br'];
\r
175 //we want to round all the corners _except_ the opposite one.
\r
176 var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition);
\r
177 corners.remove(corner);
\r
179 return corners.join(" ");
\r
182 CLASS_NAME: "OpenLayers.Popup.AnchoredBubble"
\r