index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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="18">
  9. {{ d.category.name }}
  10. </el-col>
  11. <el-col :span="6">
  12. {{ d.num }}
  13. </el-col>
  14. </el-row>
  15. </a>
  16. </el-card>
  17. </div>
  18. </div>
  19. </template>
  20. <style type="text/css">
  21. .category {
  22. position: absolute;
  23. top: 80px;
  24. left: 30px;
  25. width: 200px;
  26. z-index: 9999;
  27. }
  28. .category a {
  29. display: block;
  30. padding: 10px 0;
  31. }
  32. </style>
  33. <script>
  34. import { findByGroupByDataType, findByMapBounds } from '@/api/place/base_info'
  35. import TencentMap from '@/components/TencentMap'
  36. export default {
  37. components: { TencentMap },
  38. data() {
  39. return {
  40. listData: [],
  41. categoryId: null,
  42. northEast: null,
  43. southWest: null,
  44. markerLayer: null
  45. }
  46. },
  47. created() {
  48. },
  49. mounted() {
  50. findByGroupByDataType().then(v => {
  51. console.log(v)
  52. this.listData = v
  53. })
  54. },
  55. methods: {
  56. changeDataType: function(categoryId) {
  57. this.categoryId = categoryId
  58. this.findData()
  59. },
  60. boundsChanged: function(northEast, southWest, markerLayer) {
  61. this.northEast = northEast
  62. this.southWest = southWest
  63. this.markerLayer = markerLayer
  64. this.findData()
  65. },
  66. findData() {
  67. const _this = this
  68. findByMapBounds(_this.northEast.lng, _this.northEast.lat, _this.southWest.lng, _this.southWest.lat, _this.categoryId)
  69. .then((res) => _this.setMarker(res))
  70. .finally(() => (_this.isloading = false))
  71. },
  72. setMarker: function(res) {
  73. const listGeometries = []
  74. res.forEach((o) => {
  75. let infoContent = '<div style="text-align: left">'
  76. infoContent += '<p>名称:' + (o.name ?? '-') + '</p>'
  77. infoContent += '<p>联系人:' + (o.contacts ?? '-') + '</p>'
  78. infoContent += '<p>电话:' + (o.contactNumber ?? '-') + '</p>'
  79. infoContent += '</div>'
  80. listGeometries.push({
  81. position: new TMap.LatLng(o.lat, o.lng),
  82. properties: {
  83. infoContent: infoContent
  84. }
  85. })
  86. })
  87. this.markerLayer.setGeometries(listGeometries)
  88. }
  89. }
  90. }
  91. </script>