arcgis的基本使用

参考:https://developers.arcgis.com/javascript/latest/guide/quick-start/

1、在html中使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.17/esri/themes/light/main.css">
<script src="https://js.arcgis.com/4.17/"></script>
<style>
html,body,#map{
height: 100%;
width: 100%;
box-sizing: border-box;
overflow: hidden;
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
require([
"esri/Map",
"esri/views/MapView"
], function(Map, MapView) {
var map = new Map({
basemap: "topo-vector"
})
var view = new MapView({
container: "map",
map: map,
center: [-118.71511,34.09042],
zoom: 11
})
})
</script>
</body>
</html>

2、在vue项目中使用

安装arcgis官方依赖esri-loader,这个只是开发依赖,因此使用命令npm i esri-loader --save-dev来安装.
用模块的方式引入 esri-loader:

1
import esriLoader from 'esri-loader'

esriLoader有以下几个方法:

  1. getScript () 从库里面获取 js 文件 ;
  2. isLoaded () 检测模块是否加载完成 ;
  3. loadModules( [ ], options) 用于加载arcgis 模块;
  4. loadCss( url ) 用于加载css文件;
  5. loadScript({url: “xxxxxxxx” }) 将js 加载到页面上;
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    <template>
    <div id="map"></div>
    </template>
    <script>
    import esriLoader from 'esri-loader'
    export default {
    mounted () {
    const options = {
    url: 'https://js.arcgis.com/4.17/init.js',
    css: 'https://js.arcgis.com/4.17/esri/themes/light/main.css'
    }
    esriLoader.loadModules([
    'esri/Map',
    'esri/views/MapView'
    ], options)
    .then(([ArcGISMap, MapView]) => {
    this.map1 = new ArcGISMap({
    basemap: 'streets-relief-vector'
    })
    this.view1 = new MapView({
    container: 'map1',
    map: this.map1,
    center: [-118.71511,34.09042],
    zoom: 4
    })
    })
    }
    }
    </script>
    具体部署:arcgis for js本地部署/不部署/在线arcgis的几种情况使用