1.获取API

1.1云端托管(CDN)

1.2本地托管(Local)

配置教程:http://zhihu.geoscene.cn/article/3514
image.png

1.3Web Optimizer(Custom Build)

2.引用库

  1. <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/css/main.css">
  2. <script src="https://js.arcgis.com/4.18/"></script>

3.加载模块

  1. <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/css/main.css">
  2. <script type="module">
  3. import Map from "https://js.arcgis.com/4.18/@arcgis/core/Map.js";
  4. // Use the Map class
  5. </script>

4.写代码

  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
  5. <title>ArcGIS API for JavaScript Tutorials: Display a map</title>
  6. <style>
  7. html,
  8. body,
  9. #viewDiv {
  10. padding: 0;
  11. margin: 0;
  12. height: 100%;
  13. width: 100%;
  14. }
  15. </style>
  16. <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
  17. <script src="https://js.arcgis.com/4.18/"></script>
  18. <script>
  19. require(["esri/config","esri/Map", "esri/views/MapView"], function (esriConfig,Map, MapView) {
  20. esriConfig.apiKey = "YOUR-API-KEY";
  21. const map = new Map({
  22. basemap: "arcgis-topographic" // Basemap layer service
  23. });
  24. const view = new MapView({
  25. map: map,
  26. center: [-118.805, 34.027], // Longitude, latitude
  27. zoom: 13, // Zoom level
  28. container: "viewDiv" // Div element
  29. });
  30. });
  31. </script>
  32. </head>
  33. <body>
  34. <div id="viewDiv"></div>
  35. </body>
  36. </html>