]> dev.renevier.net Git - syp.git/blob - openlayers/lib/OpenLayers/Popup/AnchoredBubble.js
initial commit
[syp.git] / openlayers / lib / OpenLayers / Popup / AnchoredBubble.js
1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2  * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3  * full text of the license. */
4
5
6 /**
7  * @requires OpenLayers/Popup/Anchored.js
8  */
9
10 /**
11  * Class: OpenLayers.Popup.AnchoredBubble
12  * 
13  * Inherits from: 
14  *  - <OpenLayers.Popup.Anchored>
15  */
16 OpenLayers.Popup.AnchoredBubble = 
17   OpenLayers.Class(OpenLayers.Popup.Anchored, {
18
19     /**
20      * Property: rounded
21      * {Boolean} Has the popup been rounded yet?
22      */
23     rounded: false, 
24     
25     /** 
26      * Constructor: OpenLayers.Popup.AnchoredBubble
27      * 
28      * Parameters:
29      * id - {String}
30      * lonlat - {<OpenLayers.LonLat>}
31      * contentSize - {<OpenLayers.Size>}
32      * contentHTML - {String}
33      * anchor - {Object} Object to which we'll anchor the popup. Must expose 
34      *     a 'size' (<OpenLayers.Size>) and 'offset' (<OpenLayers.Pixel>) 
35      *     (Note that this is generally an <OpenLayers.Icon>).
36      * closeBox - {Boolean}
37      * closeBoxCallback - {Function} Function to be called on closeBox click.
38      */
39     initialize:function(id, lonlat, contentSize, contentHTML, anchor, closeBox,
40                         closeBoxCallback) {
41         
42         this.padding = new OpenLayers.Bounds(
43             0, OpenLayers.Popup.AnchoredBubble.CORNER_SIZE,
44             0, OpenLayers.Popup.AnchoredBubble.CORNER_SIZE
45         );
46         OpenLayers.Popup.Anchored.prototype.initialize.apply(this, arguments);
47     },
48
49     /** 
50      * Method: draw
51      * 
52      * Parameters:
53      * px - {<OpenLayers.Pixel>}
54      * 
55      * Returns:
56      * {DOMElement} Reference to a div that contains the drawn popup.
57      */
58     draw: function(px) {
59         
60         OpenLayers.Popup.Anchored.prototype.draw.apply(this, arguments);
61
62         this.setContentHTML();
63         
64         //set the popup color and opacity           
65         this.setBackgroundColor(); 
66         this.setOpacity();
67
68         return this.div;
69     },
70
71     /**
72      * Method: updateRelativePosition
73      * The popup has been moved to a new relative location, in which case
74      *     we will want to re-do the rico corners.
75      */
76     updateRelativePosition: function() {
77         this.setRicoCorners();
78     },
79
80     /**
81      * APIMethod: setSize
82      * 
83      * Parameters:
84      * contentSize - {<OpenLayers.Size>} the new size for the popup's 
85      *     contents div (in pixels).
86      */
87     setSize:function(contentSize) { 
88         OpenLayers.Popup.Anchored.prototype.setSize.apply(this, arguments);
89
90         this.setRicoCorners();
91     },  
92
93     /**
94      * APIMethod: setBackgroundColor
95      * 
96      * Parameters:
97      * color - {String}
98      */
99     setBackgroundColor:function(color) { 
100         if (color != undefined) {
101             this.backgroundColor = color; 
102         }
103         
104         if (this.div != null) {
105             if (this.contentDiv != null) {
106                 this.div.style.background = "transparent";
107                 OpenLayers.Rico.Corner.changeColor(this.groupDiv, 
108                                                    this.backgroundColor);
109             }
110         }
111     },  
112     
113     /**
114      * APIMethod: setOpacity
115      * 
116      * Parameters: 
117      * opacity - {float}
118      */
119     setOpacity:function(opacity) { 
120         OpenLayers.Popup.Anchored.prototype.setOpacity.call(this, opacity);
121         
122         if (this.div != null) {
123             if (this.groupDiv != null) {
124                 OpenLayers.Rico.Corner.changeOpacity(this.groupDiv, 
125                                                      this.opacity);
126             }
127         }
128     },  
129  
130     /** 
131      * Method: setBorder
132      * Always sets border to 0. Bubble Popups can not have a border.
133      * 
134      * Parameters:
135      * border - {Integer}
136      */
137     setBorder:function(border) { 
138         this.border = 0;
139     },      
140  
141     /** 
142      * Method: setRicoCorners
143      * Update RICO corners according to the popup's current relative postion.
144      */
145     setRicoCorners:function() {
146     
147         var corners = this.getCornersToRound(this.relativePosition);
148         var options = {corners: corners,
149                          color: this.backgroundColor,
150                        bgColor: "transparent",
151                          blend: false};
152
153         if (!this.rounded) {
154             OpenLayers.Rico.Corner.round(this.div, options);
155             this.rounded = true;
156         } else {
157             OpenLayers.Rico.Corner.reRound(this.groupDiv, options);
158             //set the popup color and opacity
159             this.setBackgroundColor(); 
160             this.setOpacity();
161         }
162     },
163
164     /** 
165      * Method: getCornersToRound
166      *  
167      * Returns:
168      * {String} The proper corners string ("tr tl bl br") for rico to round.
169      */
170     getCornersToRound:function() {
171
172         var corners = ['tl', 'tr', 'bl', 'br'];
173
174         //we want to round all the corners _except_ the opposite one. 
175         var corner = OpenLayers.Bounds.oppositeQuadrant(this.relativePosition);
176         OpenLayers.Util.removeItem(corners, corner);
177
178         return corners.join(" ");
179     },
180
181     CLASS_NAME: "OpenLayers.Popup.AnchoredBubble"
182 });
183
184 /**
185  * Constant: CORNER_SIZE
186  * {Integer} 5. Border space for the RICO corners.
187  */
188 OpenLayers.Popup.AnchoredBubble.CORNER_SIZE = 5;
189