Arcgis for js加載百度地圖


看轉:https://blog.csdn.net/qq_41046162/article/details/80248281

通過學習了一段時間的arcgis for js,讓我來講一下如何在arcgis for js加載百度地圖。

 

加載的結果顯示:

 

 

 

 

 

                                                                           地圖

 

 

 

                                                                  影像 - 無標注

 

 

 

                                                                           影像 - 有標注

 

制作步驟:

 

首先,我是在學習了https://blog.csdn.net/gisshixisheng/article/details/44853709這篇文章,代碼大多都是那里的,參數也都沒錯,但是復制過去還是打不開,這個之后我會講的。

 

其次,就是_百度地圖在柯林斯調用的有地圖在切片,影像切片,以及道路等POI切片,我將之用TiledMapServiceLayer做了擴展,成了BDAnoLayer,BDVecLayer,BDimgLayer三個圖層,其代碼如下:(通俗的意思就是在html同目錄的新建一個文件夾,然后建立三個JavaScript文件分別是BDAnoLayer,BDVecLayer,BDImgLayer)

 

BDAnoLayer.js

 

define(["dojo/_base/declare",

        "esri/layers/TiledMapServiceLayer",

        "esri/geometry/Extent",

        "esri/SpatialReference",

        "esri/layers/TileInfo"

    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {

        return declare(TiledMapServiceLayer, {

            constructor: function () {

                this.spatialReference = new SpatialReference({ wkid: 102100 });

                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));

                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,

                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,

                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];

                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,

                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,

                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];

                this.tileInfo = new TileInfo({

                    "rows": 256,

                    "cols": 256,

                    "compressionQuality": 90,

                    "origin": {

                        "x": -20037508.3427892,

                        "y": 20037508.3427892

                    },

                    "spatialReference": this.spatialReference,

                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },

                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },

                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },

                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },

                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },

                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },

                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },

                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },

                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },

                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },

                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },

                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },

                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },

                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },

                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },

                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },

                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },

                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },

                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },

                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }

                    ]

                });

                this.loaded = true;

                this.onLoad(this);

            },

            getTileUrl: function (level, row, col) {

                var zoom = level - 1;

                var offsetX = parseInt(Math.pow(2, zoom));

                var offsetY = offsetX - 1;

                var numX = col - offsetX, numY = (-row) + offsetY ;

                var num = (col + row) % 8 + 1;

                return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=sl&udt=20180505";

            }

        });

});

BDVecLayer.js

 

define(["dojo/_base/declare",

        "esri/layers/TiledMapServiceLayer",

        "esri/geometry/Extent",

        "esri/SpatialReference",

        "esri/layers/TileInfo"

    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {

        return declare(TiledMapServiceLayer, {

            constructor: function () {

                this.spatialReference = new SpatialReference({ wkid: 102100 });

                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));

                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,

                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,

                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];

                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,

                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,

                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];

                this.tileInfo = new TileInfo({

                    "rows": 256,

                    "cols": 256,

                    "compressionQuality": 90,

                    "origin": {

                        "x": -20037508.3427892,

                        "y": 20037508.3427892

                    },

                    "spatialReference": this.spatialReference,

                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },

                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },

                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },

                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },

                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },

                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },

                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },

                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },

                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },

                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },

                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },

                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },

                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },

                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },

                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },

                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },

                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },

                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },

                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },

                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }

                    ]

                });

                this.loaded = true;

                this.onLoad(this);

            },

            getTileUrl: function (level, row, col) {

                var zoom = level - 1;

                var offsetX = parseInt(Math.pow(2, zoom));

                var offsetY = offsetX - 1;

                var numX = col - offsetX, numY = (-row) + offsetY ;

                var num = (col + row) % 8 + 1;

                return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=pl&scaler=1&udt=20180505";

            }

        });

});

BDImgLayer.js

 

