OpenLayers OpenLayers

Changeset 252

Show
Ignore:
Timestamp:
05/22/06 07:45:38 (3 years ago)
Author:
euzuro
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Map.js

    r246 r252  
    154154    /**  
    155155    * @param {OpenLayers.Popup} popup 
    156     */ 
    157     addPopup: function(popup) { 
     156    * @param {OpenLayers.Pixel} px 
     157    */ 
     158    addPopup: function(popup, px) { 
    158159        this.popups.push(popup); 
    159         var popupDiv = popup.draw(); 
     160        var popupDiv = popup.draw(px); 
    160161        if (popupDiv) { 
    161162            popupDiv.style.zIndex = this.Z_INDEX_BASE['Popup'] + 
  • trunk/openlayers/lib/OpenLayers/Popup.js

    r236 r252  
    55 
    66OpenLayers.Popup.count = 0; 
    7 OpenLayers.Popup.PX = new OpenLayers.Pixel(0, 0); 
    87OpenLayers.Popup.SIZE = new OpenLayers.Size(200, 200); 
    98OpenLayers.Popup.COLOR = "white"; 
     
    2120    /** @type DOMElement */ 
    2221    div: null, 
    23  
    24     /** @type OpenLayers.Pixel */ 
    25     px: null,     
    2622 
    2723    /** @type OpenLayers.Size*/ 
     
    4541    *  
    4642    * @param {String} id 
    47     * @param {OpenLayers.Pixel} px 
    4843    * @param {OpenLayers.Size} size 
    4944    * @param {String} contentHTML 
    5045    */ 
    51     initialize:function(id, px, size, contentHTML) { 
     46    initialize:function(id, size, contentHTML) { 
    5247        OpenLayers.Popup.count += 1; 
    5348 
    5449        this.id = (id != null) ? id : "Popup" + OpenLayers.Popup.count; 
    55         this.px = (px != null) ? px : OpenLayers.Popup.PX; 
    5650        this.size = (size != null) ? size : OpenLayers.Popup.SIZE; 
    5751        if (contentHTML != null) {  
     
    7367 
    7468    /**  
     69    * @param {OpenLayers.Pixel} px 
    7570    */ 
    76     draw: function() { 
     71    draw: function(px) { 
    7772        if (this.div == null) { 
    7873            this.div = OpenLayers.Util.createDiv(this.id + "_div", 
     
    8176                                                  "hidden"); 
    8277        } 
    83         this.setPx(); 
    8478        this.setSize(); 
    8579        this.setBackgroundColor(); 
     
    8781        this.setBorder(); 
    8882        this.setContentHTML(); 
     83        this.moveTo(px); 
    8984 
    9085        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        } 
    9196    }, 
    9297 
     
    104109        }        
    105110    },   
    106  
    107     /** 
    108     * @param {OpenLayers.Pixel} px 
    109     */ 
    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  
    121111 
    122112    /** 
  • trunk/openlayers/tests/test_Map.html

    r246 r252  
    8181         
    8282        var popup = new OpenLayers.Popup("chicken",  
    83                                          new OpenLayers.Pixel(20,20), 
    8483                                         new OpenLayers.Size(200,200)); 
    8584 
    86         map.addPopup(popup); 
     85        map.addPopup(popup, new OpenLayers.Pixel(20,20)); 
    8786        t.eq(map.popups.indexOf(popup), 0, "popup successfully added to Map's internal popups array"); 
    8887         
  • trunk/openlayers/tests/test_Popup.html

    r233 r252  
    66     
    77    function test_01_Popup_default_constructor(t) { 
    8         t.plan( 11 ); 
     8        t.plan( 9 ); 
    99 
    1010        popup = new OpenLayers.Popup(); 
     
    1212        t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 
    1313        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"); 
    1614        t.eq(popup.size.w, OpenLayers.Popup.SIZE.w, "good default popup.size.w"); 
    1715        t.eq(popup.size.h, OpenLayers.Popup.SIZE.h, "good default popup.size.h"); 
     
    3129     
    3230    function test_02_Popup_constructor (t) { 
    33         t.plan( 7 ); 
     31        t.plan( 5 ); 
    3432 
    3533        var id = "chicken"; 
    36         var x = 50; 
    37         var y = 100; 
    3834        var w = 500; 
    3935        var h = 400; 
     
    4137 
    4238        popup = new OpenLayers.Popup(id, 
    43                                      new OpenLayers.Pixel(x, y), 
    4439                                     new OpenLayers.Size(w, h), 
    4540                                     content); 
     
    4742        t.ok( popup instanceof OpenLayers.Popup, "new OpenLayers.Popup returns Popup object" ); 
    4843        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"); 
    5144        t.eq(popup.size.w, w, "width of popup.size set correctly"); 
    5245        t.eq(popup.size.h, h, "height of popup.size set correctly"); 
     
    5649    function test_03_Popup_draw(t) { 
    5750     
    58         t.plan( 9 ); 
     51        t.plan( 11 ); 
    5952         
    6053        var id = "chicken"; 
     
    7063 
    7164        popup = new OpenLayers.Popup(id); 
    72         popup.setPx(new OpenLayers.Pixel(x, y)); 
    7365        popup.setSize(new OpenLayers.Size(w, h)); 
    7466        popup.setContentHTML(content); 
    75         popup.draw(); 
    7667        popup.setBackgroundColor(color); 
    7768        popup.setOpacity(opacity); 
    7869        popup.setBorder(border); 
     70        popup.draw(new OpenLayers.Pixel(x, y)); 
    7971                                      
    8072        t.eq(popup.div.id, id + "_div", "popup.div.id set correctly"); 
     
    9385        t.ok(popup.div.style.border.indexOf(border) != -1, "good default popup.border"); 
    9486 
     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 
    9593    } 
    9694