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

📄 bounds.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 2 页
字号:
/* Copyright (c) 2006-2007 MetaCarta, Inc., published under the BSD license. * See http://svn.openlayers.org/trunk/openlayers/release-license.txt  * for the full text of the license. *//** * Class: OpenLayers.Bounds * Instances of this class represent bounding boxes.  Data stored as left, * bottom, right, top floats. All values are initialized to null, however, * you should make sure you set them before using the bounds for anything. *  * Possible use case: * > bounds = new OpenLayers.Bounds(); * > bounds.extend(new OpenLayers.LonLat(4,5)); * > bounds.extend(new OpenLayers.LonLat(5,6)); * > bounds.toBBOX(); // returns 4,5,5,6 */OpenLayers.Bounds = OpenLayers.Class({    /**     * Property: left     * {Number}     */    left: null,    /**     * Property: bottom     * {Number}     */    bottom: null,    /**     * Property: right     * {Number}     */    right: null,    /**     * Property: top     * {Number}     */    top: null,        /**     * Constructor: OpenLayers.Bounds     * Construct a new bounds object.     *     * Parameters:     * left - {Number} The left bounds of the box.  Note that for width     *        calculations, this is assumed to be less than the right value.     * bottom - {Number} The bottom bounds of the box.  Note that for height     *          calculations, this is assumed to be more than the top value.     * right - {Number} The right bounds.     * top - {Number} The top bounds.     */    initialize: function(left, bottom, right, top) {        if (left != null) {            this.left = parseFloat(left);        }        if (bottom != null) {            this.bottom = parseFloat(bottom);        }        if (right != null) {            this.right = parseFloat(right);        }        if (top != null) {            this.top = parseFloat(top);        }    },    /**     * Method: clone     * Create a cloned instance of this bounds.     *     * Returns:     * {<OpenLayers.Bounds>} A fresh copy of the bounds     */    clone:function() {        return new OpenLayers.Bounds(this.left, this.bottom,                                      this.right, this.top);    },    /**     * Method: equals     * Test a two bounds for equivalence.     *     * Parameters:     * bounds - {<OpenLayers.Bounds>}     *     * Returns:     * {Boolean} The passed-in bounds object has the same left,     *           right, top, bottom components as this.  Note that if bounds      *           passed in is null, returns false.     */    equals:function(bounds) {        var equals = false;        if (bounds != null) {            equals = ((this.left == bounds.left) &&                       (this.right == bounds.right) &&                      (this.top == bounds.top) &&                       (this.bottom == bounds.bottom));        }        return equals;    },    /**      * APIMethod: toString     *      * Returns:     * {String} String representation of bounds object.      *          (ex.<i>"left-bottom=(5,42) right-top=(10,45)"</i>)     */    toString:function() {        return ( "left-bottom=(" + this.left + "," + this.bottom + ")"                 + " right-top=(" + this.right + "," + this.top + ")" );    },    /**     * APIMethod: toArray     *     * Returns:     * {Array} array of left, bottom, right, top     */    toArray: function() {        return [this.left, this.bottom, this.right, this.top];    },        /**      * APIMethod: toBBOX     *      * Parameters:     * decimal - {Integer} How many significant digits in the bbox coords?     *                     Default is 6     *      * Returns:     * {String} Simple String representation of bounds object.     *          (ex. <i>"5,42,10,45"</i>)     */    toBBOX:function(decimal) {        if (decimal== null) {            decimal = 6;         }        var mult = Math.pow(10, decimal);        var bbox = Math.round(this.left * mult) / mult + "," +                    Math.round(this.bottom * mult) / mult + "," +                    Math.round(this.right * mult) / mult + "," +                    Math.round(this.top * mult) / mult;        return bbox;    },        /**     * APIMethod: getWidth     *      * Returns:     * {Float} The width of the bounds     */    getWidth:function() {        return (this.right - this.left);    },    /**     * APIMethod: getHeight     *      * Returns:     * {Float} The height of the bounds (top minus bottom).     */    getHeight:function() {        return (this.top - this.bottom);    },    /**     * APIMethod: getSize     *      * Returns:     * {<OpenLayers.Size>} The size of the box.     */    getSize:function() {        return new OpenLayers.Size(this.getWidth(), this.getHeight());    },    /**     * APIMethod: getCenterPixel     *      * Returns:     * {<OpenLayers.Pixel>} The center of the bounds in pixel space.     */    getCenterPixel:function() {        return new OpenLayers.Pixel( (this.left + this.right) / 2,                                     (this.bottom + this.top) / 2);    },    /**     * APIMethod: getCenterLonLat     *      * Returns:     * {<OpenLayers.LonLat>} The center of the bounds in map space.     */    getCenterLonLat:function() {        return new OpenLayers.LonLat( (this.left + this.right) / 2,                                      (this.bottom + this.top) / 2);    },    /**     * APIMethod: add     *      * Parameters:     * x - {Float}     * y - {Float}     *      * Returns:     * {<OpenLayers.Bounds>} A new bounds whose coordinates are the same as     *     this, but shifted by the passed-in x and y values.     */    add:function(x, y) {        if ( (x == null) || (y == null) ) {            var msg = "You must pass both x and y values to the add function.";            OpenLayers.Console.error(msg);            return null;        }        return new OpenLayers.Bounds(this.left + x, this.bottom + y,                                     this.right + x, this.top + y);    },        /**     * APIMethod: extend     * Extend the bounds to include the point, lonlat, or bounds specified.     *     Note, this function assumes that left < right and bottom < top.     *      * Parameters:      * object - {Object} Can be LonLat, Point, or Bounds     */    extend:function(object) {        var bounds = null;        if (object) {            switch(object.CLASS_NAME) {                case "OpenLayers.LonLat":                        bounds = new OpenLayers.Bounds(object.lon, object.lat,                                                    object.lon, object.lat);                    break;                case "OpenLayers.Geometry.Point":                    bounds = new OpenLayers.Bounds(object.x, object.y,                                                    object.x, object.y);                    break;                                    case "OpenLayers.Bounds":                        bounds = object;                    break;            }                if (bounds) {                if ( (this.left == null) || (bounds.left < this.left)) {                    this.left = bounds.left;                }                if ( (this.bottom == null) || (bounds.bottom < this.bottom) ) {                    this.bottom = bounds.bottom;                }                 if ( (this.right == null) || (bounds.right > this.right) ) {                    this.right = bounds.right;                }                if ( (this.top == null) || (bounds.top > this.top) ) {                     this.top = bounds.top;                }            }        }    },    /**     * APIMethod: containsLonLat     *      * Parameters:     * ll - {<OpenLayers.LonLat>}     * inclusive - {Boolean} Whether or not to include the border.     *     Default is true.     *     * Returns:     * {Boolean} The passed-in lonlat is within this bounds.     */    containsLonLat:function(ll, inclusive) {

⌨️ 快捷键说明

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