mapNew - 副本.nvue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <div>
  3. <!-- <h1>11111111111</h1> -->
  4. <!-- <map id="map" ref="map" style="height: 713rpx;width: 100%;" @tap="tapMap">
  5. </map> -->
  6. <map id="map" ref="map" :polyline="polyline" :scale="scale" style="height: 300rpx;width: 100%;"
  7. :markers="markers" :polygons="polygons" :latitude="latitude" :longitude="longitude" @tap="tap"
  8. :show-location="true" :show-compass="true" @anchorpointtap="poitap" enable-rotate enable-overlooking
  9. enable-poi></map>
  10. <div style="display: flex;">
  11. <button @click="path()"> 绘制轨迹</button>
  12. <button @click="graph()"> 绘制矩形</button>
  13. <button @click="getLocation()"> 获取当前定位信息</button>
  14. </div>
  15. </div>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. barHeight: null, //动态高度初始值
  22. windowHeight: null,
  23. needBack: true,
  24. latitude: '39.997761',
  25. longitude: '116.478928',
  26. value: '1223',
  27. markers: [{
  28. latitude: 39.909,
  29. longitude: 116.39742,
  30. width: 60,
  31. height: 60,
  32. rotate: 90,
  33. iconPath: 'https://hellouniapp.dcloud.net.cn/static/location.png'
  34. }, ],
  35. polygons: [{
  36. points: [],
  37. fillColor: '#BB0000DD',
  38. width: 5,
  39. strokeColor: "blue", //描边颜色
  40. strokeWidth: 4, //描边宽度
  41. zIndex: 100, //层级
  42. }],
  43. polyline: [{
  44. points: [],
  45. arrowLine: true,
  46. }],
  47. scale: 16,
  48. title: '',
  49. msg: '',
  50. msg2: '',
  51. intTime: 0,
  52. maxTime: 0,
  53. minTime: 0,
  54. totalTime: 0,
  55. initTime: new Date().getTime(),
  56. lastTime: 0,
  57. nowtime: 0,
  58. locTime: 0,
  59. reTime: 0,
  60. count: 0,
  61. errorCount: 0,
  62. }
  63. },
  64. onLoad() {
  65. },
  66. methods:{
  67. //获取当前位置
  68. getLocation() {
  69. uni.getLocation({
  70. type: 'gcj02',
  71. success: (res) => {
  72. console.log('当前位置的经度:' + res.longitude);
  73. console.log('当前位置的纬度:' + res.latitude);
  74. // this.longitude = res.longitude
  75. // this.latitude = res.latitude
  76. // // this.move()
  77. // this.markeMove()
  78. }
  79. });
  80. },
  81. tap(e){
  82. console.log(e);
  83. },
  84. poitap(e) {
  85. console.log('点击maps', e.detail)
  86. // this.longitude = e.detail.longitude
  87. // this.latitude = e.detail.latitude
  88. // this.markeMove()
  89. },
  90. //绘制轨迹
  91. path(){
  92. let polyline_obj = JSON.parse(JSON.stringify(this.polyline[0]));
  93. polyline_obj.points = [
  94. {
  95. "longitude": 116.478928,
  96. "latitude": 39.997761
  97. },
  98. {
  99. "longitude": 116.478907,
  100. "latitude": 39.998422
  101. },
  102. {
  103. "longitude": 116.479384,
  104. "latitude": 39.998546
  105. },
  106. {
  107. "longitude": 116.481053,
  108. "latitude": 39.998204
  109. },
  110. {
  111. "longitude": 116.481793,
  112. "latitude": 39.997868
  113. },
  114. {
  115. "longitude": 116.482898,
  116. "latitude": 39.998217
  117. },
  118. {
  119. "longitude": 116.483789,
  120. "latitude": 39.999063
  121. },
  122. {
  123. "longitude": 116.484674,
  124. "latitude": 39.999844
  125. }
  126. ]
  127. let polyline = [polyline_obj, ];
  128. // 然后整体再赋值给原 polyline
  129. this.polyline = polyline;
  130. this.longitude = "116.478928"
  131. this.latitude = "39.997761"
  132. },
  133. //绘制矩形
  134. graph(){
  135. let polygons_obj = JSON.parse(JSON.stringify(this.polygons[0]));
  136. polygons_obj.points =[
  137. { // 右上
  138. latitude: 30.264786,
  139. longitude: 120.10775,
  140. }, { // 右下
  141. latitude: 30.268786,
  142. longitude: 120.10775,
  143. },
  144. { // 左下
  145. latitude: 30.268786,
  146. longitude: 120.10465,
  147. }, { // 左上
  148. latitude: 30.264786,
  149. longitude: 120.10575,
  150. }
  151. ]
  152. let polygons = [polygons_obj, ];
  153. // 然后整体再赋值给原 polygons
  154. this.polygons = polygons;
  155. console.log('矩形重画完毕')
  156. this.longitude = "120.10775"
  157. this.latitude = "30.264786"
  158. },
  159. }
  160. }
  161. </script>
  162. <style>
  163. </style>