index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <t-dialog
  3. :visible="visible"
  4. :header="`打卡地址`"
  5. :width="1200"
  6. :closeOnOverlayClick="false"
  7. @close="emit('close', false)"
  8. :footer="false"
  9. >
  10. <div class="map-container" ref="mapContainer"></div>
  11. </t-dialog>
  12. </template>
  13. <script setup name="QqMap">
  14. import { ref, onMounted } from 'vue';
  15. const props = defineProps({ longitude: Number, latitude: Number });
  16. const emit = defineEmits(['close']);
  17. const mapContainer = ref();
  18. const visible = ref(true);
  19. const myMap = ref(null);
  20. const markerLayer = ref(null);
  21. onMounted(() => {
  22. let center = new window.TMap.LatLng(props.latitude, props.longitude);
  23. myMap.value = new window.TMap.Map(mapContainer.value, {
  24. center: center, //设置地图中心点坐标
  25. zoom: 17.2, //设置地图缩放级别
  26. pitch: 43.5, //设置俯仰角
  27. rotation: 45, //设置地图旋转角度
  28. });
  29. markerLayer.value = new window.TMap.MultiMarker({
  30. map: myMap.value, //指定地图容器
  31. //样式定义
  32. styles: {
  33. //创建一个styleId为"myStyle"的样式(styles的子属性名即为styleId)
  34. myStyle: new window.TMap.MarkerStyle({
  35. width: 25, // 点标记样式宽度(像素)
  36. height: 35, // 点标记样式高度(像素)
  37. // src: '../img/marker.png', //图片路径
  38. //焦点在图片中的像素位置,一般大头针类似形式的图片以针尖位置做为焦点,圆形点以圆心位置为焦点
  39. anchor: { x: 16, y: 32 },
  40. }),
  41. },
  42. //点标记数据数组
  43. geometries: [
  44. {
  45. id: '1', //点标记唯一标识,后续如果有删除、修改位置等操作,都需要此id
  46. styleId: 'myStyle', //指定样式id
  47. position: new window.TMap.LatLng(props.latitude, props.longitude), //点标记坐标位置
  48. properties: {
  49. //自定义属性
  50. title: 'marker1',
  51. },
  52. },
  53. ],
  54. });
  55. });
  56. </script>
  57. <style lang="less" scoped>
  58. .map-container {
  59. width: 100%;
  60. height: calc(100vh - 150px);
  61. }
  62. </style>