SimplePointedMap.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <div :style="{ width, height }">
  3. <el-amap
  4. style="width: 100%"
  5. :center="center"
  6. :zoom="zoom"
  7. @init="handleInit"
  8. v-bind="$attrs"
  9. >
  10. <el-amap-marker :position="center" />
  11. </el-amap>
  12. </div>
  13. </template>
  14. <script setup lang="ts">
  15. import { onMounted, ref, watch } from 'vue';
  16. const props = defineProps({
  17. latitude: {
  18. type: [Number, String],
  19. default: 0
  20. },
  21. longitude: {
  22. type: [Number, String],
  23. default: 0
  24. },
  25. width: {
  26. type: [Number, String],
  27. default: '100%'
  28. },
  29. height: {
  30. type: [Number, String],
  31. default: '300px'
  32. }
  33. });
  34. const zoom = ref(12);
  35. const center = ref([121.59996, 31.197646]);
  36. let map: any = null;
  37. function handleInit(mapRef: any) {
  38. map = mapRef;
  39. }
  40. function loadMaker() {
  41. if (!map || !props.longitude || !props.latitude)
  42. return;
  43. center.value = [Number(props.longitude), Number(props.latitude)];
  44. }
  45. watch(() => [props.latitude, props.longitude], () => {
  46. loadMaker();
  47. });
  48. onMounted(() => {
  49. loadMaker();
  50. });
  51. </script>