define(["dojo/_base/declare",

        "esri/layers/TiledMapServiceLayer",

        "esri/geometry/Extent",

        "esri/SpatialReference",

        "esri/layers/TileInfo"

    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {

        return declare(TiledMapServiceLayer, {

            constructor: function () {

                this.spatialReference = new SpatialReference({ wkid: 102100 });

                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));

                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,

                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,

                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];

                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,

                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,

                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];

                this.tileInfo = new TileInfo({

                    "rows": 256,

                    "cols": 256,

                    "compressionQuality": 90,

                    "origin": {

                        "x": -20037508.3427892,

                        "y": 20037508.3427892

                    },

                    "spatialReference": this.spatialReference,

                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },

                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },

                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },

                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },

                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },

                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },

                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },

                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },

                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },

                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },

                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },

                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },

                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },

                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },

                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },

                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },

                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },

                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },

                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },

                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }

                    ]

                });

                this.loaded = true;

                this.onLoad(this);

            },

            getTileUrl: function (level, row, col) {

                var zoom = level - 1;

                var offsetX = parseInt(Math.pow(2, zoom));

                var offsetY = offsetX - 1;

                var numX = col - offsetX, numY = (-row) + offsetY ;

                var num = (col + row) % 8 + 1;

                return "http://shangetu" + num + ".map.bdimg.com/it/u=x="+numX+";y="+numY+";z="+level+";v=009;type=sate&fm=46&udt=20180505";

            }

        });

});

從上面的getTileUrl 可以看到,三者返回的URL的地址是沒有有區別的,在上述的URL有可能失效,為了得到最新的地址,學習了那篇文章,我做了如下工作:

 

1,先用百度地圖JS API調用並顯示百度地圖,代碼如下:

 

<!DOCTYPE html>  

<html>  

<head>  

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  

    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />  

    <style type="text/css">  

        body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微軟雅黑";}  

    </style>  

    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=NkuwFBPlXG1uqPDsB9nK2nqpyLFF0SFV"></script>  

    <title>地圖展示</title>  

</head>  

<body>  

<div id="allmap"></div>  

</body>  

</html>  

<script type="text/javascript">

    // 百度地圖API功能  

    var map = new BMap.Map("allmap");    // 創建Map實例  

    map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);  // 初始化地圖,設置中心點坐標和地圖級別  

    map.addControl(new BMap.MapTypeControl());   //添加地圖類型控件  

    map.setCurrentCity("北京");          // 設置地圖顯示的城市 此項是必須設置的  

    map.enableScrollWheelZoom(true);     //開啟鼠標滾輪縮放  

</script>  

你的密鑰需要更改為百度API的密鑰,有需要的要申請。

 

2,然后用chrome打開這個html,F12調試--NetWork--左邊找一張切片,右邊切換至預覽面板

 

 

 

                                                                BDVecLayer.js(地圖網址)

 

 

 

                                                                                BDImgLayer.js(影像鏈接)

 

 

 

                                                                                   BDAnoLayer.js(poi網址)

 

只需要將最后面的數字替換掉就行了,20180505。

 

3.將上面的三個JS調用到地圖主頁。

 

代碼如下:

 

<!DOCTYPE html>

<html>

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">

    <title>Baidu Map</title>

    <link rel="stylesheet" href="https://js.arcgis.com/3.23/dijit/themes/tundra/tundra.css"/>

    <link rel="stylesheet" href="https://js.arcgis.com/3.23/esri/css/esri.css">

    <style>

        html, body, #map {

            height: 100%;

            margin: 0;

            padding: 0;

        }

        .base-map-ano{

            position: absolute;

            right: 0pt;

            top:18pt;

            background: #e6edf1;

            border: #96aed1 1px solid;

            padding: 4px 5px;

            padding-left: 0px;

            padding-top: 0px;

            display: none;

            font-weight: normal;

        }

        .base-map{

            position: absolute;

            right: 15pt;

            top:15pt;

            background: #f0f0f0;

            border: #96aed1 1px solid;

            width: auto;

            height: auto;

            z-index: 99;

            font:normal 11px "宋體",Arial;

            color:#868686;

        }

        .base-map-switch{

            padding: 4px 8px;

            float: left;

        }

        .base-map-switch-active{

            background:#e6edf1;

            font-weight: bold;

            color: #4d4d4d;

        }

        .base-map-switch:hover{

            cursor: pointer;

        }

        .base-map-switch-center{

            border: 1px #96aed1 solid;

            border-top:none;

            border-bottom:none;

        }

    </style>

    <script type="text/javascript">

        dojoConfig = {

            parseOnLoad: true,

            packages: [{

                name: 'bdlib',

                location: this.location.pathname.replace(/\/[^/]+$/, "")+"/js"

            }]

        };

    </script>

