map.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <div class="mappage_con" id="mapCon"></div>
  3. </template>
  4. <script>
  5. import remoteLoad from '@/utils/remoteLoad.js'
  6. import icon1 from '@/assets/images/fxc_img6.png'
  7. import icon2 from '@/assets/images/fxc_img7.png'
  8. import icon3 from '@/assets/images/fxc_img8.png'
  9. import { getEvvmListOffice } from '@/api/screen'
  10. export default({
  11. name:"MapPage",
  12. props: {
  13. markers: Array
  14. },
  15. data () {
  16. return {
  17. list:[],
  18. }
  19. },
  20. watch: {
  21. markers(nv,ov){
  22. var list = nv
  23. this.list = list
  24. this.setMarkers(list)
  25. },
  26. },
  27. async mounted () {
  28. var MapKey = this.MapKey
  29. // 已载入高德地图API,则直接初始化地图
  30. if (window.AMap && window.AMapUI) {
  31. this.initMap()
  32. // 未载入高德地图API,则先载入API再初始化
  33. } else {
  34. await remoteLoad(`http://webapi.amap.com/maps?v=1.4.15&key=${MapKey}`)
  35. await remoteLoad(`https://webapi.amap.com/ui/1.1/main.js`)
  36. // await remoteLoad(`https://a.amap.com/Loca/static/loca-v2/demos/mock_data/events.js`)
  37. this.initMap()
  38. }
  39. },
  40. methods: {
  41. // getList(){
  42. // getEvvmListOffice().then(response => {
  43. // var list = response.data
  44. // this.setMarkers(list)
  45. // });
  46. // },
  47. getInfo(id){
  48. this.$parent.getChainInfo(id)
  49. this.$parent.getChainTemperature(id)
  50. },
  51. initMap () {
  52. let AMap = this.AMap = window.AMap
  53. let mapConfig = {
  54. zoom: 5,
  55. mapStyle: 'amap://styles/darkblue',
  56. viewMode:'3D',
  57. pitch:45,
  58. rotation:10,
  59. center:[109.591091,33.096726],
  60. // showLabel: false //不显示地图文字标记
  61. }
  62. let map = this.map = new AMap.Map('mapCon', mapConfig)
  63. // 添加 3D 罗盘控制
  64. AMap.plugin([
  65. 'AMap.ControlBar',
  66. ], function(){
  67. map.addControl(new AMap.ControlBar());
  68. })
  69. // this.getList()
  70. },
  71. setMarkers(list){
  72. var that = this
  73. this.map.clearMap()// 清除地图上所有添加的覆盖物
  74. var markers = []
  75. for(var i in list){
  76. if(list[i].lng && list[i].lat){
  77. let marker = new AMap.Marker({
  78. position: new AMap.LngLat(list[i].lng,list[i].lat),
  79. //title: list[i].NAME + '<br>' + list[i].address,
  80. //offset: new AMap.Pixel(-20,43),//偏移量,默认以marker左上角位置为基准点
  81. icon:new AMap.Icon({
  82. size: new AMap.Size(45,45), // 图标尺寸
  83. image: require('@/assets/images/index_icon_'+list[i].transportType+list[i].status+'.png'),//[icon1,icon2,icon3][list[i].type], // Icon的图像
  84. // imageOffset: new AMap.Pixel(0, -60), // 图像相对展示区域的偏移量,适于雪碧图等
  85. imageSize: new AMap.Size(45, 45) // 根据所设置的大小拉伸或压缩图片
  86. }),
  87. clickable:true,
  88. extData:list[i],
  89. });
  90. marker.on("click",function(e){
  91. var extData = e.target.De.extData
  92. var id = extData.id
  93. that.getInfo(id)
  94. })
  95. markers.push(marker)
  96. }
  97. }
  98. this.map.add(markers)
  99. },
  100. }
  101. })
  102. </script>
  103. <style>
  104. .mappage_con{ position: absolute; top: 0; left: 0; right: 0; bottom: 0;}
  105. .mappage_con .amap-marker-label{background: rgba(35,4,194,0.6);font-size: 0.8vw; border: 1px solid #51FFFF; color: #ffffff; border-radius: 5px;}
  106. .amap-logo{ display: none!important;;}
  107. </style>