OpenLayers OpenLayers

Ticket #793: basetypes.patch

File basetypes.patch, 71.6 kB (added by euzuro, 1 year ago)

split our basetypes out, leave core js basetypes in basetypes.js. Make corresponding updates to config files, OpenLayers.js

  • build/full.cfg

    old new  
    22OpenLayers/SingleFile.js 
    33OpenLayers.js 
    44OpenLayers/BaseTypes.js 
     5OpenLayers/BaseTypes/Class.js 
     6OpenLayers/BaseTypes/Bounds.js 
     7OpenLayers/BaseTypes/Element.js 
     8OpenLayers/BaseTypes/LonLat.js 
     9OpenLayers/BaseTypes/Pixel.js 
     10OpenLayers/BaseTypes/Size.js 
    511OpenLayers/Util.js 
    612Rico/Corner.js 
    713 
  • build/library.cfg

    old new  
    22OpenLayers/SingleFile.js 
    33OpenLayers.js 
    44OpenLayers/BaseTypes.js 
     5OpenLayers/BaseTypes/Class.js 
     6OpenLayers/BaseTypes/Bounds.js 
     7OpenLayers/BaseTypes/Element.js 
     8OpenLayers/BaseTypes/LonLat.js 
     9OpenLayers/BaseTypes/Pixel.js 
     10OpenLayers/BaseTypes/Size.js 
    511OpenLayers/Util.js 
    612Rico/Corner.js 
    713 
  • build/lite.cfg

    old new  
    22OpenLayers/SingleFile.js 
    33OpenLayers.js 
    44OpenLayers/BaseTypes.js 
     5OpenLayers/BaseTypes/Class.js 
     6OpenLayers/BaseTypes/Bounds.js 
     7OpenLayers/BaseTypes/Element.js 
     8OpenLayers/BaseTypes/LonLat.js 
     9OpenLayers/BaseTypes/Pixel.js 
     10OpenLayers/BaseTypes/Size.js 
    511OpenLayers/Util.js 
    612 
    713[last] 
  • lib/OpenLayers/BaseTypes/Class.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * Namespace: OpenLayers.Class 
     7 * Contains functions to create OpenLayers style classes. 
     8 */  
     9OpenLayers.Class = { 
     10    isPrototype: function () {}, // magic anonymous value 
     11 
     12    /** 
     13     * APIFunction: create 
     14     * Create an OpenLayers style class 
     15     * 
     16     * Return: 
     17     * An OpenLayers class 
     18     */ 
     19    create: function() { 
     20        return function() { 
     21            if (arguments && arguments[0] != OpenLayers.Class.isPrototype) 
     22                this.initialize.apply(this, arguments); 
     23        } 
     24    }, 
     25  
     26    /** 
     27     * APIFunction: inherit 
     28     * Inherit from one or more OpenLayers style classes 
     29     * 
     30     * Parameters: 
     31     * class - One or more classes can be provided as arguments 
     32     * 
     33     * Return: 
     34     * An object prototype 
     35     */ 
     36    inherit: function () { 
     37        var superClass = arguments[0]; 
     38        var proto = new superClass(OpenLayers.Class.isPrototype); 
     39        for (var i = 1; i < arguments.length; i++) { 
     40            if (typeof arguments[i] == "function") { 
     41                var mixin = arguments[i]; 
     42                arguments[i] = new mixin(OpenLayers.Class.isPrototype); 
     43            } 
     44            OpenLayers.Util.extend(proto, arguments[i]); 
     45 
     46            // This is a hack for IE see 
     47            // http://trac.openlayers.org/attachment/ticket/552 
     48            //  
     49            // The problem is that ie doesnt recognize toString as a property 
     50            //  so the util.extend() doesnt copy it over. we do it manually. 
     51            //  
     52            // to be revisited in 3.0 
     53            // 
     54            if((arguments[i].hasOwnProperty && arguments[i].hasOwnProperty('toString')) || 
     55               (!arguments[i].hasOwnProperty && arguments[i].toString)) { 
     56                proto.toString = arguments[i].toString; 
     57            } 
     58        } 
     59        return proto; 
     60    } 
     61}; 
     62 
     63/* 
     64    OpenLayers.Class.inherit( OpenLayers.Layer.Grid, OpenLayers.Layer.HTTPRequest, { 
     65        some stuff 
     66    }); 
     67*/ 
  • lib/OpenLayers/BaseTypes/Element.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * Namespace: OpenLayers.Element 
     7 */ 
     8OpenLayers.Element = { 
     9 
     10    /** 
     11     * APIFunction: visible 
     12     *  
     13     * Parameters:  
     14     * element - {DOMElement} 
     15     *  
     16     * Return: 
     17     * {Boolean} Is the element visible? 
     18     */ 
     19    visible: function(element) { 
     20        return OpenLayers.Util.getElement(element).style.display != 'none'; 
     21    }, 
     22 
     23    /** 
     24     * APIFunction: toggle 
     25     * Toggle the visibility of element(s) passed in 
     26     *  
     27     * Parameters: 
     28     * element - {DOMElement} Actually user can pass any number of elements 
     29     */ 
     30    toggle: function() { 
     31        for (var i = 0; i < arguments.length; i++) { 
     32            var element = OpenLayers.Util.getElement(arguments[i]); 
     33            var display = OpenLayers.Element.visible(element) ? 'hide'  
     34                                                              : 'show'; 
     35            OpenLayers.Element[display](element); 
     36        } 
     37    }, 
     38 
     39 
     40    /** 
     41     * APIFunction: hide 
     42     * Hide element(s) passed in 
     43     *  
     44     * Parameters: 
     45     * element - {DOMElement} Actually user can pass any number of elements 
     46     */ 
     47    hide: function() { 
     48        for (var i = 0; i < arguments.length; i++) { 
     49            var element = OpenLayers.Util.getElement(arguments[i]); 
     50            element.style.display = 'none'; 
     51        } 
     52    }, 
     53 
     54    /** 
     55     * APIFunction: show 
     56     * Show element(s) passed in 
     57     *  
     58     * Parameters: 
     59     * element - {DOMElement} Actually user can pass any number of elements 
     60     */ 
     61    show: function() { 
     62        for (var i = 0; i < arguments.length; i++) { 
     63            var element = OpenLayers.Util.getElement(arguments[i]); 
     64            element.style.display = ''; 
     65        } 
     66    }, 
     67 
     68    /** 
     69     * APIFunction: remove 
     70     * Remove the specified element from the DOM. 
     71     *  
     72     * Parameters: 
     73     * element - {DOMElement} 
     74     */ 
     75    remove: function(element) { 
     76        element = OpenLayers.Util.getElement(element); 
     77        element.parentNode.removeChild(element); 
     78    }, 
     79 
     80    /** 
     81     * APIFunction: getHeight 
     82     *   
     83     * Parameters: 
     84     * element - {DOMElement} 
     85     *  
     86     * Return: 
     87     * {Integer} The offset height of the element passed in 
     88     */ 
     89    getHeight: function(element) { 
     90        element = OpenLayers.Util.getElement(element); 
     91        return element.offsetHeight; 
     92    }, 
     93 
     94    /** 
     95     * APIFunction: getDimensions 
     96     *   
     97     * Parameters: 
     98     * element - {DOMElement} 
     99     *  
     100     * Return: 
     101     * {Object} Object with 'width' and 'height' properties which are the  
     102     *          dimensions of the element passed in. 
     103     */ 
     104    getDimensions: function(element) { 
     105        element = OpenLayers.Util.getElement(element); 
     106        if (OpenLayers.Element.getStyle(element, 'display') != 'none') { 
     107            return {width: element.offsetWidth, height: element.offsetHeight}; 
     108        } 
     109     
     110        // All *Width and *Height properties give 0 on elements with display none, 
     111        // so enable the element temporarily 
     112        var els = element.style; 
     113        var originalVisibility = els.visibility; 
     114        var originalPosition = els.position; 
     115        els.visibility = 'hidden'; 
     116        els.position = 'absolute'; 
     117        els.display = ''; 
     118        var originalWidth = element.clientWidth; 
     119        var originalHeight = element.clientHeight; 
     120        els.display = 'none'; 
     121        els.position = originalPosition; 
     122        els.visibility = originalVisibility; 
     123        return {width: originalWidth, height: originalHeight}; 
     124    }, 
     125 
     126    /** 
     127     * APIFunction: getStyle 
     128     *  
     129     * Parameters: 
     130     * element - {DOMElement} 
     131     * style - {?} 
     132     *  
     133     * Return: 
     134     * {?} 
     135     */ 
     136    getStyle: function(element, style) { 
     137        element = OpenLayers.Util.getElement(element); 
     138        var value = element.style[style.camelize()]; 
     139        if (!value) { 
     140            if (document.defaultView &&  
     141                document.defaultView.getComputedStyle) { 
     142                 
     143                var css = document.defaultView.getComputedStyle(element, null); 
     144                value = css ? css.getPropertyValue(style) : null; 
     145            } else if (element.currentStyle) { 
     146                value = element.currentStyle[style.camelize()]; 
     147            } 
     148        } 
     149     
     150        var positions = ['left', 'top', 'right', 'bottom']; 
     151        if (window.opera && 
     152            (OpenLayers.Util.indexOf(positions,style) != -1) && 
     153            (OpenLayers.Element.getStyle(element, 'position') == 'static')) {  
     154            value = 'auto'; 
     155        } 
     156     
     157        return value == 'auto' ? null : value; 
     158    } 
     159 
     160}; 
  • lib/OpenLayers/BaseTypes/LonLat.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * Class: OpenLayers.LonLat 
     7 * This class represents a longitude and latitude pair 
     8 */ 
     9OpenLayers.LonLat = OpenLayers.Class.create(); 
     10OpenLayers.LonLat.prototype = { 
     11 
     12    /**  
     13     * APIProperty: lon 
     14     * {Float} 
     15     */ 
     16    lon: 0.0, 
     17     
     18    /**  
     19     * APIProperty: lat 
     20     * {Float} 
     21     */ 
     22    lat: 0.0, 
     23 
     24    /** 
     25     * Constructor: OpenLayers.LonLat 
     26     * Create a new OpenLayers.LonLat instance 
     27     * 
     28     * Parameters: 
     29     * lon - {Number} The lon coordinate 
     30     * lat - {Number} The lat coordinate 
     31     */ 
     32    initialize: function(lon, lat) { 
     33        this.lon = parseFloat(lon); 
     34        this.lat = parseFloat(lat); 
     35    }, 
     36     
     37    /** 
     38     * Method: toString 
     39     * Return a readable string version of the lonlat 
     40     * 
     41     * Return: 
     42     * {String} String representation of OpenLayers.LonLat object.  
     43     *           (ex. <i>"lon=5,lat=42"</i>) 
     44     */ 
     45    toString:function() { 
     46        return ("lon=" + this.lon + ",lat=" + this.lat); 
     47    }, 
     48 
     49    /**  
     50     * APIMethod: toShortString 
     51     *  
     52     * Return: 
     53     * {String} Shortened String representation of OpenLayers.LonLat object.  
     54     *         (ex. <i>"5, 42"</i>) 
     55     */ 
     56    toShortString:function() { 
     57        return (this.lon + ", " + this.lat); 
     58    }, 
     59 
     60    /**  
     61     * APIMethod: clone 
     62     *  
     63     * Return: 
     64     * {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon  
     65     *                       and lat values 
     66     */ 
     67    clone:function() { 
     68        return new OpenLayers.LonLat(this.lon, this.lat); 
     69    }, 
     70 
     71    /**  
     72     * APIMethod: add 
     73     *  
     74     * Parameters: 
     75     * lon - {Float} 
     76     * lat - {Float} 
     77     *  
     78     * Return: 
     79     * {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and  
     80     *                       lat passed-in added to this's.  
     81     */ 
     82    add:function(lon, lat) { 
     83        return new OpenLayers.LonLat(this.lon + lon, this.lat + lat); 
     84    }, 
     85 
     86    /**  
     87     * APIMethod: equals 
     88     *  
     89     * Parameters: 
     90     * ll - {<OpenLayers.LonLat>} 
     91     *  
     92     * Return: 
     93     * {Boolean} Boolean value indicating whether the passed-in  
     94     *           <OpenLayers.LonLat> object has the same lon and lat  
     95     *           components as this. 
     96     *           Note: if ll passed in is null, returns false 
     97     */ 
     98    equals:function(ll) { 
     99        var equals = false; 
     100        if (ll != null) { 
     101            equals = ((this.lon == ll.lon && this.lat == ll.lat) || 
     102                      (isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat))); 
     103        } 
     104        return equals; 
     105    }, 
     106     
     107    /** 
     108     * APIMethod: wrapDateLine 
     109     *  
     110     * Parameters: 
     111     * maxExtent - {<OpenLayers.Bounds>} 
     112     *  
     113     * Return: 
     114     * {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the  
     115     *                       "dateline" (as specified by the borders of  
     116     *                       maxExtent) 
     117     */ 
     118    wrapDateLine: function(maxExtent) {     
     119 
     120        var newLonLat = this.clone(); 
     121     
     122        if (maxExtent) { 
     123            //shift right? 
     124            while (newLonLat.lon < maxExtent.left) { 
     125                newLonLat.lon +=  maxExtent.getWidth(); 
     126            }     
     127            
     128            //shift left? 
     129            while (newLonLat.lon > maxExtent.right) { 
     130                newLonLat.lon -= maxExtent.getWidth(); 
     131            }     
     132        } 
     133                 
     134        return newLonLat; 
     135    }, 
     136     
     137    /** @final @type String */ 
     138    CLASS_NAME: "OpenLayers.LonLat" 
     139}; 
     140 
     141/**  
     142 * Function: fromString 
     143 * Alternative constructor that builds a new <OpenLayers.LonLat> from a  
     144 *     parameter string 
     145 *  
     146 * Parameters: 
     147 * str - {String} Comma-separated Lon,Lat coordinate string.  
     148 *                 (ex. <i>"5,40"</i>) 
     149 *  
     150 * Return: 
     151 * {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the  
     152 *                       passed-in String. 
     153 */ 
     154OpenLayers.LonLat.fromString = function(str) { 
     155    var pair = str.split(","); 
     156    return new OpenLayers.LonLat(parseFloat(pair[0]),  
     157                                 parseFloat(pair[1])); 
     158}; 
  • lib/OpenLayers/BaseTypes/Bounds.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * Class: OpenLayers.Bounds 
     7 * Instances of this class represent bounding boxes.  Data stored as left, 
     8 * bottom, right, top floats 
     9 */ 
     10OpenLayers.Bounds = OpenLayers.Class.create(); 
     11OpenLayers.Bounds.prototype = { 
     12 
     13    /** 
     14     * Property: left 
     15     * {Number} 
     16     */ 
     17    left: 0.0, 
     18 
     19    /** 
     20     * Property: bottom 
     21     * {Number} 
     22     */ 
     23    bottom: 0.0, 
     24 
     25    /** 
     26     * Property: right 
     27     * {Number} 
     28     */ 
     29    right: 0.0, 
     30 
     31    /** 
     32     * Property: top 
     33     * {Number} 
     34     */ 
     35    top: 0.0,     
     36 
     37    /** 
     38     * Constructor: OpenLayers.Bounds 
     39     * Construct a new bounds object. 
     40     * 
     41     * Parameters: 
     42     * left - {Number} The left bounds of the box.  Note that for width 
     43     *        calculations, this is assumed to be less than the right value. 
     44     * bottom - {Number} The bottom bounds of the box.  Note that for height 
     45     *          calculations, this is assumed to be more than the top value. 
     46     * right - {Number} The right bounds. 
     47     * top - {Number} The top bounds. 
     48     */ 
     49    initialize: function(left, bottom, right, top) { 
     50        this.left = parseFloat(left); 
     51        this.bottom = parseFloat(bottom); 
     52        this.right = parseFloat(right); 
     53        this.top = parseFloat(top); 
     54    }, 
     55 
     56    /** 
     57     * Method: clone 
     58     * Create a cloned instance of this bounds. 
     59     * 
     60     * Return: 
     61     * {<OpenLayers.Bounds>} A fresh copy of the bounds 
     62     */ 
     63    clone:function() { 
     64        return new OpenLayers.Bounds(this.left, this.bottom,  
     65                                     this.right, this.top); 
     66    }, 
     67 
     68    /** 
     69     * Method: equals 
     70     * Test a two bounds for equivalence 
     71     * 
     72     * Parameters: 
     73     * bounds - {<OpenLayers.Bounds>} 
     74     * 
     75     * Return: 
     76     * {Boolean} The passed-in OpenLayers.Bounds object has the same left, 
     77     *           right, top, bottom components as this.  Note that if bounds  
     78     *           passed in is null, returns false. 
     79     */ 
     80    equals:function(bounds) { 
     81        var equals = false; 
     82        if (bounds != null) { 
     83            equals = ((this.left == bounds.left) &&  
     84                      (this.right == bounds.right) && 
     85                      (this.top == bounds.top) &&  
     86                      (this.bottom == bounds.bottom)); 
     87        } 
     88        return equals; 
     89    }, 
     90 
     91    /**  
     92     * APIMethod: toString 
     93     *  
     94     * Return: 
     95     * {String} String representation of OpenLayers.Bounds object.  
     96     *          (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>) 
     97     */ 
     98    toString:function() { 
     99        return ( "left-bottom=(" + this.left + "," + this.bottom + ")" 
     100                 + " right-top=(" + this.right + "," + this.top + ")" ); 
     101    }, 
     102 
     103    /**  
     104     * APIMethod: toBBOX 
     105     *  
     106     * Parameters: 
     107     * decimal - {Integer} How many significant digits in the bbox coords? 
     108     *                     Default is 6 
     109     *  
     110     * Return: 
     111     * {String} Simple String representation of OpenLayers.Bounds object. 
     112     *          (ex. <i>"5,42,10,45"</i>) 
     113     */ 
     114    toBBOX:function(decimal) { 
     115        if (decimal== null) { 
     116            decimal = 6;  
     117        } 
     118        var mult = Math.pow(10, decimal); 
     119        var bbox = Math.round(this.left * mult) / mult + "," +  
     120                   Math.round(this.bottom * mult) / mult + "," +  
     121                   Math.round(this.right * mult) / mult + "," +  
     122                   Math.round(this.top * mult) / mult; 
     123 
     124        return bbox; 
     125    }, 
     126     
     127    /** 
     128     * APIMethod: getWidth 
     129     *  
     130     * Return: 
     131     * {Float} The width of the bounds 
     132     */ 
     133    getWidth:function() { 
     134        return (this.right - this.left); 
     135    }, 
     136 
     137    /** 
     138     * APIMethod: getHeight 
     139     *  
     140     * Return: 
     141     * {Float} The height of the bounds 
     142     */ 
     143    getHeight:function() { 
     144        return (this.top - this.bottom); 
     145    }, 
     146 
     147    /** 
     148     * APIMethod: getSize 
     149     *  
     150     * Return: 
     151     * {<OpenLayers.Size>} An <OpenLayers.Size> which represents the size of the box 
     152     */ 
     153    getSize:function() { 
     154        return new OpenLayers.Size(this.getWidth(), this.getHeight()); 
     155    }, 
     156 
     157    /** 
     158     * APIMethod: getCenterPixel 
     159     *  
     160     * Return: 
     161     * {<OpenLayers.Pixel>} An <OpenLayers.Pixel> which represents the center  
     162     *                      of the bounds 
     163     */ 
     164    getCenterPixel:function() { 
     165        return new OpenLayers.Pixel( (this.left + this.right) / 2, 
     166                                     (this.bottom + this.top) / 2); 
     167    }, 
     168 
     169    /** 
     170     * APIMethod: getCenterLonLat 
     171     *  
     172     * Return: 
     173     * {<OpenLayers.LonLat>} An <OpenLayers.LonLat> which represents the center  
     174     *                      of the bounds 
     175     */ 
     176    getCenterLonLat:function() { 
     177        return new OpenLayers.LonLat( (this.left + this.right) / 2, 
     178                                      (this.bottom + this.top) / 2); 
     179    }, 
     180 
     181    /** 
     182     * APIMethod: add 
     183     *  
     184     * Parameters: 
     185     * x - {Float} 
     186     * y - {Float} 
     187     *  
     188     * Return: 
     189     * {<OpenLayers.Bounds>} A new <OpenLayers.Bounds> whose coordinates are  
     190     *                       the same as this, but shifted by the passed-in  
     191     *                       x and y values 
     192     */ 
     193    add:function(x, y) { 
     194        return new OpenLayers.Bounds(this.left + x, this.bottom + y, 
     195                                     this.right + x, this.top + y); 
     196    }, 
     197     
     198    /** 
     199     * APIMethod: extend 
     200     * Extend the bounds to include the point, lonlat, or bounds specified. 
     201     * Note: This function assumes that left<right and bottom<top. 
     202     *  
     203     *  
     204     * Parameters:  
     205     * object - {Object} Can be LonLat, Point, or Bounds 
     206     */ 
     207    extend:function(object) { 
     208        var bounds = null; 
     209        if (object) { 
     210            switch(object.CLASS_NAME) { 
     211                case "OpenLayers.LonLat":     
     212                    bounds = new OpenLayers.Bounds(object.lon, object.lat, 
     213                                                    object.lon, object.lat); 
     214                    break; 
     215                case "OpenLayers.Geometry.Point": 
     216                    bounds = new OpenLayers.Bounds(object.x, object.y, 
     217                                                    object.x, object.y); 
     218                    break; 
     219                     
     220                case "OpenLayers.Bounds":     
     221                    bounds = object; 
     222                    break; 
     223            } 
     224     
     225            if (bounds) { 
     226               this.left = (bounds.left < this.left) ? bounds.left  
     227                                                     : this.left; 
     228               this.bottom = (bounds.bottom < this.bottom) ? bounds.bottom  
     229                                                           : this.bottom; 
     230               this.right = (bounds.right > this.right) ? bounds.right  
     231                                                        : this.right; 
     232               this.top = (bounds.top > this.top) ? bounds.top  
     233                                                  : this.top; 
     234            } 
     235        } 
     236    }, 
     237 
     238    /** 
     239     * APIMethod: containsLonLat 
     240     *  
     241     * Parameters: 
     242     * ll - {<OpenLayers.LonLat>} 
     243     * inclusive - {Boolean} Whether or not to include the border.  
     244     *                       Default is true. 
     245     * 
     246     * Return: 
     247     * {Boolean} Whether or not the passed-in lonlat is within this bounds. 
     248     */ 
     249    containsLonLat:function(ll, inclusive) { 
     250        return this.contains(ll.lon, ll.lat, inclusive); 
     251    }, 
     252 
     253    /** 
     254     * APIMethod: containsPixel 
     255     *  
     256     * Parameters: 
     257     * px - {<OpenLayers.Pixel>} 
     258     * inclusive - {Boolean} Whether or not to include the border.  
     259     *                       Default is true. 
     260     * 
     261     * Return: 
     262     * {Boolean} Whether or not the passed-in pixel is within this bounds. 
     263     */ 
     264    containsPixel:function(px, inclusive) { 
     265        return this.contains(px.x, px.y, inclusive); 
     266    }, 
     267     
     268    /** 
     269     * APIMethod: contains 
     270     *  
     271     * Parameters: 
     272     * x - {Float} 
     273     * y - {Float} 
     274     * inclusive - {Boolean} Whether or not to include the border.  
     275     *                       Default is true. 
     276     * 
     277     * Return: 
     278     * {Boolean} Whether or not the passed-in coordinates are within this 
     279     *           bounds. 
     280     */ 
     281    contains:function(x, y, inclusive) { 
     282     
     283        //set default 
     284        if (inclusive == null) { 
     285            inclusive = true; 
     286        } 
     287         
     288        var contains = false; 
     289        if (inclusive) { 
     290            contains = ((x >= this.left) && (x <= this.right) &&  
     291                        (y >= this.bottom) && (y <= this.top)); 
     292        } else { 
     293            contains = ((x > this.left) && (x < this.right) &&  
     294                        (y > this.bottom) && (y < this.top)); 
     295        }               
     296        return contains; 
     297    }, 
     298 
     299    /** 
     300     * APIMethod: intersectsBounds 
     301     *  
     302     * Parameters: 
     303     * bounds - {<OpenLayers.Bounds>} 
     304     * inclusive - {<Boolean>} Whether or not to include the border.  
     305     *                         Default is true. 
     306     * 
     307     * Return: 
     308     * {Boolean} Whether or not the passed-in OpenLayers.Bounds object  
     309     *           intersects this bounds. Simple math just check if either  
     310     *           contains the other, allowing for partial. 
     311     */ 
     312    intersectsBounds:function(bounds, inclusive) { 
     313 
     314        if (inclusive == null) { 
     315            inclusive = true; 
     316        } 
     317        var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ? 
     318                    true : (((bounds.bottom > this.bottom) && (bounds.bottom < this.top)) ||  
     319                           ((this.bottom > bounds.bottom) && (this.bottom < bounds.top)));  
     320        var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ? 
     321                    true : (((bounds.top > this.bottom) && (bounds.top < this.top)) || 
     322                           ((this.top > bounds.bottom) && (this.top < bounds.top)));  
     323        var inRight = (bounds.right == this.right && bounds.left == this.left) ? 
     324                    true : (((bounds.right > this.left) && (bounds.right < this.right)) || 
     325                           ((this.right > bounds.left) && (this.right < bounds.right)));  
     326        var inLeft = (bounds.right == this.right && bounds.left == this.left) ? 
     327                    true : (((bounds.left > this.left) && (bounds.left < this.right)) ||  
     328                           ((this.left > bounds.left) && (this.left < bounds.right)));  
     329 
     330        return (this.containsBounds(bounds, true, inclusive) || 
     331                bounds.containsBounds(this, true, inclusive) || 
     332                ((inTop || inBottom ) && (inLeft || inRight ))); 
     333    }, 
     334     
     335    /** 
     336     * APIMethod: containsBounds 
     337     *  
     338     * bounds - {<OpenLayers.Bounds>} 
     339     * partial - {<Boolean>} If true, only part of passed-in  
     340     *                       <OpenLayers.Bounds> needs be within this bounds.  
     341     *                       If false, the entire passed-in bounds must be 
     342     *                       within. Default is false 
     343     * inclusive - {<Boolean>} Whether or not to include the border.  
     344     *                         Default is true. 
     345     * 
     346     * Return: 
     347     * {Boolean} Whether or not the passed-in OpenLayers.Bounds object is  
     348     *           contained within this bounds.  
     349     */ 
     350    containsBounds:function(bounds, partial, inclusive) { 
     351 
     352        //set defaults 
     353        if (partial == null) { 
     354            partial = false; 
     355        } 
     356        if (inclusive == null) { 
     357            inclusive = true; 
     358        } 
     359 
     360        var inLeft; 
     361        var inTop; 
     362        var inRight; 
     363        var inBottom; 
     364         
     365        if (inclusive) { 
     366            inLeft = (bounds.left >= this.left) && (bounds.left <= this.right); 
     367            inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top); 
     368            inRight= (bounds.right >= this.left) && (bounds.right <= this.right); 
     369            inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top); 
     370        } else { 
     371            inLeft = (bounds.left > this.left) && (bounds.left < this.right); 
     372            inTop = (bounds.top > this.bottom) && (bounds.top < this.top); 
     373            inRight= (bounds.right > this.left) && (bounds.right < this.right); 
     374            inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top); 
     375        } 
     376         
     377        return (partial) ? (inTop || inBottom ) && (inLeft || inRight )  
     378                         : (inTop && inLeft && inBottom && inRight); 
     379    }, 
     380 
     381    /**  
     382     * APIMethod: determineQuadrant 
     383     *  
     384     * Parameters: 
     385     * lonlat - {<OpenLayers.LonLat>} 
     386     *  
     387     * Return: 
     388     * {String} The quadrant ("br" "tr" "tl" "bl") of the bounds in which  
     389     *          the coordinate lies. 
     390     */ 
     391    determineQuadrant: function(lonlat) { 
     392     
     393        var quadrant = ""; 
     394        var center = this.getCenterLonLat(); 
     395         
     396        quadrant += (lonlat.lat < center.lat) ? "b" : "t"; 
     397        quadrant += (lonlat.lon < center.lon) ? "l" : "r"; 
     398     
     399        return quadrant;  
     400    }, 
     401 
     402    /** 
     403     * APIMethod: wrapDateLine 
     404     *   
     405     * Parameters: 
     406     * maxExtent - {<OpenLayers.Bounds>} 
     407     * options - {Object} Some possible options are: 
     408     *                    leftTolerance - {float} Allow for a margin of error  
     409     *                                            with the 'left' value of this  
     410     *                                            bound. 
     411     *                                            Default is 0. 
     412     *                    rightTolerance - {float} Allow for a margin of error  
     413     *                                             with the 'right' value of  
     414     *                                             this bound. 
     415     *                                             Default is 0. 
     416     *  
     417     * Return: 
     418     * {<OpenLayers.Bounds>} A copy of this bounds, but wrapped around the  
     419     *                       "dateline" (as specified by the borders of  
     420     *                       maxExtent). Note that this function only returns  
     421     *                       a different bounds value if this bounds is  
     422     *                       *entirely* outside of the maxExtent. If this  
     423     *                       bounds straddles the dateline (is part in/part  
     424     *                       out of maxExtent), the returned bounds will be  
     425     *                       merely a copy of this one. 
     426     */ 
     427    wrapDateLine: function(maxExtent, options) {     
     428        options = options || new Object(); 
     429         
     430        var leftTolerance = options.leftTolerance || 0; 
     431        var rightTolerance = options.rightTolerance || 0; 
     432 
     433        var newBounds = this.clone(); 
     434     
     435        if (maxExtent) { 
     436 
     437           //shift right? 
     438           while ( newBounds.left < maxExtent.left &&  
     439                   (newBounds.right - rightTolerance) <= maxExtent.left ) {  
     440                newBounds = newBounds.add(maxExtent.getWidth(), 0); 
     441           } 
     442 
     443           //shift left? 
     444           while ( (newBounds.left + leftTolerance) >= maxExtent.right &&  
     445                   newBounds.right > maxExtent.right ) {  
     446                newBounds = newBounds.add(-maxExtent.getWidth(), 0); 
     447           } 
     448        } 
     449                 
     450        return newBounds; 
     451    }, 
     452     
     453    /** @final @type String */ 
     454    CLASS_NAME: "OpenLayers.Bounds" 
     455}; 
     456 
     457/**  
     458 * APIFunction: fromString 
     459 * Alternative constructor that builds a new OpenLayers.Bounds from a  
     460 *     parameter string 
     461 *  
     462 * Parameters:  
     463 * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>) 
     464 *  
     465 * Return: 
     466 * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the  
     467 *                       passed-in String. 
     468 */ 
     469OpenLayers.Bounds.fromString = function(str) { 
     470    var bounds = str.split(","); 
     471    return OpenLayers.Bounds.fromArray(bounds); 
     472}; 
     473 
     474/**  
     475 * APIFunction: fromArray 
     476 * Alternative constructor that builds a new OpenLayers.Bounds 
     477 *     from an array 
     478 *  
     479 * Parameters: 
     480 * bbox - {Array} Array of bounds values (ex. <i>[5,42,10,45]</i>) 
     481 * 
     482 * Return: 
     483 * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the  
     484 *                       passed-in Array. 
     485 */ 
     486OpenLayers.Bounds.fromArray = function(bbox) { 
     487    return new OpenLayers.Bounds(parseFloat(bbox[0]), 
     488                                 parseFloat(bbox[1]), 
     489                                 parseFloat(bbox[2]), 
     490                                 parseFloat(bbox[3])); 
     491}; 
     492 
     493/**  
     494 * APIFunction: fromSize 
     495 * Alternative constructor that builds a new OpenLayers.Bounds 
     496 *     from a size 
     497 *  
     498 * Parameters: 
     499 * size - {<OpenLayers.Size>}  
     500 * 
     501 * Return: 
     502 * {<OpenLayers.Bounds>} New <OpenLayers.Bounds> object built from the  
     503 *                       passed-in size. 
     504 */ 
     505OpenLayers.Bounds.fromSize = function(size) { 
     506    return new OpenLayers.Bounds(0, 
     507                                 size.h, 
     508                                 size.w, 
     509                                 0); 
     510}; 
     511 
     512/** 
     513 * Function: oppositeQuadrant 
     514 * Get the opposite quadrant for a given quadrant string. 
     515 * 
     516 * Parameters: 
     517 * quadrant - {String} two character quadrant shortstring 
     518 * 
     519 * Return: 
     520 * {String} The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if  
     521 *          you pass in "bl" it returns "tr", if you pass in "br" it  
     522 *          returns "tl", etc. 
     523 */ 
     524OpenLayers.Bounds.oppositeQuadrant = function(quadrant) { 
     525    var opp = ""; 
     526     
     527    opp += (quadrant.charAt(0) == 't') ? 'b' : 't'; 
     528    opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l'; 
     529     
     530    return opp; 
     531}; 
  • lib/OpenLayers/BaseTypes/Size.js

    old new  
     1/* Copyright (c) 2006 MetaCarta, Inc., published under a modified BSD license. 
     2 * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt  
     3 * for the full text of the license. */ 
     4 
     5/** 
     6 * Class: OpenLayers.Size 
     7 * Instances of this class represent a width/height pair 
     8 */ 
     9OpenLayers.Size = OpenLayers.Class.create(); 
     10OpenLayers.Size.prototype = { 
     11 
     12    /** 
     13     * APIProperty: w 
     14     * {Number} width 
     15     */ 
     16    w: 0.0, 
     17     
     18    /** 
     19     * APIProperty: h 
     20     * {Number} height 
     21     */ 
     22    h: 0.0, 
     23 
     24 
     25    /** 
     26     * Constructor: OpenLayers.Size 
     27     * Create an instance of OpenLayers.Size 
     28     * 
     29     * Parameters: 
     30     * w - {Number} width 
     31     * h - {Number} height 
     32     */ 
     33    initialize: function(w, h) { 
     34        this.w = parseFloat(w); 
     35        this.h = parseFloat(h); 
     36    }, 
     37 
     38    /** 
     39     * Method: toString 
     40     * Return the string representation of a size object 
     41     * 
     42     * Return: 
     43     * {String} The string representation of OpenLayers.Size object.  
     44     * (ex. <i>"w=55,h=66"</i>) 
     45     */ 
     46    toString:function() { 
     47        return ("w=" + this.w + ",h=" + this.h); 
     48    }, 
     49 
     50    /** 
     51     * APIMethod: clone 
     52     * Create a clone of this size object 
     53     * 
     54     * Return: 
     55     * {<OpenLayers.Size>} A new OpenLayers.Size object with the same w and h 
     56     * values 
     57     */ 
     58    clone:function() { 
     59        return new OpenLayers.Size(this.w, this.h); 
     60    }, 
     61 
     62    /** 
     63     * 
     64     * APIMethod: equals 
     65     * Determine where this size is equal to another 
     66     * 
     67     * Parameters: 
     68     * sz - {<OpenLayers.Size>} 
     69     * 
     70     * Return:  
     71     * {Boolean} The passed in size has the same h and w properties as this one. 
     72     * Note that if sz passed in is null, returns false. 
     73     * 
     74     */ 
     75    equals:function(sz) { 
     76