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:
@@ -153,10 +153,11 @@ OpenLayers.Map.prototype = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {OpenLayers.Popup} popup
|
* @param {OpenLayers.Popup} popup
|
||||||
|
* @param {OpenLayers.Pixel} px
|
||||||
*/
|
*/
|
||||||
addPopup: function(popup) {
|
addPopup: function(popup, px) {
|
||||||
this.popups.push(popup);
|
this.popups.push(popup);
|
||||||
var popupDiv = popup.draw();
|
var popupDiv = popup.draw(px);
|
||||||
if (popupDiv) {
|
if (popupDiv) {
|
||||||
popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] +
|
popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] +
|
||||||
this.popups.length;
|
this.popups.length;
|
||||||
|
|||||||
+14
-24
@@ -4,7 +4,6 @@
|
|||||||
OpenLayers.Popup = Class.create();
|
OpenLayers.Popup = Class.create();
|
||||||
|
|
||||||
OpenLayers.Popup.count = 0;
|
OpenLayers.Popup.count = 0;
|
||||||
OpenLayers.Popup.PX = new OpenLayers.Pixel(0, 0);
|
|
||||||
OpenLayers.Popup.SIZE = new OpenLayers.Size(200, 200);
|
OpenLayers.Popup.SIZE = new OpenLayers.Size(200, 200);
|
||||||
OpenLayers.Popup.COLOR = "white";
|
OpenLayers.Popup.COLOR = "white";
|
||||||
OpenLayers.Popup.OPACITY = 1;
|
OpenLayers.Popup.OPACITY = 1;
|
||||||
@@ -21,9 +20,6 @@ OpenLayers.Popup.prototype = {
|
|||||||
/** @type DOMElement */
|
/** @type DOMElement */
|
||||||
div: null,
|
div: null,
|
||||||
|
|
||||||
/** @type OpenLayers.Pixel */
|
|
||||||
px: null,
|
|
||||||
|
|
||||||
/** @type OpenLayers.Size*/
|
/** @type OpenLayers.Size*/
|
||||||
size: null,
|
size: null,
|
||||||
|
|
||||||
@@ -44,15 +40,13 @@ OpenLayers.Popup.prototype = {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*
|
*
|
||||||
* @param {String} id
|
* @param {String} id
|
||||||
* @param {OpenLayers.Pixel} px
|
|
||||||
* @param {OpenLayers.Size} size
|
* @param {OpenLayers.Size} size
|
||||||
* @param {String} contentHTML
|
* @param {String} contentHTML
|
||||||
*/
|
*/
|
||||||
initialize:function(id, px, size, contentHTML) {
|
initialize:function(id, size, contentHTML) {
|
||||||
OpenLayers.Popup.count += 1;
|
OpenLayers.Popup.count += 1;
|
||||||
|
|
||||||
this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count;
|
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;
|
this.size = (size != null) ? size : OpenLayers.Popup.SIZE;
|
||||||
if (contentHTML != null) {
|
if (contentHTML != null) {
|
||||||
this.contentHTML = contentHTML;
|
this.contentHTML = contentHTML;
|
||||||
@@ -72,24 +66,35 @@ OpenLayers.Popup.prototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param {OpenLayers.Pixel} px
|
||||||
*/
|
*/
|
||||||
draw: function() {
|
draw: function(px) {
|
||||||
if (this.div == null) {
|
if (this.div == null) {
|
||||||
this.div = OpenLayers.Util.createDiv(this.id + "_div",
|
this.div = OpenLayers.Util.createDiv(this.id + "_div",
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
"hidden");
|
"hidden");
|
||||||
}
|
}
|
||||||
this.setPx();
|
|
||||||
this.setSize();
|
this.setSize();
|
||||||
this.setBackgroundColor();
|
this.setBackgroundColor();
|
||||||
this.setOpacity();
|
this.setOpacity();
|
||||||
this.setBorder();
|
this.setBorder();
|
||||||
this.setContentHTML();
|
this.setContentHTML();
|
||||||
|
this.moveTo(px);
|
||||||
|
|
||||||
return this.div;
|
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
|
* @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
|
* @param {String} color
|
||||||
*/
|
*/
|
||||||
|
|||||||
+1
-2
@@ -80,10 +80,9 @@
|
|||||||
map = new OpenLayers.Map('map');
|
map = new OpenLayers.Map('map');
|
||||||
|
|
||||||
var popup = new OpenLayers.Popup("chicken",
|
var popup = new OpenLayers.Popup("chicken",
|
||||||
new OpenLayers.Pixel(20,20),
|
|
||||||
new OpenLayers.Size(200,200));
|
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");
|
t.eq(map.popups.indexOf(popup), 0, "popup successfully added to Map's internal popups array");
|
||||||
|
|
||||||
var nodes = map.viewPortDiv.childNodes;
|
var nodes = map.viewPortDiv.childNodes;
|
||||||
|
|||||||
+10
-12
@@ -5,14 +5,12 @@
|
|||||||
var popup;
|
var popup;
|
||||||
|
|
||||||
function test_01_Popup_default_constructor(t) {
|
function test_01_Popup_default_constructor(t) {
|
||||||
t.plan( 11 );
|
t.plan( 9 );
|
||||||
|
|
||||||
popup = new OpenLayers.Popup();
|
popup = new OpenLayers.Popup();
|
||||||
|
|
||||||
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
|
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
|
||||||
t.ok(popup.id.startsWith("Popup"), "good default popup.id");
|
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.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.size.h, OpenLayers.Popup.SIZE.h, "good default popup.size.h");
|
||||||
t.eq(popup.contentHTML, "", "good default popup.contentHTML");
|
t.eq(popup.contentHTML, "", "good default popup.contentHTML");
|
||||||
@@ -30,24 +28,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_02_Popup_constructor (t) {
|
function test_02_Popup_constructor (t) {
|
||||||
t.plan( 7 );
|
t.plan( 5 );
|
||||||
|
|
||||||
var id = "chicken";
|
var id = "chicken";
|
||||||
var x = 50;
|
|
||||||
var y = 100;
|
|
||||||
var w = 500;
|
var w = 500;
|
||||||
var h = 400;
|
var h = 400;
|
||||||
var content = "foo";
|
var content = "foo";
|
||||||
|
|
||||||
popup = new OpenLayers.Popup(id,
|
popup = new OpenLayers.Popup(id,
|
||||||
new OpenLayers.Pixel(x, y),
|
|
||||||
new OpenLayers.Size(w, h),
|
new OpenLayers.Size(w, h),
|
||||||
content);
|
content);
|
||||||
|
|
||||||
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
|
t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" );
|
||||||
t.eq(popup.id, id, "popup.id set correctly");
|
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.w, w, "width of popup.size set correctly");
|
||||||
t.eq(popup.size.h, h, "height 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");
|
t.eq(popup.contentHTML, content, "contentHTML porpoerty of set correctly");
|
||||||
@@ -55,7 +48,7 @@
|
|||||||
|
|
||||||
function test_03_Popup_draw(t) {
|
function test_03_Popup_draw(t) {
|
||||||
|
|
||||||
t.plan( 9 );
|
t.plan( 11 );
|
||||||
|
|
||||||
var id = "chicken";
|
var id = "chicken";
|
||||||
var x = 50;
|
var x = 50;
|
||||||
@@ -69,13 +62,12 @@
|
|||||||
|
|
||||||
|
|
||||||
popup = new OpenLayers.Popup(id);
|
popup = new OpenLayers.Popup(id);
|
||||||
popup.setPx(new OpenLayers.Pixel(x, y));
|
|
||||||
popup.setSize(new OpenLayers.Size(w, h));
|
popup.setSize(new OpenLayers.Size(w, h));
|
||||||
popup.setContentHTML(content);
|
popup.setContentHTML(content);
|
||||||
popup.draw();
|
|
||||||
popup.setBackgroundColor(color);
|
popup.setBackgroundColor(color);
|
||||||
popup.setOpacity(opacity);
|
popup.setOpacity(opacity);
|
||||||
popup.setBorder(border);
|
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.id, id + "_div", "popup.div.id set correctly");
|
||||||
t.eq(popup.div.style.left, x + "px", "left position of popup.div 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");
|
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");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user