index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="app-container">
  3. <tencent-map id="amapcontainer" :height="900" :enable-click="false" :enable-bounds-changed="true" @boundsChanged="boundsChanged"/>
  4. <div class="category">
  5. <el-card>
  6. <a v-for="d in listData" :key="d.category.id" href="javascript:;" @click="changeDataType(d.category.id)">
  7. <el-row>
  8. <el-col :span="4">
  9. <el-image :src="d.category.iconImage" style="height: 20px"/>
  10. </el-col>
  11. <el-col :span="14">
  12. {{ d.category.name }}
  13. </el-col>
  14. <el-col :span="6">
  15. {{ d.num }}
  16. </el-col>
  17. </el-row>
  18. </a>
  19. </el-card>
  20. </div>
  21. </div>
  22. </template>
  23. <style type="text/css">
  24. .category {
  25. position: absolute;
  26. top: 80px;
  27. left: 30px;
  28. width: 200px;
  29. z-index: 9999;
  30. }
  31. .category a {
  32. display: block;
  33. padding: 10px 0;
  34. }
  35. .marker span {
  36. color: #666666;
  37. margin-right: 10px;
  38. font-size: 12px
  39. }
  40. .marker p{
  41. font-size: 16px;
  42. margin: 5px 0;
  43. }
  44. </style>
  45. <script>
  46. import { findByGroupByDataType, findByMapBounds } from '@/api/place/base_info'
  47. import TencentMap from '@/components/TencentMap'
  48. export default {
  49. components: { TencentMap },
  50. data() {
  51. return {
  52. listData: [],
  53. categoryId: null,
  54. northEast: null,
  55. southWest: null,
  56. markerLayer: null
  57. }
  58. },
  59. created() {
  60. },
  61. mounted() {
  62. findByGroupByDataType().then(v => {
  63. console.log(v)
  64. this.listData = v
  65. })
  66. },
  67. methods: {
  68. changeDataType: function(categoryId) {
  69. this.categoryId = categoryId
  70. this.findData()
  71. },
  72. boundsChanged: function(northEast, southWest, markerLayer) {
  73. this.northEast = northEast
  74. this.southWest = southWest
  75. this.markerLayer = markerLayer
  76. this.findData()
  77. },
  78. findData() {
  79. const _this = this
  80. findByMapBounds(_this.northEast.lng, _this.northEast.lat, _this.southWest.lng, _this.southWest.lat, _this.categoryId)
  81. .then((res) => _this.setMarker(res))
  82. .finally(() => (_this.isloading = false))
  83. },
  84. setMarker: function(res) {
  85. const listGeometries = []
  86. const listStyles = {}
  87. res.forEach((o) => {
  88. let infoContent = '<div style="text-align: left" class="marker">'
  89. infoContent += '<p><img src="' + o.litpic + '" width="200" height="150"/></p>'
  90. infoContent += '<p>' + (o.name ?? '-') + '</p>'
  91. infoContent += '<p><span>联系人</span>' + (o.contacts ?? '-') + '</p>'
  92. infoContent += '<p><span>电话</span>' + (o.contactNumber ?? '-') + '</p>'
  93. infoContent += '</div>'
  94. const styleKey = 'myStyle' + o.category.id
  95. listGeometries.push({
  96. 'id': o.id,
  97. 'styleId': styleKey,
  98. 'position': new TMap.LatLng(o.lat, o.lng),
  99. 'properties': {
  100. 'infoContent': infoContent
  101. }
  102. })
  103. listStyles[styleKey] = new TMap.MarkerStyle({
  104. 'width': 50,
  105. 'height': 60, // 点标记样式高度(像素)
  106. 'src': o.category.iconImage,
  107. 'anchor': { x: 16, y: 32 }
  108. })
  109. })
  110. console.log(listStyles)
  111. this.markerLayer.setStyles(listStyles)
  112. this.markerLayer.setGeometries(listGeometries)
  113. }
  114. }
  115. }
  116. </script>