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

📄 lonlat.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. *//** * Class: OpenLayers.LonLat * This class represents a longitude and latitude pair */OpenLayers.LonLat = OpenLayers.Class({    /**      * APIProperty: lon     * {Float} The x-axis coodinate in map units     */    lon: 0.0,        /**      * APIProperty: lat     * {Float} The y-axis coordinate in map units     */    lat: 0.0,    /**     * Constructor: OpenLayers.LonLat     * Create a new map location.     *     * Parameters:     * lon - {Number} The x-axis coordinate in map units.  If your map is in     *     a geographic projection, this will be the Longitude.  Otherwise,     *     it will be the x coordinate of the map location in your map units.     * lat - {Number} The y-axis coordinate in map units.  If your map is in     *     a geographic projection, this will be the Latitude.  Otherwise,     *     it will be the y coordinate of the map location in your map units.     */    initialize: function(lon, lat) {        this.lon = parseFloat(lon);        this.lat = parseFloat(lat);    },        /**     * Method: toString     * Return a readable string version of the lonlat     *     * Returns:     * {String} String representation of OpenLayers.LonLat object.      *           (ex. <i>"lon=5,lat=42"</i>)     */    toString:function() {        return ("lon=" + this.lon + ",lat=" + this.lat);    },    /**      * APIMethod: toShortString     *      * Returns:     * {String} Shortened String representation of OpenLayers.LonLat object.      *         (ex. <i>"5, 42"</i>)     */    toShortString:function() {        return (this.lon + ", " + this.lat);    },    /**      * APIMethod: clone     *      * Returns:     * {<OpenLayers.LonLat>} New OpenLayers.LonLat object with the same lon      *                       and lat values     */    clone:function() {        return new OpenLayers.LonLat(this.lon, this.lat);    },    /**      * APIMethod: add     *      * Parameters:     * lon - {Float}     * lat - {Float}     *      * Returns:     * {<OpenLayers.LonLat>} A new OpenLayers.LonLat object with the lon and      *                       lat passed-in added to this's.      */    add:function(lon, lat) {        if ( (lon == null) || (lat == null) ) {            var msg = "You must pass both lon and lat values " +                      "to the add function.";            OpenLayers.Console.error(msg);            return null;        }        return new OpenLayers.LonLat(this.lon + lon, this.lat + lat);    },    /**      * APIMethod: equals     *      * Parameters:     * ll - {<OpenLayers.LonLat>}     *      * Returns:     * {Boolean} Boolean value indicating whether the passed-in      *           <OpenLayers.LonLat> object has the same lon and lat      *           components as this.     *           Note: if ll passed in is null, returns false     */    equals:function(ll) {        var equals = false;        if (ll != null) {            equals = ((this.lon == ll.lon && this.lat == ll.lat) ||                      (isNaN(this.lon) && isNaN(this.lat) && isNaN(ll.lon) && isNaN(ll.lat)));        }        return equals;    },        /**     * APIMethod: wrapDateLine     *      * Parameters:     * maxExtent - {<OpenLayers.Bounds>}     *      * Returns:     * {<OpenLayers.LonLat>} A copy of this lonlat, but wrapped around the      *                       "dateline" (as specified by the borders of      *                       maxExtent)     */    wrapDateLine: function(maxExtent) {            var newLonLat = this.clone();            if (maxExtent) {            //shift right?            while (newLonLat.lon < maxExtent.left) {                newLonLat.lon +=  maxExtent.getWidth();            }                           //shift left?            while (newLonLat.lon > maxExtent.right) {                newLonLat.lon -= maxExtent.getWidth();            }            }                        return newLonLat;    },    CLASS_NAME: "OpenLayers.LonLat"});/**  * Function: fromString * Alternative constructor that builds a new <OpenLayers.LonLat> from a  *     parameter string *  * Parameters: * str - {String} Comma-separated Lon,Lat coordinate string.  *                 (ex. <i>"5,40"</i>) *  * Returns: * {<OpenLayers.LonLat>} New <OpenLayers.LonLat> object built from the  *                       passed-in String. */OpenLayers.LonLat.fromString = function(str) {    var pair = str.split(",");    return new OpenLayers.LonLat(parseFloat(pair[0]),                                  parseFloat(pair[1]));};

⌨️ 快捷键说明

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