sportsTrajectory.nvue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <view>
  3. <view class="datebox">
  4. <picker :value="date" mode="date" fields="day" @change="changeday">
  5. <view class="datebox-item u-f u-f-ac u-f-ajc">
  6. 日期:{{date}}
  7. <uni-icons type="down" size="18"></uni-icons>
  8. </view>
  9. </picker>
  10. </view>
  11. <!--轨迹地图-->
  12. <view class="mapbox">
  13. <map class="mapstyle" id='map' :latitude="latitude" :longitude="longitude" :markers="covers"
  14. :style="{width: windowWidth+'px', height: height}" :scale="13" :polyline="polyline">
  15. <!-- <cover-view class="btnBox">
  16. <button :disabled="isDisabled" @click="start" class="btnBox_btn btnBox_one">开始回放</button>
  17. <button @click="pause" class="btnBox_btn btnBox_two">暂停</button>
  18. </cover-view> -->
  19. </map>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import timeFormat from '@/utils/timeFormat.js'
  25. import { queryGnssByDateAndDeviceId,getInfoByDeviceIds } from "@/api/pages_watch/index.js"
  26. export default {
  27. data() {
  28. return {
  29. show: true,
  30. windowWidth: uni.getSystemInfoSync().windowWidth,
  31. windowHeight: uni.getSystemInfoSync().windowHeight,
  32. height: 0,
  33. date: "",
  34. map: null,
  35. movementInterval: null, // 用于存储定时器的引用
  36. mapHeight: 0,
  37. timer: null,
  38. isDisabled: false,
  39. isStart: false,
  40. playIndex: 1,
  41. id: 0, // 使用 marker点击事件 需要填写id
  42. title: 'map',
  43. latitude: 39.909,
  44. longitude: 116.39742,
  45. // 标记点
  46. covers: [{
  47. id: 1,
  48. width: 42,
  49. height: 42,
  50. latitude: 39.909,
  51. longitude: 116.39742,
  52. iconPath: '/static/images/pages_watch/icons/location.png',
  53. callout: {
  54. content: "", //
  55. display: "ALWAYS",
  56. fontWeight: "bold",
  57. color: "#ffffff", //文本颜色
  58. fontSize: "12px",
  59. bgColor: "#282c34", //背景色
  60. padding: 5, //文本边缘留白
  61. textAlign: "center",
  62. },
  63. anchor: {
  64. x: 0.5,
  65. y: 0.5,
  66. },
  67. }],
  68. // 线
  69. polyline: [],
  70. // 坐标数据
  71. coordinate: [],
  72. isFamily: false
  73. }
  74. },
  75. onLoad(option) {
  76. this.isFamily = option.selectUser != '0'
  77. const height = this.windowHeight - uni.upx2px(90)
  78. this.height = height + 'px'
  79. this.date = timeFormat(new Date())
  80. this.getGnss()
  81. this.getUser()
  82. },
  83. onReady() {
  84. // 创建map对象
  85. this.map = uni.createMapContext('map');
  86. },
  87. methods: {
  88. getGnss(){
  89. const param = {
  90. date: this.date,
  91. deviceId: uni.getStorageSync("deviceId")
  92. }
  93. queryGnssByDateAndDeviceId(param).then(res=>{
  94. if(res.code == 200) {
  95. this.coordinate = res.data.map(item=>({
  96. ...item,
  97. latitude: item.lat,
  98. longitude: item.lng,
  99. }))
  100. this.polyline = [{
  101. points: this.coordinate,
  102. color: '#025ADD',
  103. width: 4,
  104. dottedLine: false,
  105. }];
  106. this.latitude = this.coordinate[this.coordinate.length - 1].latitude || 39.909
  107. this.longitude = this.coordinate[this.coordinate.length - 1].longitude || 116.39742
  108. this.covers[0].latitude = this.latitude
  109. this.covers[0].longitude = this.longitude
  110. this.$nextTick(()=>{
  111. this.map.moveToLocation({
  112. latitude:this.latitude,
  113. longitude:this.longitude,
  114. })
  115. this.map.addMarkers({
  116. markers: this.covers,
  117. clear: false
  118. })
  119. })
  120. } else {
  121. uni.showToast({
  122. title: res.msg,
  123. icon: "none",
  124. });
  125. }
  126. })
  127. },
  128. changeday(e) {
  129. this.date = e.detail.value
  130. this.getGnss()
  131. },
  132. getUser() {
  133. const deviceId = uni.getStorageSync('deviceId') || ''
  134. const param = {
  135. deviceIds: deviceId,
  136. isFamily: this.isFamily
  137. }
  138. getInfoByDeviceIds(param).then(res => {
  139. if (res.code == 200) {
  140. this.covers[0].callout.content = res.data[0].ble
  141. this.$nextTick(()=>{
  142. this.map.addMarkers({
  143. markers: this.covers,
  144. clear: false
  145. })
  146. })
  147. }
  148. })
  149. },
  150. start() {
  151. if (this.movementInterval) {
  152. clearInterval(this.movementInterval);
  153. }
  154. this.isStart = true;
  155. this.moveMarker();
  156. },
  157. moveMarker() {
  158. if (!this.isStart) return;
  159. if (this.playIndex >= this.coordinate.length) {
  160. this.playIndex = 0;
  161. uni.showToast({
  162. title: "播放完成",
  163. duration: 1400,
  164. icon: "none",
  165. });
  166. this.isStart = false;
  167. this.isDisabled = false;
  168. return;
  169. }
  170. let datai = this.coordinate[this.playIndex];
  171. this.map.translateMarker({
  172. markerId: 1,
  173. autoRotate: true,
  174. destination: {
  175. longitude: datai.longitude,
  176. latitude: datai.latitude,
  177. },
  178. duration: 700,
  179. complete: () => {
  180. this.playIndex++;
  181. this.moveMarker();
  182. },
  183. });
  184. },
  185. pause() {
  186. this.isStart = false;
  187. this.isDisabled = false;
  188. if (this.movementInterval) {
  189. clearInterval(this.movementInterval);
  190. this.movementInterval = null;
  191. }
  192. },
  193. }
  194. }
  195. </script>
  196. <style lang="scss" scoped>
  197. .datebox {
  198. background-color: #fff;
  199. padding: 24rpx;
  200. .datebox-item {
  201. display: flex;
  202. flex-direction: row;
  203. align-items: center;
  204. }
  205. }
  206. .mapstyle {
  207. position: relative;
  208. }
  209. .btnBox {
  210. width: 750rpx;
  211. position: absolute;
  212. bottom: 60rpx;
  213. z-index: 99;
  214. display: flex;
  215. flex-direction: row;
  216. justify-content: space-around;
  217. .btnBox_btn {
  218. margin: 0;
  219. background-color: #1e80ff;
  220. color: #fff;
  221. border: none;
  222. width: 90px;
  223. font-size: 10px;
  224. &::after {
  225. border: none;
  226. }
  227. }
  228. .btnBox_one {
  229. background-color: #1e80ff;
  230. }
  231. .btnBox_two {
  232. background-color: #e0433e;
  233. }
  234. }
  235. </style>