<script src="https://js.arcgis.com/3.23/"></script>

    <script src="js/jquery-1.8.3.js"></script>

    <script>

        var map,showMap,anoCtrl;

        require(["esri/map",

                "bdlib/BDVecLayer",

                "bdlib/BDImgLayer",

                "bdlib/BDAnoLayer",

                "esri/layers/FeatureLayer",

                "esri/geometry/Point",

                "esri/SpatialReference",

                "dojo/domReady!"],

            function (Map,

                      BDVecLayer,

                      BDImgLayer,

                      BDAnoLayer,

                      FeatureLayer,

                      Point,

                      SpatialReference

            ){

                map = new Map("map", {

                    logo: false

                });

                var vecMap = new BDVecLayer();

                var imgMap = new BDImgLayer();

                var anoMap = new BDAnoLayer();

                map.addLayer(vecMap);

                map.addLayers([imgMap,anoMap]);

                imgMap.hide();

                anoMap.hide();

 

                var pt = new Point(7038512.810510807, 2629489.7975553474, new SpatialReference({ wkid: 102100 }));

                map.centerAndZoom(pt, 5);

 

                showMap = function(layer){

                    //設置按鈕樣式

                    var baseMap = ["vec","img"];

                    for(var i= 0, dl=baseMap.length;i<dl;i++){

                        $("#"+baseMap[i]).removeClass("base-map-switch-active");

                    }

                    $("#"+layer).addClass("base-map-switch-active");

                    //設置顯示地圖

                    switch(layer){

                        case "img":{//影像

                            vecMap.hide();

                            imgMap.show();

                            $("#ano").show();

                            break;

                        }

                        default :{//地圖

                            vecMap.show();

                            imgMap.hide();

                            anoMap.hide();

                            $("#ano").hide();

                            $("#chkAno").attr("checked",false);

                            break;

                        }

                    }

                };

                anoCtrl = function(){

                    if($("#chkAno").prop("checked")){

                        anoMap.show();

                    }

                    else{

                        anoMap.hide();

                    }

                }

            });

    </script>

</head>

<body>

<div id="map">

    <div class="base-map">

        <div id="vec" class="base-map-switch base-map-switch-active" onclick="showMap('vec')">地圖</div>

        <div id="img" class="base-map-switch base-map-switch-center"  onclick="showMap('img')">影像

            <div id="ano" class="base-map-ano">

                <input id="chkAno" type="checkbox" name="chkAno" value="chkAno" onchange="anoCtrl()"/>標注

            </div>

        </div>

    </div>

</div>

</body>

</html>

 

其中的jQuery-1.8.3.js的代碼可以自己百度下,然后放到JS文件夾下面。

全部代碼下載鏈接:下載鏈接

最后建議先用火狐瀏覽器打開這個baidumap,顯示偏移的話可能是代碼錯了.google瀏覽器要改一下,需要配置google chrome支持本地(file協議)的AJAX請求:

設置瀏覽器的快捷方式屬性,在“目標”后面加上--allow-文件訪問從 - 文件,注意前面有個空格,重新打開瀏覽器即可。

如果還是不顯示的話請用火狐瀏覽器。

--------------------- 

作者:新生GIS 

來源:CSDN 

原文:https://blog.csdn.net/qq_41046162/article/details/80248281 

版權聲明:本文為博主原創文章,轉載請附上博文鏈接!

通過學習了一段時間的arcgis for js,讓我來講一下如何在arcgis for js加載百度地圖。
加載的結果顯示:




                                                                           地圖


                                                                  影像 - 無標注


                                                                           影像 - 有標注
