warehouseReceiptMap.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <style lang='scss' scoped>
  2. .mapContent {
  3. position: relative;
  4. height: 95%;
  5. transition: 0.5s;
  6. .center-add {
  7. position: absolute;
  8. top: 0;
  9. bottom: 0;
  10. left: 0;
  11. right: 0;
  12. margin: auto;
  13. z-index: 999;
  14. width: 30px;
  15. height: 30px;
  16. }
  17. }
  18. #mapContainer {
  19. width: 100%;
  20. height: 100%;
  21. }
  22. .amap-info-close {
  23. display: none !important;
  24. }
  25. </style>
  26. <template>
  27. <div class="mapContent">
  28. <div id="mapContainer"></div>
  29. </div>
  30. </template>
  31. <script>
  32. import {
  33. regionData,
  34. CodeToText,
  35. TextToCode
  36. } from 'element-china-area-data'
  37. import image from '../../../public/img/ic_locationmarker.jpg'
  38. import AMapLoader from '@amap/amap-jsapi-loader';
  39. export default {
  40. data() {
  41. return {
  42. map: null,
  43. marker: null,
  44. markers: [],
  45. zoomEnable: true,
  46. dragEnable: true,
  47. status: true,
  48. }
  49. },
  50. props: [
  51. 'listData'
  52. ],
  53. computed: {},
  54. watch: {
  55. listData: function(val1, val2) {
  56. this.listData = val1
  57. var that = this
  58. this.map = new AMap.Map('mapContainer', {
  59. resizeEnable: true,
  60. zoom: 5,
  61. center: [103.809074, 36.051121],
  62. zoomEnable: this.zoomEnable,
  63. dragEnable: this.dragEnable
  64. })
  65. this.loadmap()
  66. }
  67. },
  68. async created() {
  69. // AMapLoader.reset();
  70. if (window.AMap && window.AMapUI) {
  71. // 未载入高德地图API,则先载入API再初始化
  72. } else {
  73. // await remoteLoad(`http://webapi.amap.com/maps?v=1.3&key=${MapKey}&plugin=AMap.AutoComplete`)
  74. // await remoteLoad('http://webapi.amap.com/ui/1.0/main.js')
  75. // AMapLoader.reset();
  76. AMapLoader.load({
  77. "key": "211dd6f989e719022aaf47ddb0659c47", // 申请好的Web端开发者Key,首次调用 load 时必填
  78. "version": "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  79. "plugins": ['plugin=AMap.Scale', 'AMap.ToolBar','AMap.AutoComplete', 'AMap.PlaceSearch', 'AMap.Geocoder', 'AMap.DistrictSearch','AMap.Geolocation', 'Geolocation'],
  80. "Loca": { // 是否加载 Loca, 缺省不加载
  81. "version": '2.0.0' // Loca 版本,缺省 1.3.2
  82. },
  83. }).then((AMap) => {
  84. })
  85. }
  86. },
  87. mounted() {},
  88. methods: {
  89. makeMarkersList() {
  90. let _list = this.listData
  91. for (let i = 0; i < _list.length; i++) {
  92. _list[i].marker = []
  93. _list[i].marker.push(_list[i].warehousePositioning.split(',')[1])
  94. _list[i].marker.push(_list[i].warehousePositioning.split(',')[0])
  95. }
  96. },
  97. loadmap(val) {
  98. let that = this
  99. //构造markersList
  100. AMap.plugin(['AMap.DistrictSearch', 'AMap.Polygon'], function() {
  101. var geolocation = new AMap.Geolocation({
  102. // 是否使用高精度定位,默认:true
  103. enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大
  104. timeout: 10000, // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
  105. buttonOffset: new AMap.Pixel(10, 20), // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
  106. zoomToAccuracy: true, // 定位按钮的排放位置, RB表示右下
  107. buttonPosition: 'RB'
  108. })
  109. geolocation.getCurrentPosition()
  110. geolocation.on( 'complete', e => {
  111. console.log(e) // 定位成功之后做的事 // 定位成功之后再定位处添加一个marker
  112. var infoWindow = new AMap.InfoWindow({
  113. offset: new AMap.Pixel(0, -30)
  114. })
  115. function infoOpen(e) {
  116. infoWindow.setContent(e.target.content)
  117. infoWindow.open(that.map, e.target.getPosition())
  118. }
  119. function infoClose(e) {
  120. infoWindow.close(that.map, e.target.getPosition())
  121. }
  122. function toGetList(e) {
  123. // console.log(e.target.getExtData())
  124. that.$parent.getList(e.target.getExtData().id, 1)
  125. }
  126. for (let i = 0; i < that.listData.length; i++) {
  127. var marker = new AMap.Marker({
  128. map: that.map,
  129. position: that.listData[i]
  130. .marker, // marker最终显示在那个点上,
  131. icon: new AMap.Icon({
  132. image: "https://taohaoliang.oss-cn-beijing.aliyuncs.com/pcfiles/home_pic.png",
  133. size: new AMap.Size(20, 20), //图标大小
  134. imageSize: new AMap.Size(20, 20),
  135. }),
  136. })
  137. marker.setExtData({
  138. 'id': that.listData[i].warehouseName
  139. })
  140. let _cwList = '<div class="cw-wrap">'
  141. for (let k = 0; k < that.listData[i].tradeWarehouseReceiptAppls.length; k++) {
  142. let _k = that.listData[i].tradeWarehouseReceiptAppls[k]
  143. _cwList += '<div style="display:flex">' +
  144. '<div style="margin:10px 20px">' + _k.warehouseNo + '仓位</div>' +
  145. '<div style="margin:10px 20px">' + _k.goodsName + '</div>' +
  146. '<div style="margin:10px 20px">' + _k.weight + '</div>' +
  147. '</div>'
  148. }
  149. _cwList = _cwList + '</div>'
  150. console.log('地图仓位数据', _cwList)
  151. marker.content = '<div style="display:flex;justify-content: center">' + that.listData[i]
  152. .warehouseName + '</div>' + _cwList + '</div>'
  153. marker.on('mouseover', infoOpen)
  154. marker.on('mouseout', infoClose)
  155. marker.on('click', toGetList)
  156. // 设置label标签
  157. // label默认蓝框白底左上角显示,样式className为:amap-marker-label
  158. // marker.setLabel({
  159. // offset: new AMap.Pixel(20, 20), //设置文本标注偏移量
  160. // content: "<div class='info'>我是 marker 的 label 标签</div>", //设置文本标注内容
  161. // direction: 'right' //设置文本标注方位
  162. // });
  163. }
  164. })
  165. geolocation.on( 'error', e => {
  166. console.log(e) // 定位失败
  167. })
  168. })
  169. }
  170. }
  171. }
  172. </script>