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