OpenLayers OpenLayers

Changeset 140

Show
Ignore:
Timestamp:
05/18/06 08:48:52 (3 years ago)
Author:
euzuro
Message:

Changed OpenLayers.Bounds to use left, bottom, right, top INSTEAD OF minlon, minlat, maxlon, maxlat. Removed OpenLayers.Box which was not getting used. JSDOC/coding standard-ified the OpenLayers.Bounds code and wrote thorough testing for it. Should be all good.

Files:

Legend:

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

    r104 r140  
    4444        } else { 
    4545          var i = 0; 
    46           while (this.getGridBounds().minlat > bounds.minlat) { 
     46          while (this.getGridBounds().bottom > bounds.bottom) { 
    4747             this.insertRow(false);  
    4848          } 
    49           while (this.getGridBounds().minlon > bounds.minlon) { 
     49          while (this.getGridBounds().left > bounds.left) { 
    5050             this.insertColumn(true);  
    5151          } 
    52           while (this.getGridBounds().maxlat < bounds.maxlat) { 
     52          while (this.getGridBounds().top < bounds.top) { 
    5353             this.insertRow(true);  
    5454          } 
    55           while (this.getGridBounds().maxlon < bounds.maxlon) { 
     55          while (this.getGridBounds().right < bounds.right) { 
    5656             this.insertColumn(false);  
    5757          } 
     
    6161        var topLeftTile = this.grid[0][0]; 
    6262        var bottomRightTile = this.grid[this.grid.length-1][this.grid[0].length-1]; 
    63         return new OpenLayers.Bounds(topLeftTile.bounds.minlon,  
    64                                      bottomRightTile.bounds.minlat
    65                                      bottomRightTile.bounds.maxlon,  
    66                                      topLeftTile.bounds.maxlat); 
     63        return new OpenLayers.Bounds(topLeftTile.bounds.left,  
     64                                     bottomRightTile.bounds.bottom
     65                                     bottomRightTile.bounds.right,  
     66                                     topLeftTile.bounds.top); 
    6767    }, 
    6868    _initTiles:function() { 
     
    7474        var tilelat = resolution*this.tileSize.h; 
    7575         
    76         var offsetlon = bounds.minlon - extent.minlon
     76        var offsetlon = bounds.left - extent.left
    7777        var tilecol = Math.floor(offsetlon/tilelon); 
    7878        var tilecolremain = offsetlon/tilelon - tilecol; 
    7979        var tileoffsetx = -tilecolremain * this.tileSize.w; 
    80         var tileoffsetlon = extent.minlon + tilecol * tilelon; 
    81          
    82         var offsetlat = bounds.maxlat - (extent.minlat + tilelat);   
     80        var tileoffsetlon = extent.left + tilecol * tilelon; 
     81         
     82        var offsetlat = bounds.top - (extent.bottom + tilelat);   
    8383        var tilerow = Math.ceil(offsetlat/tilelat); 
    8484        var tilerowremain = tilerow - offsetlat/tilelat; 
    8585        var tileoffsety = -tilerowremain * this.tileSize.h; 
    86         var tileoffsetlat = extent.minlat + tilerow * tilelat; 
     86        var tileoffsetlat = extent.bottom + tilerow * tilelat; 
    8787         
    8888        tileoffsetx = Math.round(tileoffsetx); // heaven help us 
     
    114114                tileoffsetlon += tilelon;        
    115115                tileoffsetx += this.tileSize.w; 
    116             } while (tileoffsetlon < bounds.maxlon)   
     116            } while (tileoffsetlon < bounds.right)   
    117117             
    118118            tileoffsetlat -= tilelat; 
    119119            tileoffsety += this.tileSize.h; 
    120         } while(tileoffsetlat > bounds.minlat - tilelat) 
     120        } while(tileoffsetlat > bounds.bottom - tilelat) 
    121121 
    122122    }, 
     
    140140            var bounds = modelTile.bounds.copyOf(); 
    141141            var position = modelTile.position.copyOf(); 
    142             bounds.minlat = bounds.minlat + deltaLat; 
    143             bounds.maxlat = bounds.maxlat + deltaLat; 
     142            bounds.bottom = bounds.bottom + deltaLat; 
     143            bounds.top = bounds.top + deltaLat; 
    144144            position.y = position.y + deltaY; 
    145145            var newTile = this.addTile(bounds, position); 
     
    173173            var bounds = modelTile.bounds.copyOf(); 
    174174            var position = modelTile.position.copyOf(); 
    175             bounds.minlon = bounds.minlon + deltaLon; 
    176             bounds.maxlon = bounds.maxlon + deltaLon; 
     175            bounds.left = bounds.left + deltaLon; 
     176            bounds.right = bounds.right + deltaLon; 
    177177            position.x = position.x + deltaX; 
    178178            var newTile = this.addTile(bounds, position); 
  • trunk/openlayers/lib/OpenLayers/Layer/Marker.js

    r135 r140  
    5151        var extent = this.map.getExtent(); 
    5252        var pixel = new OpenLayers.Pixel( 
    53                        1/resolution * (marker.lonlat.lon - extent.minlon), 
    54                        1/resolution * (extent.maxlat - marker.lonlat.lat) 
     53                       1/resolution * (marker.lonlat.lon - extent.left), 
     54                       1/resolution * (extent.top - marker.lonlat.lat) 
    5555                       ); 
    5656        var m = marker.generateMarker(pixel); 
  • trunk/openlayers/lib/OpenLayers/Map.js

    r118 r140  
    223223    getZoomForExtent: function (bounds) { 
    224224        var size = this.getSize(); 
    225         var deg_per_pixel = bounds.width / size.w; 
     225        var deg_per_pixel = bounds.getWidth() / size.w; 
    226226        var zoom = Math.log(deg_per_pixel / this.maxResolution) / Math.log(2); 
    227227        return Math.floor(Math.max(zoom, 0));  
     
    319319        this.zoom = this.getZoomForExtent( fullExtent ); 
    320320        this.setCenter( 
    321           new OpenLayers.LonLat((fullExtent.minlon+fullExtent.maxlon)/2, 
    322                                 (fullExtent.minlat+fullExtent.maxlat)/2) 
     321          new OpenLayers.LonLat((fullExtent.left+fullExtent.right)/2, 
     322                                (fullExtent.bottom+fullExtent.top)/2) 
    323323                               ); 
    324324    }, 
  • trunk/openlayers/lib/OpenLayers/Util.js

    r139 r140  
    1 /* 
     1/** 
    22* @class 
    33*/ 
     
    224224/** 
    225225* @class This class represents a bounding box.  
    226 *        Data stored as Min and Max Longitudes and Latitude
     226*        Data stored as left, bottom, right, top float
    227227*/ 
    228228OpenLayers.Bounds = Class.create(); 
     
    230230 
    231231    /** @type float */ 
    232     minlon: 0.0, 
    233  
    234     /** @type float */ 
    235     minlat: 0.0, 
    236  
    237     /** @type float */ 
    238     maxlon: 0.0, 
    239  
    240     /** @type float */ 
    241     maxlat: 0.0, 
    242  
    243     /** @type float */ 
    244     width: 0.0, 
    245  
    246     /** @type float */ 
    247     height: 0.0, 
    248      
    249  
    250     /**  
     232    left: 0.0, 
     233 
     234    /** @type float */ 
     235    bottom: 0.0, 
     236 
     237    /** @type float */ 
     238    right: 0.0, 
     239 
     240    /** @type float */ 
     241    top: 0.0,     
     242 
     243    /** 
    251244    * @constructor 
    252245    * 
    253     * @param {float} minlon 
    254     * @param {float} minlat 
    255     * @param {float} maxlon 
    256     * @param {float} maxlat 
    257     */ 
    258     initialize: function(minlon, minlat, maxlon, maxlat) { 
    259         this.minlon = minlon; 
    260         this.minlat = minlat; 
    261         this.maxlon = maxlon; 
    262         this.maxlat = maxlat; 
    263         this.width = Math.abs(this.maxlon - this.minlon); 
    264         this.height = Math.abs(this.maxlat - this.minlat); 
    265     }, 
    266      
     246    * @param {float} left 
     247    * @param {float} bottom 
     248    * @param {float} right 
     249    * @param {float} top 
     250    * 
     251    */ 
     252    initialize: function(left, bottom, right, top) { 
     253        this.left = left; 
     254        this.bottom = bottom; 
     255        this.right = right; 
     256        this.top = top; 
     257    }, 
     258 
     259    /** 
     260    * @returns A fresh copy of the bounds 
     261    * @type OpenLayers.Bounds 
     262    */ 
     263    copyOf:function() { 
     264        return new OpenLayers.Bounds(this.left, this.bottom,  
     265                                     this.right, this.top); 
     266    }, 
     267 
    267268    /**  
    268269    * @return String representation of OpenLayers.Bounds object.  
    269     *         (ex.<i>"Min lon/lat=5/42 Max lon/lat=10/45 width=5 height=3"</i>) 
     270    *         (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>) 
    270271    * @type String 
    271272    */ 
    272273    toString:function(){ 
    273         return ("Min lon/lat=" + this.minlon +"/"+ this.minlat 
    274                 + " Max lon/lat=" + this.maxlon +"/"+ this.maxlat 
    275                 + " width=" + this.width + " height=" + this.height); 
    276     }, 
    277      
    278     /**  
    279     * @return New OpenLayers.Bounds object with the same min/max lon/lat values 
    280     * @type OpenLayers.Bounds 
    281     */ 
    282     copyOf:function() { 
    283         return new OpenLayers.Bounds(this.minlon, this.minlat, 
    284                                      this.maxlon, this.maxlat); 
     274        return ( "left-bottom=(" + this.left + "," + this.bottom + ")" 
     275                 + " right-top=(" + this.right + "," + this.top + ")" ); 
    285276    }, 
    286277 
     
    291282    */ 
    292283    toBBOX:function() { 
    293         return (this.minlon + "," + this.minlat + "," +  
    294                 this.maxlon + "," + this.maxlat); 
    295     }, 
    296      
    297      
    298     /**  
    299     * @return Whether or not the passed-in coordinate is within the area 
    300     *         delineated by this OpenLayers.Bounds 
     284        return (this.left + "," + this.bottom + "," 
     285                + this.right + "," + this.top); 
     286    }, 
     287     
     288    /** 
     289    * @returns The width of the bounds 
     290    * @type float 
     291    */ 
     292    getWidth:function() { 
     293        return (this.right - this.left); 
     294    }, 
     295 
     296    /** 
     297    * @returns The height of the bounds 
     298    * @type float 
     299    */ 
     300    getHeight:function() { 
     301        return (this.top - this.bottom); 
     302    }, 
     303 
     304    /** 
     305    * @returns An OpenLayers.Size which represents the size of the box 
     306    * @type OpenLayers.Size 
     307    */ 
     308    getSize:function() { 
     309        return new OpenLayers.Size(this.getWidth(), this.getHeight()); 
     310    }, 
     311 
     312    /** 
     313    * @returns An OpenLayers.Pixel which represents the center of the bounds 
     314    * @type OpenLayers.Pixel 
     315    */ 
     316    getCenterPixel:function() { 
     317        return new OpenLayers.Pixel(this.left + (this.getWidth() / 2), 
     318                                    this.bottom + (this.getHeight() / 2)); 
     319    }, 
     320 
     321    /** 
     322    * @returns An OpenLayers.LonLat which represents the center of the bounds 
     323    * @type OpenLayers.LonLat 
     324    */ 
     325    getCenterLonLat:function() { 
     326        return new OpenLayers.LonLat(this.left + (this.getWidth() / 2), 
     327                                    this.bottom + (this.getHeight() / 2)); 
     328    }, 
     329 
     330    /** 
     331    * @param {float} x 
     332    * @param {float} y 
     333    * 
     334    * @returns A new OpenLayers.Bounds whose coordinates are the same as this,  
     335    *          but shifted by the passed-in x and y values 
     336    * @type OpenLayers.Bounds 
     337    */ 
     338    add:function(x, y){ 
     339        return new OpenLayers.Box(this.left + x, this.bottom + y, 
     340                                  this.right + x, this.top + y); 
     341    }, 
     342 
     343    /** 
     344    * @param {float} x 
     345    * @param {float} y 
     346    * @param {Boolean} inclusive Whether or not to include the border.  
     347    *                            Default is true 
     348    * 
     349    * @return Whether or not the passed-in coordinates are within this bounds 
    301350    * @type Boolean 
    302351    */ 
    303     contains:function(ll) { 
    304         return ((ll.lon >= this.minlon) && (ll.lon <= this.maxlon)  
    305                  && (ll.lat >= this.minlat) && (ll.lat <= this.maxlat)); 
    306     }, 
    307      
     352    contains:function(x, y, inclusive) { 
     353     
     354        //set default 
     355        if (inclusive == null) { 
     356            inclusive = true; 
     357        } 
     358         
     359        var contains = false; 
     360        if (inclusive) { 
     361            contains = ((x >= this.left) && (x <= this.right) &&  
     362                        (y >= this.bottom) && (y <= this.top)); 
     363        } else { 
     364            contains = ((x > this.left) && (x < this.right) &&  
     365                        (y > this.bottom) && (y < this.top)); 
     366        }               
     367        return contains; 
     368    }, 
     369  
     370    /** 
     371    * @param {OpenLayers.Bounds} bounds 
     372    * @param {Boolean} partial If true, only part of passed-in  
     373    *                          OpenLayers.Bounds needs be within this bounds.  
     374    *                          If false, the entire passed-in bounds must be 
     375    *                          within. Default is false 
     376    * @param {Boolean} inclusive Whether or not to include the border.  
     377    *                            Default is true 
     378    * 
     379    * @return Whether or not the passed-in OpenLayers.Bounds object is  
     380    *         contained within this bounds.  
     381    * @type Boolean 
     382    */ 
     383    containsBounds:function(bounds, partial, inclusive) { 
     384 
     385        //set defaults 
     386        if (partial == null) { 
     387            partial = false; 
     388        } 
     389        if (inclusive == null) { 
     390            inclusive = true; 
     391        } 
     392 
     393        var inLeft; 
     394        var inTop; 
     395        var inRight; 
     396        var inBottom; 
     397         
     398        if (inclusive) { 
     399            inLeft = (bounds.left >= this.left) && (bounds.left <= this.right); 
     400            inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top); 
     401            inRight= (bounds.right >= this.left) && (bounds.right <= this.right); 
     402            inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top); 
     403        } else { 
     404            inLeft = (bounds.left > this.left) && (bounds.left < this.right); 
     405            inTop = (bounds.top > this.bottom) && (bounds.top < this.top); 
     406            inRight= (bounds.right > this.left) && (bounds.right < this.right); 
     407            inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top); 
     408        } 
     409         
     410        return (partial) ? (inTop || inBottom) && (inLeft || inRight ) 
     411                         : (inTop && inLeft && inBottom && inRight); 
     412    }, 
     413 
    308414    /** @final @type String */ 
    309415    CLASS_NAME: "OpenLayers.Bounds" 
     
    328434}; 
    329435 
    330 OpenLayers.Box = Class.create(); 
    331 OpenLayers.Box.prototype = { 
    332     initialize: function(x,y,w,h){ 
    333         this.xy=new OpenLayers.Pixel(x,y); 
    334         this.sz=new OpenLayers.Size(w,h); 
    335         this.c = new OpenLayers.Pixel(x+(w/2), y+(h/2)); 
    336         this.br = new OpenLayers.Pixel(x+w-1,y+h-1); 
    337     }, 
    338  
    339     /* offset box by df 
    340     * @df(OpenLayers.Size) 
    341     */ 
    342     offset:function(df){ 
    343         this.xy=new OpenLayers.Pixel(this.xy.x+df.w,this.xy.y+df.h); 
    344         this.c = new OpenLayers.Pixel(this.xy.x+(this.sz.w/2), this.xy.y+(this.sz.h/2)); 
    345         var x=this.xy.x; 
    346         var y=this.xy.y; 
    347         var w=this.sz.w; 
    348         var h=this.sz.h; 
    349         this.br = new OpenLayers.Pixel(x+w-1,y+h-1); 
    350     }, 
    351  
    352     getOrigin:function(){return this.xy;}, 
    353     getSize:function(){return this.sz;}, 
    354     getCenter:function(){return this.c;}, 
    355     getBotRight:function(){return this.br;}, 
    356     getWidth:function(){return this.sz.w;}, 
    357     getHeight:function(){return this.sz.h;}, 
    358     getSize:function(){return this.sz;}, 
    359  
    360     toString:function(){ 
    361         return (this.xy.toString() + " " + this.sz.toString()); 
    362     }, 
    363     copyOf:function(){ 
    364         return new OpenLayers.Box(this.xy.x, this.xy.y, this.sz.w, this.sz.h); 
    365     }, 
    366     toCoordsString:function(){ 
    367         var x1 = this.xy.x; 
    368         var x2 = this.xy.x+this.sz.w-1; 
    369         var y1 = this.xy.y; 
    370         var y2 = this.xy.y+this.sz.h-1; 
    371         return (x1+","+y1+","+x2+","+y2); 
    372     }, 
    373     contains:function(pt){ 
    374         var returnVal = false; 
    375          
    376         var lx=this.xy.x; 
    377         var ly=this.xy.y; 
    378         var rx=lx+this.sz.w-1; 
    379         var ry=ly+this.sz.h-1; 
    380  
    381         if (pt != null) { 
    382             //upper left in 
    383             returnVal =  (pt.x >=lx && pt.x <=rx && pt.y >=ly && pt.y <= ry); 
    384         } 
    385         return returnVal; 
    386     }, 
    387  
    388     /** 
    389     * @param {ol.Box} box 
    390     * @param {bool} partial - if true, returns whether any part of the passed  
    391     *                         in box is within the calling box. otherwise box 
    392     *                         must contain entire box to return true. 
    393     * 
    394     * @return {bool} 
    395     */ 
    396     containsBox:function(box, partial) { 
    397         var contains = false; 
    398          
    399         var mainTop = this.xy.y; 
    400         var mainLeft = this.xy.x; 
    401         var mainBottom = this.xy.y + this.sz.h; 
    402         var mainRight = this.xy.x + this.sz.w; 
    403  
    404         var top = box.xy.y; 
    405         var left = box.xy.x; 
    406         var bottom = box.xy.y + box.sz.h; 
    407         var right = box.xy.x + box.sz.w; 
    408  
    409         var inTop = (top >= mainTop) && (top <= mainBottom); 
    410         var inLeft = (left >= mainLeft) && (left <= mainRight); 
    411         var inBottom = (bottom >= mainTop) && (bottom <= mainBottom); 
    412         var inRight= (right >= mainLeft) && (right <= mainRight); 
    413          
    414         if (partial) { 
    415             contains = (inTop || inBottom) && (inLeft || inRight ); 
    416         } else { 
    417             contains = (inTop && inLeft && inBottom && inRight); 
    418         } 
    419          
    420         return contains;       
    421     }, 
    422  
    423     // is this point the center of the box, +-2 pixels (@todo fix that number!) 
    424     isCenter:function(pt){ 
    425         var size = this.c.absDiff(pt); 
    426         return (size.w <= 2 && size.h <= 2); 
    427     } 
    428 }; 
    429436 
    430437 
    431438// Some other helpful things 
     439 
     440/** 
     441* @param {String} sStart 
     442*  
     443* @returns Whether or not this string starts with the string passed in. 
     444* @type Boolean 
     445*/ 
    432446String.prototype.startsWith = function(sStart){ 
    433     return (this.substr(0,sStart.length)==sStart); 
     447    return (this.substr(0,sStart.length) == sStart); 
    434448}; 
    435449String.prototype.trim = function() { 
     
    464478Array.prototype.clear=function() {this.length=0;}; 
    465479 
     480 
     481 
    466482/** Create a child element (a div currently) that 
    467483* is a proper child of the supplied parent, is invisible, 
  • trunk/openlayers/tests/test_Bounds.html

    r122 r140  
    55    var bounds;  
    66    function test_01_Bounds_constructor (t) { 
    7         t.plan( 8 ); 
     7        t.plan( 14 ); 
    88        bounds = new OpenLayers.Bounds(0,2,10,4); 
    99        t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); 
    1010        t.eq( bounds.CLASS_NAME, "OpenLayers.Bounds", "bounds.CLASS_NAME is set correctly" ); 
    11         t.eq( bounds.minlon, 0, "bounds.minlon is set correctly" ); 
    12         t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" ); 
    13         t.eq( bounds.maxlon, 10, "bounds.maxlon is set correctly" ); 
    14         t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" ); 
    15         t.eq( bounds.width, 10, "bounds.width is set correctly" ); 
    16         t.eq( bounds.height, 2, "bounds.height is set correctly" ); 
     11        t.eq( bounds.left, 0, "bounds.left is set correctly" ); 
     12        t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); 
     13        t.eq( bounds.right, 10, "bounds.right is set correctly" ); 
     14        t.eq( bounds.top, 4, "bounds.top is set correctly" ); 
     15        t.eq( bounds.getWidth(), 10, "bounds.getWidth() returns correct value" ); 
     16        t.eq( bounds.getHeight(), 2, "bounds.getHeight() returns correct value" ); 
     17         
     18        var sz = bounds.getSize(); 
     19        t.eq( sz.w, 10, "bounds.getSize() has correct width value" ); 
     20        t.eq( sz.h, 2, "bounds.getSize() has correct height value" ); 
     21     
     22        var center = bounds.getCenterPixel(); 
     23        t.eq( center.x, 5, "bounds.getCenterPixel() has correct x value" ); 
     24        t.eq( center.y, 3, "bounds.getCenterPixel() has correct y value" ); 
     25 
     26        var center = bounds.getCenterLonLat(); 
     27        t.eq( center.lon, 5, "bounds.getCenterLonLat() has correct lon value" ); 
     28        t.eq( center.lat, 3, "bounds.getCenterLonLat() has correct lat value" ); 
     29 
    1730     } 
    1831 
     
    2639         t.plan( 1 ); 
    2740         bounds = new OpenLayers.Bounds(1,2,3,4); 
    28          t.eq( bounds.toString(), "Min lon/lat=1/2 Max lon/lat=3/4 width=2 height=2", "toString() returns correct value." );  
     41         t.eq( bounds.toString(), "left-bottom=(1,2) right-top=(3,4)", "toString() returns correct value." );  
    2942     } 
    3043 
    3144     function test_04_Bounds_contains(t) { 
    32          t.plan( 3 ); 
     45         t.plan( 4 ); 
    3346         bounds = new OpenLayers.Bounds(10,10,40,40); 
    34          ll = new OpenLayers.LonLat(20,20); 
    35          t.eq( bounds.contains(ll), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); 
    36          ll = new OpenLayers.LonLat(0,0); 
    37          t.eq( bounds.contains(ll), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" ); 
    38          ll = new OpenLayers.LonLat(40,40); 
    39          t.eq( bounds.contains(ll), true, "bounds(10,10,40,40) correctly contains LonLat(40,40)" ); 
     47         t.eq( bounds.contains(20,20), true, "bounds(10,10,40,40) correctly contains LonLat(20,20)" ); 
     48         t.eq( bounds.contains(0,0), false, "bounds(10,10,40,40) correctly does not contain LonLat(0,0)" ); 
     49         t.eq( bounds.contains(40,40), true, "bounds(10,10,40,40) correctly contains LonLat(40,40) with inclusive set to true" ); 
     50         t.eq( bounds.contains(40,40, false), false, "bounds(10,10,40,40) correctly does not contain LonLat(40,40) with inclusive set to false" ); 
    4051     } 
    4152 
     
    4455        bounds = OpenLayers.Bounds.fromString("1,2,3,4"); 
    4556        t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); 
    46         t.eq( bounds.minlon, 1, "bounds.minlon is set correctly" ); 
    47         t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" ); 
    48         t.eq( bounds.maxlon, 3, "bounds.maxlon is set correctly" ); 
    49         t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" ); 
     57        t.eq( bounds.left, 1, "bounds.left is set correctly" ); 
     58        t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); 
     59        t.eq( bounds.right, 3, "bounds.right is set correctly" ); 
     60        t.eq( bounds.top, 4, "bounds.top is set correctly" ); 
    5061     } 
    5162 
     
    5465        bounds = OpenLayers.Bounds.fromString("1.1,2.2,3.3,4.4"); 
    5566        t.ok( bounds instanceof OpenLayers.Bounds, "new OpenLayers.Bounds returns Bounds object" ); 
    56         t.eq( bounds.minlon, 1.1, "bounds.minlon is set correctly" ); 
    57         t.eq( bounds.minlat, 2.2, "bounds.minlat is set correctly" ); 
    58         t.eq( bounds.maxlon, 3.3, "bounds.maxlon is set correctly" ); 
    59         t.eq( bounds.maxlat, 4.4, "bounds.maxlat is set correctly" ); 
     67        t.eq( bounds.left, 1.1, "bounds.left is set correctly" ); 
     68        t.eq( bounds.bottom, 2.2, "bounds.bottom is set correctly" ); 
     69        t.eq( bounds.right, 3.3, "bounds.right is set correctly" ); 
     70        t.eq( bounds.top, 4.4, "bounds.top is set correctly" ); 
    6071     } 
    6172 
     
    6576        var bounds = oldBounds.copyOf(); 
    6677        t.ok( bounds instanceof OpenLayers.Bounds, "copyOf returns new OpenLayers.Bounds object" ); 
    67         t.eq( bounds.minlon, 1, "bounds.minlon is set correctly" ); 
    68         t.eq( bounds.minlat, 2, "bounds.minlat is set correctly" ); 
    69         t.eq( bounds.maxlon, 3, "bounds.maxlon is set correctly" ); 
    70         t.eq( bounds.maxlat, 4, "bounds.maxlat is set correctly" ); 
     78        t.eq( bounds.left, 1, "bounds.left is set correctly" ); 
     79        t.eq( bounds.bottom, 2, "bounds.bottom is set correctly" ); 
     80        t.eq( bounds.right, 3, "bounds.right is set correctly" ); 
     81        t.eq( bounds.top, 4, "bounds.top is set correctly" ); 
    7182         
    72         //change minlon of oldBounds - if bounds is a  
    73         // real copyOf, bounds.minlon should not change 
    74         oldBounds.minlon = 100; 
    75         t.eq( bounds.minlon, 1, "changing olBounds.minlon does not change bounds.minlon" ); 
     83        oldBounds.left = 100; 
     84        t.eq( bounds.left, 1, "changing olBounds.left does not change bounds.left" ); 
    7685     } 
    7786 
     87     function test_08_Bounds_containsBounds(t) { 
     88         t.plan( 35 ); 
     89         containerBounds = new OpenLayers.Bounds(10,10,40,40); 
    7890 
     91         //totally outside 
     92         bounds = new OpenLayers.Bounds(0,0,5,5); 
     93         t.eq( containerBounds.containsBounds(bounds)              , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); 
     94         t.eq( containerBounds.containsBounds(bounds, false)       , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); 
     95         t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); 
     96         t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); 
     97         t.eq( containerBounds.containsBounds(bounds, true)        , false , "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true" ); 
     98         t.eq( containerBounds.containsBounds(bounds, true, true)  , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); 
     99         t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); 
     100 
     101         //totally outside on border 
     102         bounds = new OpenLayers.Bounds(15,0,30,10); 
     103         t.eq( containerBounds.containsBounds(bounds)              , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); 
     104         t.eq( containerBounds.containsBounds(bounds, false)       , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); 
     105         t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); 
     106         t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); 
     107         t.eq( containerBounds.containsBounds(bounds, true)        , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); 
     108         t.eq( containerBounds.containsBounds(bounds, true, true)  , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); 
     109         t.eq( containerBounds.containsBounds(bounds, true, false) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); 
     110 
     111         //partially inside 
     112         bounds = new OpenLayers.Bounds(20,20,50,30); 
     113         t.eq( containerBounds.containsBounds(bounds)              , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ")"); 
     114         t.eq( containerBounds.containsBounds(bounds, false)       , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false" ); 
     115         t.eq( containerBounds.containsBounds(bounds, false, true) , false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); 
     116         t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); 
     117         t.eq( containerBounds.containsBounds(bounds, true)        , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); 
     118         t.eq( containerBounds.containsBounds(bounds, true, true)  , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); 
     119         t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); 
     120 
     121         //totally inside on border 
     122         bounds = new OpenLayers.Bounds(10,20,30,30); 
     123         t.eq( containerBounds.containsBounds(bounds)              , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); 
     124         t.eq( containerBounds.containsBounds(bounds, false)       , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); 
     125         t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); 
     126         t.eq( containerBounds.containsBounds(bounds, false, false), false, "(" + containerBounds.toBBOX() + ") correctly does not contain (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); 
     127         t.eq( containerBounds.containsBounds(bounds, true)        , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); 
     128         t.eq( containerBounds.containsBounds(bounds, true, true)  , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); 
     129         t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); 
     130 
     131         //totally inside 
     132         bounds = new OpenLayers.Bounds(20,20,30,30); 
     133         t.eq( containerBounds.containsBounds(bounds)              , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ")"); 
     134         t.eq( containerBounds.containsBounds(bounds, false)       , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false" ); 
     135         t.eq( containerBounds.containsBounds(bounds, false, true) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is true" ); 
     136         t.eq( containerBounds.containsBounds(bounds, false, false), true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is false, inclusive is false" ); 
     137         t.eq( containerBounds.containsBounds(bounds, true)        , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true" ); 
     138         t.eq( containerBounds.containsBounds(bounds, true, true)  , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is true" ); 
     139         t.eq( containerBounds.containsBounds(bounds, true, false) , true, "(" + containerBounds.toBBOX() + ") correctly contains (" + bounds.toBBOX() + ") when partial is true, inclusive is false" ); 
     140     } 
     141      
     142      
    79143  // --> 
    80144  </script> 
  • trunk/openlayers/tests/test_Tile.html

    r104 r140  
    1212        t.ok( tile instanceof OpenLayers.Tile, "new OpenLayers.Tile returns Tile object" ); 
    1313        t.ok( tile.bounds instanceof OpenLayers.Bounds, "tile.bounds is a Bounds object" ); 
    14         t.eq( tile.bounds.minlon, 1, "tile.bounds.minlon is set correctly"); 
    15         t.eq( tile.bounds.minlat, 2, "tile.bounds.minlat is set correctly"); 
    16         t.eq( tile.bounds.maxlon, 3, "tile.bounds.maxlon is set correctly"); 
    17         t.eq( tile.bounds.maxlat, 4, "tile.bounds.maxlat is set correctly"); 
     14        t.eq( tile.bounds.left, 1, "tile.bounds.left is set correctly"); 
     15        t.eq( tile.bounds.bottom, 2, "tile.bounds.bottom is set correctly"); 
     16        t.eq( tile.bounds.right, 3, "tile.bounds.right is set correctly"); 
     17        t.eq( tile.bounds.top, 4, "tile.bounds.top is set correctly"); 
    1818        t.ok( tile.size instanceof OpenLayers.Size, "tile.size is a Size object" ); 
    1919        t.eq( tile.size.w, 5, "tile.size.w is set correctly"); 
  • trunk/openlayers/tests/test_Tile_Image.html

    r104 r140  
    1212        t.ok( tile instanceof OpenLayers.Tile.Image, "new OpenLayers.Tile returns Tile object" ); 
    1313        t.ok( tile.bounds instanceof OpenLayers.Bounds, "tile.bounds is a Bounds object" ); 
    14         t.eq( tile.bounds.minlon, 1, "tile.bounds.minlon is set correctly"); 
    15         t.eq( tile.bounds.minlat, 2, "tile.bounds.minlat is set correctly"); 
    16         t.eq( tile.bounds.maxlon, 3, "tile.bounds.maxlon is set correctly"); 
    17         t.eq( tile.bounds.maxlat, 4, "tile.bounds.maxlat is set correctly"); 
     14        t.eq( tile.bounds.left, 1, "tile.bounds.left is set correctly"); 
     15        t.eq( tile.bounds.bottom, 2, "tile.bounds.bottom is set correctly"); 
     16        t.eq( tile.bounds.right, 3, "tile.bounds.right is set correctly"); 
     17        t.eq( tile.bounds.top, 4, "tile.bounds.top is set correctly"); 
    1818        t.ok( tile.size instanceof OpenLayers.Size, "tile.size is a Size object" ); 
    1919        t.eq( tile.size.w, 5, "tile.size.w is set correctly");