map_search.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <view style="height: 100%;">
  3. <map style="width: 100%;height: 100%;" :latitude="latitude" :longitude="longitude" :markers="covers" @markertap="markertap($event)">
  4. </map>
  5. <cover-view class="map-pop-box" v-show="isShowPop" @click="goParkDetail()">
  6. <cover-view class="display-between">
  7. <cover-view class="pop-title">{{popInfo.title}}</cover-view>
  8. <cover-image src="/static/park/location2.png" style='width:50rpx;height:50rpx;'></cover-image>
  9. </cover-view>
  10. <cover-view class="display-flex-start" style="margin-bottom: 10rpx;">
  11. <cover-view class="pop-subtitle">入驻企业:</cover-view>
  12. <cover-view class="pop-value">{{popInfo.enterprise}}</cover-view>
  13. </cover-view>
  14. <cover-view class="display-flex-start">
  15. <cover-view class="pop-subtitle">园区地址:</cover-view>
  16. <cover-view class="pop-value">{{popInfo.address}}</cover-view>
  17. </cover-view>
  18. </cover-view>
  19. </view>
  20. </template>
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. id:0, // 使用 marker点击事件 需要填写id
  26. title: 'map',
  27. latitude: 39.909,
  28. longitude: 116.39742,
  29. isShowPop:false,
  30. popInfo:{
  31. title:"新鸿辉工业园测试数据",
  32. enterprise:'484',
  33. address:'渭城区底张镇88号',
  34. id:1
  35. },
  36. covers: [{
  37. id:1,
  38. latitude: 39.909,
  39. longitude: 116.39742,
  40. name:'天安门',
  41. iconPath: '/static/park/location.svg',
  42. }, {
  43. id:2,
  44. name:'XX12221',
  45. latitude: 39.90,
  46. longitude: 116.39,
  47. iconPath: '/static/park/location.svg'
  48. }]
  49. }
  50. },
  51. onLoad() {
  52. this.init()
  53. },
  54. methods: {
  55. init(){
  56. let that = this;
  57. that.mapRender(that,that.covers)
  58. },
  59. mapRender(that,data){
  60. let arrayData = [];
  61. for (var i = 0; i < data.length; i++) {
  62. arrayData.push({
  63. id: data[i].id, //marker点击事件回调会返回此id。建议为每个marker设置上Number类型id,保证更新marker时有更好的性能。
  64. latitude: data[i].latitude, //纬度
  65. longitude: data[i].longitude, //经度
  66. title: data[i].name, //点击时显示,callout存在时将被忽略
  67. iconPath:data[i].iconPath, //项目目录下的图片路径,支持相对路径写法,以'/'开头则表示相对小程序根目录;也支持临时路径
  68. width: 20,
  69. height: 30,
  70. callout: {
  71. content: data[i].name, //文本
  72. color: '#000', //文本颜色
  73. borderRadius: 3, //边框圆角
  74. borderWidth: 0, //边框宽度
  75. borderColor: '#FF0202', //边框颜色
  76. bgColor: '#fff', //背景色
  77. padding: 10, //文本边缘留白
  78. display:'ALWAYS',
  79. textAlign: 'center' //文本对齐方式 left, right, center
  80. },
  81. });
  82. }
  83. console.log(arrayData);
  84. that.covers = arrayData;
  85. },
  86. //地图点击事件
  87. markertap(e) {
  88. console.log("你点击的标记点ID是:" + e.detail.markerId)
  89. this.isShowPop = true;
  90. //console.log(e)
  91. // this.covers.forEach((item)=>{
  92. // if(item.id === e.detail.markerId){
  93. // item.label.color = '#000'
  94. // }else {
  95. // item.label.color = '#999'
  96. // }
  97. // })
  98. },
  99. goParkDetail(){
  100. uni.navigateTo({
  101. url:'park_deatil?id=1'
  102. })
  103. }
  104. },
  105. }
  106. </script>
  107. <style>
  108. page {
  109. height: 100%;
  110. }
  111. .map-pop-box {
  112. width: 92%;
  113. padding: 30rpx;
  114. background-color: #fff;
  115. position: fixed;
  116. bottom: 0;
  117. }
  118. .pop-title {
  119. font-size: 28rpx;
  120. font-weight: 600;
  121. line-height: 36rpx;
  122. letter-spacing: 0.02em;
  123. color: #0D1937;
  124. }
  125. .pop-subtitle{
  126. font-size: 20rpx;
  127. color: #CFCFCF;
  128. margin-right: 10rpx;
  129. }
  130. .pop-value {
  131. font-size: 20rpx;
  132. color: #0D1937;
  133. }
  134. </style>