LastPoem / Notes

This is a note library
1 stars 0 forks source link

ArcGIS API for JavaScript在npm环境下的使用 #25

Open LastPoem opened 5 years ago

LastPoem commented 5 years ago

配置本地API

首先要把API放到本地服务器上。需要注意的是要给服务器设置跨域请求。

把init.js和dojo.js 里的路径也要改成本地服务器下的路径。

最后可以直接在项目中引入API。

LastPoem commented 5 years ago

在项目中引入:

在npm环境下需要使用esri-loader进行加载。如下实例:

import esriLoader from 'esri-loader'

export default {
  name: 'map_',

  components: {},

  props: {},

  data() {
    return {}
  },

  created() {},

  mounted() {
    this.createMap()
  },

  computed: {},

  methods: {
    createMap() {
      const options = {
        url: 'http://localhost/arcgis_js_api/library/4.12/dojo/dojo.js'
      }

      esriLoader
        .loadModules(
          [
            'esri/Map',
            'esri/views/MapView',
            'esri/views/SceneView',
            'esri/layers/Layer',
            'dojo/domReady!'
          ],
          options
        )
        .then(
          ([Map, MapView, SceneView, Layer]) => {
            const map = new Map({
              basemap: 'dark-gray-vector'
            })
            const mapview = new MapView({
              map: map,
              container: 'viewDiv',
              zoom: 8,
              center: [102.7346125, 25.0563901]
            })
          },
          reason => {
            console.log(reason)
          }
        )
    }
  }
}