制作步驟:
首先,我是在學習了https://blog.csdn.net/gisshixisheng/article/details/44853709這篇文章,代碼大多都是那里的,參數也都沒錯,但是復制過去還是打不開,這個之后我會講的。
其次,就是_百度地圖在柯林斯調用的有地圖在切片,影像切片,以及道路等POI切片,我將之用TiledMapServiceLayer做了擴展,成了BDAnoLayer,BDVecLayer,BDimgLayer三個圖層,其代碼如下:(通俗的意思就是在html同目錄的新建一個文件夾,然后建立三個JavaScript文件分別是BDAnoLayer,BDVecLayer,BDImgLayer)
BDAnoLayer.js
define(["dojo/_base/declare",        "esri/layers/TiledMapServiceLayer",        "esri/geometry/Extent",        "esri/SpatialReference",        "esri/layers/TileInfo"    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {        return declare(TiledMapServiceLayer, {            constructor: function () {                this.spatialReference = new SpatialReference({ wkid: 102100 });                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];                this.tileInfo = new TileInfo({                    "rows": 256,                    "cols": 256,                    "compressionQuality": 90,                    "origin": {                        "x": -20037508.3427892,                        "y": 20037508.3427892                    },                    "spatialReference": this.spatialReference,                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }                    ]                });                this.loaded = true;                this.onLoad(this);            },            getTileUrl: function (level, row, col) {                var zoom = level - 1;                var offsetX = parseInt(Math.pow(2, zoom));                var offsetY = offsetX - 1;                var numX = col - offsetX, numY = (-row) + offsetY ;                var num = (col + row) % 8 + 1;                return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=sl&udt=20180505";            }        });});BDVecLayer.js
define(["dojo/_base/declare",        "esri/layers/TiledMapServiceLayer",        "esri/geometry/Extent",        "esri/SpatialReference",        "esri/layers/TileInfo"    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {        return declare(TiledMapServiceLayer, {            constructor: function () {                this.spatialReference = new SpatialReference({ wkid: 102100 });                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];                this.tileInfo = new TileInfo({                    "rows": 256,                    "cols": 256,                    "compressionQuality": 90,                    "origin": {                        "x": -20037508.3427892,                        "y": 20037508.3427892                    },                    "spatialReference": this.spatialReference,                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }                    ]                });                this.loaded = true;                this.onLoad(this);            },            getTileUrl: function (level, row, col) {                var zoom = level - 1;                var offsetX = parseInt(Math.pow(2, zoom));                var offsetY = offsetX - 1;                var numX = col - offsetX, numY = (-row) + offsetY ;                var num = (col + row) % 8 + 1;                return "http://online" + num + ".map.bdimg.com/tile/?qt=tile&x="+numX+"&y="+numY+"&z="+level+"&styles=pl&scaler=1&udt=20180505";            }        });});BDImgLayer.js
define(["dojo/_base/declare",        "esri/layers/TiledMapServiceLayer",        "esri/geometry/Extent",        "esri/SpatialReference",        "esri/layers/TileInfo"    ], function (declare, TiledMapServiceLayer, Extent, SpatialReference, TileInfo) {        return declare(TiledMapServiceLayer, {            constructor: function () {                this.spatialReference = new SpatialReference({ wkid: 102100 });                this.initialExtent = (this.fullExtent = new Extent(-20037508.3427892, -20037508.3427892, 20037508.3427892, 20037508.3427892, this.spatialReference));                this.scale = [591657527.591555,295828763.795777,147914381.897889,73957190.948944,36978595.474472,18489297.737236,9244648.868618,                    4622324.434309,2311162.217155,1155581.108577,577790.554289,288895.277144,144447.638572,72223.819286,                    36111.9096437,18055.9548224,9027.977411,4513.988705,2256.994353,1128.497176];                this.resolution = [156543.033928,78271.5169639999,39135.7584820001,19567.8792409999,9783.93962049996,4891.96981024998,2445.98490512499,                    1222.99245256249,611.49622628138,305.748113140558,152.874056570411,76.4370282850732,38.2185141425366,19.1092570712683,9.55462853563415,                    4.77731426794937,2.38865713397468,1.19432856685505,0.597164283559817,0.298582141647617];                this.tileInfo = new TileInfo({                    "rows": 256,                    "cols": 256,                    "compressionQuality": 90,                    "origin": {                        "x": -20037508.3427892,                        "y": 20037508.3427892                    },                    "spatialReference": this.spatialReference,                    "lods": [{ "level": 0, "resolution": this.resolution[0], "scale": this.scale[0] },                        { "level": 1, "resolution": this.resolution[1], "scale": this.scale[1] },                        { "level": 2, "resolution": this.resolution[2], "scale": this.scale[2] },                        { "level": 3, "resolution": this.resolution[3], "scale": this.scale[3] },                        { "level": 4, "resolution": this.resolution[4], "scale": this.scale[4] },                        { "level": 5, "resolution": this.resolution[5], "scale": this.scale[5] },                        { "level": 6, "resolution": this.resolution[6], "scale": this.scale[6] },                        { "level": 7, "resolution": this.resolution[7], "scale": this.scale[7] },                        { "level": 8, "resolution": this.resolution[8], "scale": this.scale[8] },                        { "level": 9, "resolution": this.resolution[9], "scale": this.scale[9] },                        { "level": 10, "resolution": this.resolution[10], "scale": this.scale[10] },                        { "level": 11, "resolution": this.resolution[11], "scale": this.scale[11] },                        { "level": 12, "resolution": this.resolution[12], "scale": this.scale[12] },                        { "level": 13, "resolution": this.resolution[13], "scale": this.scale[13] },                        { "level": 14, "resolution": this.resolution[14], "scale": this.scale[14] },                        { "level": 15, "resolution": this.resolution[15], "scale": this.scale[15] },                        { "level": 16, "resolution": this.resolution[16], "scale": this.scale[16] },                        { "level": 17, "resolution": this.resolution[17], "scale": this.scale[17] },                        { "level": 18, "resolution": this.resolution[18], "scale": this.scale[18] },                        { "level": 19, "resolution": this.resolution[19], "scale": this.scale[19] }                    ]                });                this.loaded = true;                this.onLoad(this);            },            getTileUrl: function (level, row, col) {                var zoom = level - 1;                var offsetX = parseInt(Math.pow(2, zoom));                var offsetY = offsetX - 1;                var numX = col - offsetX, numY = (-row) + offsetY ;                var num = (col + row) % 8 + 1;                return "http://shangetu" + num + ".map.bdimg.com/it/u=x="+numX+";y="+numY+";z="+level+";v=009;type=sate&fm=46&udt=20180505";            }        });});從上面的getTileUrl 可以看到,三者返回的URL的地址是沒有有區別的,在上述的URL有可能失效,為了得到最新的地址,學習了那篇文章,我做了如下工作:
1,先用百度地圖JS API調用並顯示百度地圖,代碼如下:
<!DOCTYPE html>  <html>  <head>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />      <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />      <style type="text/css">          body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微軟雅黑";}      </style>      <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=NkuwFBPlXG1uqPDsB9nK2nqpyLFF0SFV"></script>      <title>地圖展示</title>  </head>  <body>  <div id="allmap"></div>  </body>  </html>  <script type="text/javascript">    // 百度地圖API功能      var map = new BMap.Map("allmap");    // 創建Map實例      map.centerAndZoom(new BMap.Point(116.404, 39.915), 5);  // 初始化地圖,設置中心點坐標和地圖級別      map.addControl(new BMap.MapTypeControl());   //添加地圖類型控件      map.setCurrentCity("北京");          // 設置地圖顯示的城市 此項是必須設置的      map.enableScrollWheelZoom(true);     //開啟鼠標滾輪縮放  </script>  你的密鑰需要更改為百度API的密鑰,有需要的要申請。
2,然后用chrome打開這個html,F12調試--NetWork--左邊找一張切片,右邊切換至預覽面板


                                                                BDVecLayer.js(地圖網址)


                                                                                BDImgLayer.js(影像鏈接)


                                                                                   BDAnoLayer.js(poi網址)
只需要將最后面的數字替換掉就行了,20180505。
3.將上面的三個JS調用到地圖主頁。
代碼如下:
<!DOCTYPE html><html><head>    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">    <title>Baidu Map</title>    <link rel="stylesheet" href="https://js.arcgis.com/3.23/dijit/themes/tundra/tundra.css"/>    <link rel="stylesheet" href="https://js.arcgis.com/3.23/esri/css/esri.css">    <style>        html, body, #map {            height: 100%;            margin: 0;            padding: 0;        }        .base-map-ano{            position: absolute;            right: 0pt;            top:18pt;            background: #e6edf1;            border: #96aed1 1px solid;            padding: 4px 5px;            padding-left: 0px;            padding-top: 0px;            display: none;            font-weight: normal;        }        .base-map{            position: absolute;            right: 15pt;            top:15pt;            background: #f0f0f0;            border: #96aed1 1px solid;            width: auto;            height: auto;            z-index: 99;            font:normal 11px "宋體",Arial;            color:#868686;        }        .base-map-switch{            padding: 4px 8px;            float: left;        }        .base-map-switch-active{            background:#e6edf1;            font-weight: bold;            color: #4d4d4d;        }        .base-map-switch:hover{            cursor: pointer;        }        .base-map-switch-center{            border: 1px #96aed1 solid;            border-top:none;            border-bottom:none;        }    </style>    <script type="text/javascript">        dojoConfig = {            parseOnLoad: true,            packages: [{                name: 'bdlib',                location: this.location.pathname.replace(/\/[^/]+$/, "")+"/js"            }]        };    </script><script src="https://js.arcgis.com/3.23/"></script>    <script src="js/jquery-1.8.3.js"></script>    <script>        var map,showMap,anoCtrl;        require(["esri/map",                "bdlib/BDVecLayer",                "bdlib/BDImgLayer",                "bdlib/BDAnoLayer",                "esri/layers/FeatureLayer",                "esri/geometry/Point",                "esri/SpatialReference",                "dojo/domReady!"],            function (Map,                      BDVecLayer,                      BDImgLayer,                      BDAnoLayer,                      FeatureLayer,                      Point,                      SpatialReference            ){                map = new Map("map", {                    logo: false                });                var vecMap = new BDVecLayer();                var imgMap = new BDImgLayer();                var anoMap = new BDAnoLayer();                map.addLayer(vecMap);                map.addLayers([imgMap,anoMap]);                imgMap.hide();                anoMap.hide();                 var pt = new Point(7038512.810510807, 2629489.7975553474, new SpatialReference({ wkid: 102100 }));                map.centerAndZoom(pt, 5);                 showMap = function(layer){                    //設置按鈕樣式                    var baseMap = ["vec","img"];                    for(var i= 0, dl=baseMap.length;i<dl;i++){                        $("#"+baseMap[i]).removeClass("base-map-switch-active");                    }                    $("#"+layer).addClass("base-map-switch-active");                    //設置顯示地圖                    switch(layer){                        case "img":{//影像                            vecMap.hide();                            imgMap.show();                            $("#ano").show();                            break;                        }                        default :{//地圖                            vecMap.show();                            imgMap.hide();                            anoMap.hide();                            $("#ano").hide();                            $("#chkAno").attr("checked",false);                            break;                        }                    }                };                anoCtrl = function(){                    if($("#chkAno").prop("checked")){                        anoMap.show();                    }                    else{                        anoMap.hide();                    }                }            });    </script></head><body><div id="map">    <div class="base-map">        <div id="vec" class="base-map-switch base-map-switch-active" onclick="showMap('vec')">地圖</div>        <div id="img" class="base-map-switch base-map-switch-center"  onclick="showMap('img')">影像            <div id="ano" class="base-map-ano">                <input id="chkAno" type="checkbox" name="chkAno" value="chkAno" onchange="anoCtrl()"/>標注            </div>        </div>    </div></div></body></html>
其中的jQuery-1.8.3.js的代碼可以自己百度下,然后放到JS文件夾下面。全部代碼下載鏈接:下載鏈接最后建議先用火狐瀏覽器打開這個baidumap,顯示偏移的話可能是代碼錯了.google瀏覽器要改一下,需要配置google chrome支持本地(file協議)的AJAX請求:設置瀏覽器的快捷方式屬性,在“目標”后面加上--allow-文件訪問從 - 文件,注意前面有個空格,重新打開瀏覽器即可。如果還是不顯示的話請用火狐瀏覽器。--------------------- 作者:新生GIS 來源:CSDN 原文:https://blog.csdn.net/qq_41046162/article/details/80248281 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM