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. */
7 OpenLayers.Popup = Class.create();
\r
9 OpenLayers.Popup.count = 0;
\r
10 OpenLayers.Popup.WIDTH = 200;
\r
11 OpenLayers.Popup.HEIGHT = 200;
\r
12 OpenLayers.Popup.COLOR = "white";
\r
13 OpenLayers.Popup.OPACITY = 1;
\r
14 OpenLayers.Popup.BORDER = "0px";
\r
16 OpenLayers.Popup.prototype = {
\r
18 /** @type OpenLayers.Events*/
\r
24 /** @type OpenLayers.LonLat */
\r
27 /** @type DOMElement */
\r
30 /** @type OpenLayers.Size*/
\r
37 backgroundColor: "",
\r
45 /** this gets set in Map.js when the popup is added to the map
\r
46 * @type OpenLayers.Map */
\r
52 * @param {String} id
\r
53 * @param {OpenLayers.LonLat} lonlat
\r
54 * @param {OpenLayers.Size} size
\r
55 * @param {String} contentHTML
\r
57 initialize:function(id, lonlat, size, contentHTML) {
\r
58 OpenLayers.Popup.count += 1;
\r
59 this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count;
\r
60 this.lonlat = lonlat;
\r
61 this.size = (size != null) ? size
\r
62 : new OpenLayers.Size(
\r
63 OpenLayers.Popup.WIDTH,
\r
64 OpenLayers.Popup.HEIGHT);
\r
65 if (contentHTML != null) {
\r
66 this.contentHTML = contentHTML;
\r
68 this.backgroundColor = OpenLayers.Popup.COLOR;
\r
69 this.opacity = OpenLayers.Popup.OPACITY;
\r
70 this.border = OpenLayers.Popup.BORDER;
\r
72 this.div = OpenLayers.Util.createDiv(this.id + "_div", null, null,
\r
73 null, null, null, "hidden");
\r
75 this.events = new OpenLayers.Events(this, this.div, null);
\r
80 destroy: function() {
\r
81 if (this.map != null) {
\r
82 this.map.removePopup(this);
\r
89 * @param {OpenLayers.Pixel} px
\r
91 * @returns Reference to a div that contains the drawn popup
\r
94 draw: function(px) {
\r
96 if ((this.lonlat != null) && (this.map != null)) {
\r
97 px = this.map.getLayerPxFromLonLat(this.lonlat);
\r
102 this.setBackgroundColor();
\r
105 this.setContentHTML();
\r
112 * if the popup has a lonlat and its map members set,
\r
113 * then have it move itself to its proper position
\r
115 updatePosition: function() {
\r
116 if ((this.lonlat) && (this.map)) {
\r
117 var px = this.map.getLayerPxFromLonLat(this.lonlat);
\r
123 * @param {OpenLayers.Pixel} px
\r
125 moveTo: function(px) {
\r
126 if ((px != null) && (this.div != null)) {
\r
127 this.div.style.left = px.x + "px";
\r
128 this.div.style.top = px.y + "px";
\r
133 * @returns Boolean indicating whether or not the popup is visible
\r
136 visible: function() {
\r
137 return Element.visible(this.div);
\r
143 toggle: function() {
\r
144 Element.toggle(this.div);
\r
151 Element.show(this.div);
\r
158 Element.hide(this.div);
\r
162 * @param {OpenLayers.Size} size
\r
164 setSize:function(size) {
\r
165 if (size != undefined) {
\r
169 if (this.div != null) {
\r
170 this.div.style.width = this.size.w;
\r
171 this.div.style.height = this.size.h;
\r
176 * @param {String} color
\r
178 setBackgroundColor:function(color) {
\r
179 if (color != undefined) {
\r
180 this.backgroundColor = color;
\r
183 if (this.div != null) {
\r
184 this.div.style.backgroundColor = this.backgroundColor;
\r
189 * @param {float} opacity
\r
191 setOpacity:function(opacity) {
\r
192 if (opacity != undefined) {
\r
193 this.opacity = opacity;
\r
196 if (this.div != null) {
\r
197 // for Mozilla and Safari
\r
198 this.div.style.opacity = this.opacity;
\r
201 this.div.style.filter = 'alpha(opacity=' + this.opacity*100 + ')';
\r
206 * @param {int} border
\r
208 setBorder:function(border) {
\r
209 if (border != undefined) {
\r
210 this.border = border;
\r
213 if (this.div != null) {
\r
214 this.div.style.border = this.border;
\r
219 * @param {String} contentHTML
\r
221 setContentHTML:function(contentHTML) {
\r
222 if (contentHTML != null) {
\r
223 this.contentHTML = contentHTML;
\r
226 if (this.div != null) {
\r
227 this.div.innerHTML = this.contentHTML;
\r
231 CLASS_NAME: "OpenLayers.Popup"
\r