ArcGIS API for JavaScript 4.6 版本載入高德地

來源:互聯網
上載者:User

標籤:地理資訊

ArcGIS API for JavaScript 4.X 版本升級後,API發生了很大的變化。

其中就支援了WebEarth展示,主要是通過 esri/views/SceneView 實現的。

在新版本中,預設都是載入Esri自己的地圖。

若想載入其他地圖,可以通過擴充BaseTileLayer實現。

例如,最新版本載入高德地圖的demo如下:

[html] view plain copy
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Custom TileLayer - 4.6</title>

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

<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>

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

<script>
require([
"esri/Map",
"esri/config",
"esri/request",
"esri/Color",
"esri/views/SceneView",
"esri/widgets/LayerList",
"esri/layers/BaseTileLayer",

  "dojo/domReady!"  ], function(    Map, esriConfig, esriRequest, Color,    SceneView, LayerList, BaseTileLayer  ) {    // *******************************************************    // Custom tile layer class code    // Create a subclass of BaseTileLayer    // *******************************************************    var TintLayer = BaseTileLayer.createSubclass({      properties: {        urlTemplate: null,        tint: {          value: null,          type: Color        }      },      // generate the tile url for a given level, row and column      getTileUrl: function(level, row, col) {        return this.urlTemplate.replace("{z}", level).replace("{x}",          col).replace("{y}", row);      },      // This method fetches tiles for the specified level and size.      // Override this method to process the data returned from the server.      fetchTile: function(level, row, col) {        // call getTileUrl() method to construct the URL to tiles        // for a given level, row and col provided by the LayerView        var url = this.getTileUrl(level, row, col);        // request for tiles based on the generated url        // set allowImageDataAccess to true to allow        // cross-domain access to create WebGL textures for 3D.        return esriRequest(url, {            responseType: "image",            allowImageDataAccess: true          })          .then(function(response) {            // when esri request resolves successfully            // get the image from the response            var image = response.data;            var width = this.tileInfo.size[0];            var height = this.tileInfo.size[0];            // create a canvas with 2D rendering context            var canvas = document.createElement("canvas");            var context = canvas.getContext("2d");            canvas.width = width;            canvas.height = height;            // Draw the blended image onto the canvas.            context.drawImage(image, 0, 0, width, height);            return canvas;          }.bind(this));      }    });    // *******************************************************    // Start of JavaScript application    // *******************************************************    // Add stamen url to the list of servers known to support CORS specification.    esriConfig.request.corsEnabledServers.push("webst01.is.autonavi.com");    // Create a new instance of the TintLayer and set its properties    var stamenTileLayer = new TintLayer({      urlTemplate: "http://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}",      tint: new Color("#004FBB"),      title: "高德"    });    // add the new instance of the custom tile layer the map    var map = new Map({      layers: [stamenTileLayer]    });    // create a new scene view and add the map    var view = new SceneView({      container: "viewDiv",      map: map,      center: [0, 30],      zoom: 3    });    // create a layer list widget    var layerList = new LayerList({      view: view,    });    view.ui.add(layerList, "top-right");  });  

</script>
</head>

<body>
<div id="viewDiv"></div>
</body>

</html>


[地圖大資料雲平台 www.favxu.com

三維地球雲平台 3d.favxu.com

地圖雲平台交流合作 QQ:63747667

郵箱:[email protected]

ArcGIS API for JavaScript 4.6 版本載入高德地

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.