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

📄 map.js

📁 用来在地图上做操作GIS,在地图上做标记
💻 JS
📖 第 1 页 / 共 4 页
字号:
     */    getMaxExtent: function () {        var maxExtent = null;        if (this.baseLayer != null) {            maxExtent = this.baseLayer.maxExtent;        }                return maxExtent;    },        /**     * APIMethod: getNumZoomLevels     *      * Returns:     * {Integer} The total number of zoom levels that can be displayed by the      *           current baseLayer.     */    getNumZoomLevels: function() {        var numZoomLevels = null;        if (this.baseLayer != null) {            numZoomLevels = this.baseLayer.numZoomLevels;        }        return numZoomLevels;    },  /********************************************************/  /*                                                      */  /*                 Baselayer Functions                  */  /*                                                      */  /*    The following functions, all publicly exposed     */  /*       in the API?, are all merely wrappers to the    */  /*       the same calls on whatever layer is set as     */  /*                the current base layer                */  /*                                                      */  /********************************************************/    /**     * APIMethod: getExtent     *      * Returns:     * {<OpenLayers.Bounds>} A Bounds object which represents the lon/lat      *                       bounds of the current viewPort.      *                       If no baselayer is set, returns null.     */    getExtent: function () {        var extent = null;        if (this.baseLayer != null) {            extent = this.baseLayer.getExtent();        }        return extent;    },    /**     * APIMethod: getResolution     *      * Returns:     * {Float} The current resolution of the map.      *         If no baselayer is set, returns null.     */    getResolution: function () {        var resolution = null;        if (this.baseLayer != null) {            resolution = this.baseLayer.getResolution();        }        return resolution;    },     /**      * APIMethod: getScale      *       * Returns:      * {Float} The current scale denominator of the map.       *         If no baselayer is set, returns null.      */    getScale: function () {        var scale = null;        if (this.baseLayer != null) {            var res = this.getResolution();            var units = this.baseLayer.units;            scale = OpenLayers.Util.getScaleFromResolution(res, units);        }        return scale;    },    /**     * APIMethod: getZoomForExtent     *      * Parameters:      * bounds - {<OpenLayers.Bounds>}     * closest - {Boolean} Find the zoom level that most closely fits the      *     specified bounds. Note that this may result in a zoom that does      *     not exactly contain the entire extent.     *     Default is false.     *      * Returns:     * {Integer} A suitable zoom level for the specified bounds.     *           If no baselayer is set, returns null.     */    getZoomForExtent: function (bounds, closest) {        var zoom = null;        if (this.baseLayer != null) {            zoom = this.baseLayer.getZoomForExtent(bounds, closest);        }        return zoom;    },    /**     * APIMethod: getZoomForResolution     *      * Parameter:     * resolution - {Float}     * closest - {Boolean} Find the zoom level that corresponds to the absolute      *     closest resolution, which may result in a zoom whose corresponding     *     resolution is actually smaller than we would have desired (if this     *     is being called from a getZoomForExtent() call, then this means that     *     the returned zoom index might not actually contain the entire      *     extent specified... but it'll be close).     *     Default is false.     *      * Returns:     * {Integer} A suitable zoom level for the specified resolution.     *           If no baselayer is set, returns null.     */    getZoomForResolution: function(resolution, closest) {        var zoom = null;        if (this.baseLayer != null) {            zoom = this.baseLayer.getZoomForResolution(resolution, closest);        }        return zoom;    },  /********************************************************/  /*                                                      */  /*                  Zooming Functions                   */  /*                                                      */  /*    The following functions, all publicly exposed     */  /*       in the API, are all merely wrappers to the     */  /*               the setCenter() function               */  /*                                                      */  /********************************************************/      /**      * APIMethod: zoomTo     * Zoom to a specific zoom level     *      * Parameters:     * zoom - {Integer}     */    zoomTo: function(zoom) {        if (this.isValidZoomLevel(zoom)) {            this.setCenter(null, zoom);        }    },        /**     * APIMethod: zoomIn     *      * Parameters:     * zoom - {int}     */    zoomIn: function() {        this.zoomTo(this.getZoom() + 1);    },        /**     * APIMethod: zoomOut     *      * Parameters:     * zoom - {int}     */    zoomOut: function() {        this.zoomTo(this.getZoom() - 1);    },    /**     * APIMethod: zoomToExtent     * Zoom to the passed in bounds, recenter     *      * Parameters:     * bounds - {<OpenLayers.Bounds>}     */    zoomToExtent: function(bounds) {        var center = bounds.getCenterLonLat();        if (this.baseLayer.wrapDateLine) {            var maxExtent = this.getMaxExtent();            //fix straddling bounds (in the case of a bbox that straddles the             // dateline, it's left and right boundaries will appear backwards.             // we fix this by allowing a right value that is greater than the            // max value at the dateline -- this allows us to pass a valid             // bounds to calculate zoom)            //            bounds = bounds.clone();            while (bounds.right < bounds.left) {                bounds.right += maxExtent.getWidth();            }            //if the bounds was straddling (see above), then the center point             // we got from it was wrong. So we take our new bounds and ask it            // for the center. Because our new bounds is at least partially             // outside the bounds of maxExtent, the new calculated center             // might also be. We don't want to pass a bad center value to             // setCenter, so we have it wrap itself across the date line.            //            center = bounds.getCenterLonLat().wrapDateLine(maxExtent);        }        this.setCenter(center, this.getZoomForExtent(bounds));    },    /**      * APIMethod: zoomToMaxExtent     * Zoom to the full extent and recenter.     */    zoomToMaxExtent: function() {        this.zoomToExtent(this.getMaxExtent());    },    /**      * APIMethod: zoomToScale     * Zoom to a specified scale      *      * Parameters:     * scale - {float}     */    zoomToScale: function(scale) {        var res = OpenLayers.Util.getResolutionFromScale(scale,                                                          this.baseLayer.units);        var size = this.getSize();        var w_deg = size.w * res;        var h_deg = size.h * res;        var center = this.getCenter();        var extent = new OpenLayers.Bounds(center.lon - w_deg / 2,                                           center.lat - h_deg / 2,                                           center.lon + w_deg / 2,                                           center.lat + h_deg / 2);        this.zoomToExtent(extent);    },      /********************************************************/  /*                                                      */  /*             Translation Functions                    */  /*                                                      */  /*      The following functions translate between       */  /*           LonLat, LayerPx, and ViewPortPx            */  /*                                                      */  /********************************************************/        //  // TRANSLATION: LonLat <-> ViewPortPx  //    /**     * APIMethod: getLonLatFromViewPortPx     *      * Parameters:     * viewPortPx - {<OpenLayers.Pixel>}     *      * Returns:     * {<OpenLayers.LonLat>} An OpenLayers.LonLat which is the passed-in view      *                       port <OpenLayers.Pixel>, translated into lon/lat     *                       by the current base layer.     */    getLonLatFromViewPortPx: function (viewPortPx) {        var lonlat = null;         if (this.baseLayer != null) {            lonlat = this.baseLayer.getLonLatFromViewPortPx(viewPortPx);        }        return lonlat;    },    /**     * APIMethod: getViewPortPxFromLonLat     *      * Parameters:     * lonlat - {<OpenLayers.LonLat>}     *      * Returns:     * {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in      *                      <OpenLayers.LonLat>, translated into view port      *                      pixels by the current base layer.     */    getViewPortPxFromLonLat: function (lonlat) {        var px = null;         if (this.baseLayer != null) {            px = this.baseLayer.getViewPortPxFromLonLat(lonlat);        }        return px;    },      //  // CONVENIENCE TRANSLATION FUNCTIONS FOR API  //    /**     * APIMethod: getLonLatFromPixel     *      * Parameters:     * px - {<OpenLayers.Pixel>}     *     * Returns:     * {<OpenLayers.LonLat>} An OpenLayers.LonLat corresponding to the given     *                       OpenLayers.Pixel, translated into lon/lat by the      *                       current base layer     */    getLonLatFromPixel: function (px) {        return this.getLonLatFromViewPortPx(px);    },    /**     * APIMethod: getPixelFromLonLat     *      * Parameters:     * lonlat - {<OpenLayers.LonLat>}     *      * Returns:      * {<OpenLayers.Pixel>} An OpenLayers.Pixel corresponding to the      *                      <OpenLayers.LonLat> translated into view port      *                      pixels by the current base layer.     */    getPixelFromLonLat: function (lonlat) {        return this.getViewPortPxFromLonLat(lonlat);    },  //  // TRANSLATION: ViewPortPx <-> LayerPx  //    /**     * APIMethod: getViewPortPxFromLayerPx     *      * Parameters:     * layerPx - {<OpenLayers.Pixel>}     *      * Returns:     * {<OpenLayers.Pixel>} Layer Pixel translated into ViewPort Pixel      *                      coordinates     */    getViewPortPxFromLayerPx:function(layerPx) {        var viewPortPx = null;        if (layerPx != null) {            var dX = parseInt(this.layerContainerDiv.style.left);            var dY = parseInt(this.layerContainerDiv.style.top);            viewPortPx = layerPx.add(dX, dY);                    }        return viewPortPx;    },        /**     * APIMethod: getLayerPxFromViewPortPx     *      * Parameters:     * viewPortPx - {<OpenLayers.Pixel>}     *      * Returns:     * {<OpenLayers.Pixel>} ViewPort Pixel translated into Layer Pixel      *                      coordinates     */    getLayerPxFromViewPortPx:function(viewPortPx) {        var layerPx = null;        if (viewPortPx != null) {            var dX = -parseInt(this.layerContainerDiv.style.left);            var dY = -parseInt(this.layerContainerDiv.style.top);            layerPx = viewPortPx.add(dX, dY);            if (isNaN(layerPx.x) || isNaN(layerPx.y)) {                layerPx = null;            }        }        return layerPx;    },      //  // TRANSLATION: LonLat <-> LayerPx  //    /**     * APIMethod: getLonLatFromLayerPx     *      * Parameters:     * px - {<OpenLayers.Pixel>}     *     * Returns:     * {<OpenLayers.LonLat>}     */    getLonLatFromLayerPx: function (px) {       //adjust for displacement of layerContainerDiv       px = this.getViewPortPxFromLayerPx(px);       return this.getLonLatFromViewPortPx(px);             },        /**     * APIMethod: getLayerPxFromLonLat     *      * Parameters:     * lonlat - {<OpenLayers.LonLat>} lonlat     *     * Returns:     * {<OpenLayers.Pixel>} An OpenLayers.Pixel which is the passed-in      *                      <OpenLayers.LonLat>, translated into layer pixels      *                      by the current base layer     */    getLayerPxFromLonLat: function (lonlat) {       //adjust for displacement of layerContainerDiv       var px = this.getViewPortPxFromLonLat(lonlat);       return this.getLayerPxFromViewPortPx(px);             },    CLASS_NAME: "OpenLayers.Map"});/** * Constant: TILE_WIDTH * {Integer} 256 Default tile width (unless otherwise specified) */OpenLayers.Map.TILE_WIDTH = 256;/** * Constant: TILE_HEIGHT * {Integer} 256 Default tile height (unless otherwise specified) */OpenLayers.Map.TILE_HEIGHT = 256;

⌨️ 快捷键说明

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