Changeset 252
- Timestamp:
- 05/22/06 07:45:38 (3 years ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Map.js (modified) (1 diff)
- trunk/openlayers/lib/OpenLayers/Popup.js (modified) (7 diffs)
- trunk/openlayers/tests/test_Map.html (modified) (1 diff)
- trunk/openlayers/tests/test_Popup.html (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Map.js
r246 r252 154 154 /** 155 155 * @param {OpenLayers.Popup} popup 156 */ 157 addPopup: function(popup) { 156 * @param {OpenLayers.Pixel} px 157 */ 158 addPopup: function(popup, px) { 158 159 this.popups.push(popup); 159 var popupDiv = popup.draw( );160 var popupDiv = popup.draw(px); 160 161 if (popupDiv) { 161 162 popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + trunk/openlayers/lib/OpenLayers/Popup.js
r236 r252 5 5 6 6 OpenLayers.Popup.count = 0; 7 OpenLayers.Popup.PX = new OpenLayers.Pixel(0, 0);8 7 OpenLayers.Popup.SIZE = new OpenLayers.Size(200, 200); 9 8 OpenLayers.Popup.COLOR = "white"; … … 21 20 /** @type DOMElement */ 22 21 div: null, 23 24 /** @type OpenLayers.Pixel */25 px: null,26 22 27 23 /** @type OpenLayers.Size*/ … … 45 41 * 46 42 * @param {String} id 47 * @param {OpenLayers.Pixel} px48 43 * @param {OpenLayers.Size} size 49 44 * @param {String} contentHTML 50 45 */ 51 initialize:function(id, px,size, contentHTML) {46 initialize:function(id, size, contentHTML) { 52 47 OpenLayers.Popup.count += 1; 53 48 54 49 this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count; 55 this.px = (px != null) ? px : OpenLayers.Popup.PX;56 50 this.size = (size != null) ? size : OpenLayers.Popup.SIZE; 57 51 if (contentHTML != null) { … … 73 67 74 68 /** 69 * @param {OpenLayers.Pixel} px 75 70 */ 76 draw: function( ) {71 draw: function(px) { 77 72 if (this.div == null) { 78 73 this.div = OpenLayers.Util.createDiv(this.id + "_div", … … 81 76 "hidden"); 82 77 } 83 this.setPx();84 78 this.setSize(); 85 79 this.setBackgroundColor(); … … 87 81 this.setBorder(); 88 82 this.setContentHTML(); 83 this.moveTo(px); 89 84 90 85 return this.div; 86 }, 87 88 /** 89 * @param {OpenLayers.Pixel} px 90 */ 91 moveTo: function(px) { 92 if (this.div != null) { 93 this.div.style.left = px.x + "px"; 94 this.div.style.top = px.y + "px"; 95 } 91 96 }, 92 97 … … 104 109 } 105 110 }, 106 107 /**108 * @param {OpenLayers.Pixel} px109 */110 setPx:function(px) {111 if (px != undefined) {112 this.px = px;113 }114 115 if (this.div != null) {116 this.div.style.left = this.px.x;117 this.div.style.top = this.px.y;118 }119 },120 121 111 122 112 /** trunk/openlayers/tests/test_Map.html
r246 r252 81 81 82 82 var popup = new OpenLayers.Popup("chicken", 83 new OpenLayers.Pixel(20,20),84 83 new OpenLayers.Size(200,200)); 85 84 86 map.addPopup(popup );85 map.addPopup(popup, new OpenLayers.Pixel(20,20)); 87 86 t.eq(map.popups.indexOf(popup), 0, "popup successfully added to Map's internal popups array"); 88 87 trunk/openlayers/tests/test_Popup.html
r233 r252 6 6 7 7 function test_01_Popup_default_constructor(t) { 8 t.plan( 11);8 t.plan( 9 ); 9 9 10 10 popup = new OpenLayers.Popup(); … … 12 12 t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 13 13 t.ok(popup.id.startsWith("Popup"), "good default popup.id"); 14 t.eq(popup.px.x, OpenLayers.Popup.PX.x, "good default popup.px.x");15 t.eq(popup.px.y, OpenLayers.Popup.PX.y, "good default popup.px.y");16 14 t.eq(popup.size.w, OpenLayers.Popup.SIZE.w, "good default popup.size.w"); 17 15 t.eq(popup.size.h, OpenLayers.Popup.SIZE.h, "good default popup.size.h"); … … 31 29 32 30 function test_02_Popup_constructor (t) { 33 t.plan( 7);31 t.plan( 5 ); 34 32 35 33 var id = "chicken"; 36 var x = 50;37 var y = 100;38 34 var w = 500; 39 35 var h = 400; … … 41 37 42 38 popup = new OpenLayers.Popup(id, 43 new OpenLayers.Pixel(x, y),44 39 new OpenLayers.Size(w, h), 45 40 content); … … 47 42 t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 48 43 t.eq(popup.id, id, "popup.id set correctly"); 49 t.eq(popup.px.x, x, "left position of popup.px set correctly");50 t.eq(popup.px.y, y, "top position of popup.px set correctly");51 44 t.eq(popup.size.w, w, "width of popup.size set correctly"); 52 45 t.eq(popup.size.h, h, "height of popup.size set correctly"); … … 56 49 function test_03_Popup_draw(t) { 57 50 58 t.plan( 9);51 t.plan( 11 ); 59 52 60 53 var id = "chicken"; … … 70 63 71 64 popup = new OpenLayers.Popup(id); 72 popup.setPx(new OpenLayers.Pixel(x, y));73 65 popup.setSize(new OpenLayers.Size(w, h)); 74 66 popup.setContentHTML(content); 75 popup.draw();76 67 popup.setBackgroundColor(color); 77 68 popup.setOpacity(opacity); 78 69 popup.setBorder(border); 70 popup.draw(new OpenLayers.Pixel(x, y)); 79 71 80 72 t.eq(popup.div.id, id + "_div", "popup.div.id set correctly"); … … 93 85 t.ok(popup.div.style.border.indexOf(border) != -1, "good default popup.border"); 94 86 87 x += 50; 88 popup.moveTo(new OpenLayers.Pixel(x, y)); 89 t.eq(popup.div.style.left, x + "px", "moveTo updates left position of popup.div correctly"); 90 t.eq(popup.div.style.top, y + "px", "moveTo updates top position of popup.div correctly"); 91 92 95 93 } 96 94
