⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bounds.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 2 页
字号:
        return this.contains(ll.lon, ll.lat, inclusive);    },    /**     * APIMethod: containsPixel     *      * Parameters:     * px - {<OpenLayers.Pixel>}     * inclusive - {Boolean} Whether or not to include the border. Default is     *     true.     *     * Returns:     * {Boolean} The passed-in pixel is within this bounds.     */    containsPixel:function(px, inclusive) {        return this.contains(px.x, px.y, inclusive);    },        /**     * APIMethod: contains     *      * Parameters:     * x - {Float}     * y - {Float}     * inclusive - {Boolean} Whether or not to include the border. Default is     *     true.     *     * Returns:     * {Boolean} Whether or not the passed-in coordinates are within this     *     bounds.     */    contains:function(x, y, inclusive) {            //set default        if (inclusive == null) {            inclusive = true;        }                var contains = false;        if (inclusive) {            contains = ((x >= this.left) && (x <= this.right) &&                         (y >= this.bottom) && (y <= this.top));        } else {            contains = ((x > this.left) && (x < this.right) &&                         (y > this.bottom) && (y < this.top));        }                      return contains;    },    /**     * APIMethod: intersectsBounds     *      * Parameters:     * bounds - {<OpenLayers.Bounds>}     * inclusive - {<Boolean>} Whether or not to include the border.  Default     *     is true.     *     * Returns:     * {Boolean} The passed-in OpenLayers.Bounds object intersects this bounds.     *     Simple math just check if either contains the other, allowing for     *     partial.     */    intersectsBounds:function(bounds, inclusive) {        if (inclusive == null) {            inclusive = true;        }        var inBottom = (bounds.bottom == this.bottom && bounds.top == this.top) ?                    true : (((bounds.bottom > this.bottom) && (bounds.bottom < this.top)) ||                            ((this.bottom > bounds.bottom) && (this.bottom < bounds.top)));         var inTop = (bounds.bottom == this.bottom && bounds.top == this.top) ?                    true : (((bounds.top > this.bottom) && (bounds.top < this.top)) ||                           ((this.top > bounds.bottom) && (this.top < bounds.top)));         var inRight = (bounds.right == this.right && bounds.left == this.left) ?                    true : (((bounds.right > this.left) && (bounds.right < this.right)) ||                           ((this.right > bounds.left) && (this.right < bounds.right)));         var inLeft = (bounds.right == this.right && bounds.left == this.left) ?                    true : (((bounds.left > this.left) && (bounds.left < this.right)) ||                            ((this.left > bounds.left) && (this.left < bounds.right)));         return (this.containsBounds(bounds, true, inclusive) ||                bounds.containsBounds(this, true, inclusive) ||                ((inTop || inBottom ) && (inLeft || inRight )));    },        /**     * APIMethod: containsBounds     *      * bounds - {<OpenLayers.Bounds>}     * partial - {<Boolean>} If true, only part of passed-in bounds needs be     *     within this bounds.  If false, the entire passed-in bounds must be     *     within. Default is false     * inclusive - {<Boolean>} Whether or not to include the border. Default is     *     true.     *     * Returns:     * {Boolean} The passed-in bounds object is contained within this bounds.      */    containsBounds:function(bounds, partial, inclusive) {        //set defaults        if (partial == null) {            partial = false;        }        if (inclusive == null) {            inclusive = true;        }        var inLeft;        var inTop;        var inRight;        var inBottom;                if (inclusive) {            inLeft = (bounds.left >= this.left) && (bounds.left <= this.right);            inTop = (bounds.top >= this.bottom) && (bounds.top <= this.top);            inRight= (bounds.right >= this.left) && (bounds.right <= this.right);            inBottom = (bounds.bottom >= this.bottom) && (bounds.bottom <= this.top);        } else {            inLeft = (bounds.left > this.left) && (bounds.left < this.right);            inTop = (bounds.top > this.bottom) && (bounds.top < this.top);            inRight= (bounds.right > this.left) && (bounds.right < this.right);            inBottom = (bounds.bottom > this.bottom) && (bounds.bottom < this.top);        }                return (partial) ? (inTop || inBottom ) && (inLeft || inRight )                          : (inTop && inLeft && inBottom && inRight);    },    /**      * APIMethod: determineQuadrant     *      * Parameters:     * lonlat - {<OpenLayers.LonLat>}     *      * Returns:     * {String} The quadrant ("br" "tr" "tl" "bl") of the bounds in which the     *     coordinate lies.     */    determineQuadrant: function(lonlat) {            var quadrant = "";        var center = this.getCenterLonLat();                quadrant += (lonlat.lat < center.lat) ? "b" : "t";        quadrant += (lonlat.lon < center.lon) ? "l" : "r";            return quadrant;     },    /**     * APIMethod: wrapDateLine     *       * Parameters:     * maxExtent - {<OpenLayers.Bounds>}     * options - {Object} Some possible options are:     *                    leftTolerance - {float} Allow for a margin of error      *                                            with the 'left' value of this      *                                            bound.     *                                            Default is 0.     *                    rightTolerance - {float} Allow for a margin of error      *                                             with the 'right' value of      *                                             this bound.     *                                             Default is 0.     *      * Returns:     * {<OpenLayers.Bounds>} A copy of this bounds, but wrapped around the      *                       "dateline" (as specified by the borders of      *                       maxExtent). Note that this function only returns      *                       a different bounds value if this bounds is      *                       *entirely* outside of the maxExtent. If this      *                       bounds straddles the dateline (is part in/part      *                       out of maxExtent), the returned bounds will be      *                       merely a copy of this one.     */    wrapDateLine: function(maxExtent, options) {            options = options || {};                var leftTolerance = options.leftTolerance || 0;        var rightTolerance = options.rightTolerance || 0;        var newBounds = this.clone();            if (maxExtent) {           //shift right?           while ( newBounds.left < maxExtent.left &&                    (newBounds.right - rightTolerance) <= maxExtent.left ) {                 newBounds = newBounds.add(maxExtent.getWidth(), 0);           }           //shift left?           while ( (newBounds.left + leftTolerance) >= maxExtent.right &&                    newBounds.right > maxExtent.right ) {                 newBounds = newBounds.add(-maxExtent.getWidth(), 0);           }        }                        return newBounds;    },    CLASS_NAME: "OpenLayers.Bounds"});/**  * APIFunction: fromString * Alternative constructor that builds a new OpenLayers.Bounds from a  *     parameter string *  * Parameters:  * str - {String}Comma-separated bounds string. (ex. <i>"5,42,10,45"</i>) *  * Returns: * {<OpenLayers.Bounds>} New bounds object built from the  *                       passed-in String. */OpenLayers.Bounds.fromString = function(str) {    var bounds = str.split(",");    return OpenLayers.Bounds.fromArray(bounds);};/**  * APIFunction: fromArray * Alternative constructor that builds a new OpenLayers.Bounds *     from an array *  * Parameters: * bbox - {Array(Float)} Array of bounds values (ex. <i>[5,42,10,45]</i>) * * Returns: * {<OpenLayers.Bounds>} New bounds object built from the passed-in Array. */OpenLayers.Bounds.fromArray = function(bbox) {    return new OpenLayers.Bounds(parseFloat(bbox[0]),                                 parseFloat(bbox[1]),                                 parseFloat(bbox[2]),                                 parseFloat(bbox[3]));};/**  * APIFunction: fromSize * Alternative constructor that builds a new OpenLayers.Bounds *     from a size *  * Parameters: * size - {<OpenLayers.Size>}  * * Returns: * {<OpenLayers.Bounds>} New bounds object built from the passed-in size. */OpenLayers.Bounds.fromSize = function(size) {    return new OpenLayers.Bounds(0,                                 size.h,                                 size.w,                                 0);};/** * Function: oppositeQuadrant * Get the opposite quadrant for a given quadrant string. * * Parameters: * quadrant - {String} two character quadrant shortstring * * Returns: * {String} The opposing quadrant ("br" "tr" "tl" "bl"). For Example, if  *          you pass in "bl" it returns "tr", if you pass in "br" it  *          returns "tl", etc. */OpenLayers.Bounds.oppositeQuadrant = function(quadrant) {    var opp = "";        opp += (quadrant.charAt(0) == 't') ? 'b' : 't';    opp += (quadrant.charAt(1) == 'l') ? 'r' : 'l';        return opp;};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -