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

📄 geometry.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
字号:
/* 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. */ /** * @requires OpenLayers/Format/WKT.js * @requires OpenLayers/Feature/Vector.js *  * Class: OpenLayers.Geometry * A Geometry is a description of a geographic object.  Create an instance of * this class with the <OpenLayers.Geometry> constructor.  This is a base class, * typical geometry types are described by subclasses of this class. */OpenLayers.Geometry = OpenLayers.Class({    /**     * Property: id     * {String} A unique identifier for this geometry.     */    id: null,    /**     * Property: parent     * {<OpenLayers.Geometry>}This is set when a Geometry is added as component     * of another geometry     */    parent: null,    /**     * Property: bounds      * {<OpenLayers.Bounds>} The bounds of this geometry     */    bounds: null,    /**     * Constructor: OpenLayers.Geometry     * Creates a geometry object.       */    initialize: function() {        this.id = OpenLayers.Util.createUniqueID(this.CLASS_NAME+ "_");    },        /**     * Method: destroy     * Destroy this geometry.     */    destroy: function() {        this.id = null;        this.bounds = null;    },        /**     * APIMethod: clone     * Create a clone of this geometry.  Does not set any non-standard     *     properties of the cloned geometry.     *      * Returns:     * {<OpenLayers.Geometry>} An exact clone of this geometry.     */    clone: function() {        return new OpenLayers.Geometry();    },        /**     * Set the bounds for this Geometry.     *      * Parameters:     * object - {<OpenLayers.Bounds>}      */    setBounds: function(bounds) {        if (bounds) {            this.bounds = bounds.clone();        }    },        /**     * Method: clearBounds     * Nullify this components bounds and that of its parent as well.     */    clearBounds: function() {        this.bounds = null;        if (this.parent) {            this.parent.clearBounds();        }        },        /**     * Method: extendBounds     * Extend the existing bounds to include the new bounds.      * If geometry's bounds is not yet set, then set a new Bounds.     *      * Parameters:     * newBounds - {<OpenLayers.Bounds>}      */    extendBounds: function(newBounds){        var bounds = this.getBounds();        if (!bounds) {            this.setBounds(newBounds);        } else {            this.bounds.extend(newBounds);        }    },        /**     * APIMethod: getBounds     * Get the bounds for this Geometry. If bounds is not set, it      * is calculated again, this makes queries faster.     *      * Returns:     * {<OpenLayers.Bounds>}     */    getBounds: function() {        if (this.bounds == null) {            this.calculateBounds();        }        return this.bounds;    },        /**      * APIMethod: calculateBounds     * Recalculate the bounds for the geometry.      */    calculateBounds: function() {        //        // This should be overridden by subclasses.        //    },        /**     * Method: atPoint     * Note - This is only an approximation based on the bounds of the      * geometry.     *      * Parameters:     * lonlat - {<OpenLayers.LonLat>}      * toleranceLon - {float} Optional tolerance in Geometric Coords     * toleranceLat - {float} Optional tolerance in Geographic Coords     *      * Returns:     * {Boolean} Whether or not the geometry is at the specified location     */    atPoint: function(lonlat, toleranceLon, toleranceLat) {        var atPoint = false;        var bounds = this.getBounds();        if ((bounds != null) && (lonlat != null)) {            var dX = (toleranceLon != null) ? toleranceLon : 0;            var dY = (toleranceLat != null) ? toleranceLat : 0;                var toleranceBounds =                 new OpenLayers.Bounds(this.bounds.left - dX,                                      this.bounds.bottom - dY,                                      this.bounds.right + dX,                                      this.bounds.top + dY);            atPoint = toleranceBounds.containsLonLat(lonlat);        }        return atPoint;    },        /**     * Method: getLength     * Calculate the length of this geometry. This method is defined in     * subclasses.     *      * Returns:     * {Float} The length of the collection by summing its parts     */    getLength: function() {        //to be overridden by geometries that actually have a length        //        return 0.0;    },    /**     * Method: getArea     * Calculate the area of this geometry. This method is defined in subclasses.     *      * Returns:     * {Float} The area of the collection by summing its parts     */    getArea: function() {        //to be overridden by geometries that actually have an area        //        return 0.0;    },    /**     * Method: toString     * Returns the Well-Known Text representation of a geometry     *     * Returns:     * {String} Well-Known Text     */    toString: function() {        return OpenLayers.Format.WKT.prototype.write(            new OpenLayers.Feature.Vector(this)        );    },    CLASS_NAME: "OpenLayers.Geometry"});

⌨️ 快捷键说明

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