DJIsean
2022-08-17 c5f51306bfc8e57e4837d071e38e25fa6aa87f76
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
import AMapLoader from '@amap/amap-jsapi-loader'
import { App, reactive } from 'vue'
import { AMapConfig } from '/@/constants/index'
 
export function useGMapManage () {
  const state = reactive({
    mapEntity: null,
    mapObj: null,
    mouseTool: null,
  })
  async function initMap (container: string, app:App) {
    AMapLoader.load({
      ...AMapConfig
    }).then((AMap) => {
      state.mapObj = AMap
      state.mapEntity = new AMap.Map(container, {
        center: [113.935913, 22.525335],
        zoom: 15
      })
      state.mouseTool = new AMap.MouseTool(state.mapEntity)
      app.config.globalProperties.$aMap = state.mapEntity
      app.config.globalProperties.$aMapObj = state.mapObj
      app.config.globalProperties.$mouseTool = state.mouseTool
    }).catch(e => {
      console.log(e)
    })
  }
  function globalPropertiesConfig (app:App) {
    initMap('g-container', app)
  }
  return {
    globalPropertiesConfig,
  }
}