index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="box">
  3. <div id="container" style="width: 100%; height: 100%; position: relative"></div>
  4. </div>
  5. </template>
  6. <script setup lang="ts">
  7. import AMapLoader from '@amap/amap-jsapi-loader'
  8. import { CreateComponentType } from '@/packages/index.d'
  9. import { reactive, ref, shallowRef, PropType, toRefs, watch } from 'vue'
  10. const props = defineProps({
  11. chartConfig: {
  12. type: Object as PropType<CreateComponentType>,
  13. required: true
  14. }
  15. })
  16. let { amapKey, amapStyleKey, amapLon, amapLat, amapZindex, lang, amapStyleKeyCustom, features } = toRefs(
  17. props.chartConfig.option
  18. )
  19. let map = shallowRef(null)
  20. const ininMap = () => {
  21. AMapLoader.load({
  22. key: amapKey.value, //api服务key--另外需要在public中使用安全密钥!!!
  23. version: '1.4.4', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  24. plugins: ['AMap.PlaceSearch', 'AMap.AutoComplete'] // 需要使用的的插件列表
  25. })
  26. .then(AMap => {
  27. map = new AMap.Map('container', {
  28. resizeEnable: true,
  29. zoom: amapZindex.value, // 地图显示的缩放级别
  30. center: [amapLon.value, amapLat.value],
  31. mapStyle: `amap://styles/${amapStyleKeyCustom.value !== '' ? amapStyleKeyCustom.value : amapStyleKey.value}`, //自定义地图的显示样式
  32. lang: lang.value,
  33. features: features.value
  34. })
  35. })
  36. .catch(e => {})
  37. }
  38. watch(
  39. () => props.chartConfig.option,
  40. newData => {
  41. ininMap()
  42. },
  43. { immediate: true, deep: true }
  44. )
  45. </script>