removed px member from OpenLayers.Popup. user must now specify a px value in the draw() method, just like with markers. updated tests

git-svn-id: http://svn.openlayers.org/trunk/openlayers@252 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-05-22 11:45:38 +00:00
parent d2c18d4de7
commit 2410d94107
4 changed files with 28 additions and 40 deletions

View File

@@ -153,10 +153,11 @@ OpenLayers.Map.prototype = {
/**
* @param {OpenLayers.Popup} popup
* @param {OpenLayers.Pixel} px
*/
addPopup: function(popup) {
addPopup: function(popup, px) {
this.popups.push(popup);
var popupDiv = popup.draw();
var popupDiv = popup.draw(px);
if (popupDiv) {
popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] +
this.popups.length;

View File

@@ -4,7 +4,6 @@
OpenLayers.Popup = Class.create();
OpenLayers.Popup.count = 0;
OpenLayers.Popup.PX = new OpenLayers.Pixel(0, 0);
OpenLayers.Popup.SIZE = new OpenLayers.Size(200, 200);
OpenLayers.Popup.COLOR = "white";
OpenLayers.Popup.OPACITY = 1;
@@ -21,9 +20,6 @@ OpenLayers.Popup.prototype = {
/** @type DOMElement */
div: null,
/** @type OpenLayers.Pixel */
px: null,
/** @type OpenLayers.Size*/
size: null,
@@ -44,15 +40,13 @@ OpenLayers.Popup.prototype = {
* @constructor
*
* @param {String} id
* @param {OpenLayers.Pixel} px
* @param {OpenLayers.Size} size
* @param {String} contentHTML
*/
initialize:function(id, px, size, contentHTML) {
initialize:function(id, size, contentHTML) {
OpenLayers.Popup.count += 1;
this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count;
this.px = (px != null) ? px : OpenLayers.Popup.PX;
this.size = (size != null) ? size : OpenLayers.Popup.SIZE;
if (contentHTML != null) {
this.contentHTML = contentHTML;
@@ -72,24 +66,35 @@ OpenLayers.Popup.prototype = {
},
/**
* @param {OpenLayers.Pixel} px
*/
draw: function() {
draw: function(px) {
if (this.div == null) {
this.div = OpenLayers.Util.createDiv(this.id + "_div",
null,
null,
"hidden");
}
this.setPx();
this.setSize();
this.setBackgroundColor();
this.setOpacity();
this.setBorder();
this.setContentHTML();
this.moveTo(px);
return this.div;
},
/**
* @param {OpenLayers.Pixel} px
*/
moveTo: function(px) {
if (this.div != null) {
this.div.style.left = px.x + "px";
this.div.style.top = px.y + "px";
}
},
/**
* @param {OpenLayers.Size} size
*/
@@ -104,21 +109,6 @@ OpenLayers.Popup.prototype = {
}
},
/**
* @param {OpenLayers.Pixel} px
*/
setPx:function(px) {
if (px != undefined) {
this.px = px;
}
if (this.div != null) {
this.div.style.left = this.px.x;
this.div.style.top = this.px.y;
}
},
/**
* @param {String} color
*/

View File

@@ -80,10 +80,9 @@
map = new OpenLayers.Map('map');
var popup = new OpenLayers.Popup("chicken",
new OpenLayers.Pixel(20,20),
new OpenLayers.Size(200,200));
map.addPopup(popup);
map.addPopup(popup, new OpenLayers.Pixel(20,20));
t.eq(map.popups.indexOf(popup), 0, "popup successfully added to Map's internal popups array");
var nodes = map.viewPortDiv.childNodes;

View File

@@ -5,14 +5,12 @@
var popup;
function test_01_Popup_default_constructor(t) {
t.plan( 11 );
t.plan( 9 );
popup = new OpenLayers.Popup();
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
t.ok(popup.id.startsWith("Popup"), "good default popup.id");
t.eq(popup.px.x, OpenLayers.Popup.PX.x, "good default popup.px.x");
t.eq(popup.px.y, OpenLayers.Popup.PX.y, "good default popup.px.y");
t.eq(popup.size.w, OpenLayers.Popup.SIZE.w, "good default popup.size.w");
t.eq(popup.size.h, OpenLayers.Popup.SIZE.h, "good default popup.size.h");
t.eq(popup.contentHTML, "", "good default popup.contentHTML");
@@ -30,24 +28,19 @@
}
function test_02_Popup_constructor (t) {
t.plan( 7 );
t.plan( 5 );
var id = "chicken";
var x = 50;
var y = 100;
var w = 500;
var h = 400;
var content = "foo";
popup = new OpenLayers.Popup(id,
new OpenLayers.Pixel(x, y),
new OpenLayers.Size(w, h),
content);
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
t.eq(popup.id, id, "popup.id set correctly");
t.eq(popup.px.x, x, "left position of popup.px set correctly");
t.eq(popup.px.y, y, "top position of popup.px set correctly");
t.eq(popup.size.w, w, "width of popup.size set correctly");
t.eq(popup.size.h, h, "height of popup.size set correctly");
t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly");
@@ -55,7 +48,7 @@
function test_03_Popup_draw(t) {
t.plan( 9 );
t.plan( 11 );
var id = "chicken";
var x = 50;
@@ -69,13 +62,12 @@
popup = new OpenLayers.Popup(id);
popup.setPx(new OpenLayers.Pixel(x, y));
popup.setSize(new OpenLayers.Size(w, h));
popup.setContentHTML(content);
popup.draw();
popup.setBackgroundColor(color);
popup.setOpacity(opacity);
popup.setBorder(border);
popup.draw(new OpenLayers.Pixel(x, y));
t.eq(popup.div.id, id + "_div", "popup.div.id set correctly");
t.eq(popup.div.style.left, x + "px", "left position of popup.div set correctly");
@@ -92,6 +84,12 @@
}
t.ok(popup.div.style.border.indexOf(border) != -1, "good default popup.border");
x += 50;
popup.moveTo(new OpenLayers.Pixel(x, y));
t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly");
t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly");
}