效果如图:
一、引入arcgis
<link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css" />
<script src="https://js.arcgis.com/4.26/"></script>
2.加载模块
使用第二个标记从 API 加载特定模块。使用以下代码片段中的语法加载以下模块:
esri/Map- 加载特定于创建地图的代码
esri/views/MapView- 加载允许以 2D 方式查看地图的代码
<script>
require([ "esri/Map", "esri/views/MapView" ], (Map, MapView) => {
// Code to create the map and view will go here
});
</script>
将 JavaScript 放在脚本标记中在构建简单页面或进行实验时很有用,但不适合大型应用程序。在构建更大的应用程序时,所有 JavaScript 都应该放在单独的.js文件中。
全局require()函数用于加载 API 的AMD模块
3.创建地图
使用 创建一个新地图Map,它是对从模块加载的 Map 类的引用esri/Map。basemap
您可以通过将对象传递给 Map 构造函数来指定地图属性,例如。
require(["esri/Map", "esri/views/MapView"], (Map, MapView