cuixinyu-trajectory.nvue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <!-- <web-view allow="fullscreen" src="/hybrid/html/style3.html"></web-view> -->
  4. <map :show-compass="true" id='map' :style="{ width: '750rpx', height: windowHeight + 'px' }" :latitude="latitude" :longitude="longitude" :markers="covers" :scale="15.5" :polyline="polyline">
  5. </map>
  6. <!-- <view class="container">
  7. <map id='map' :latitude="latitude" :longitude="longitude" :markers="covers" :style="{ width: '100%', height: mapHeight + 'px' }"
  8. :scale="13" :polyline="polyline">
  9. </map>
  10. </view> -->
  11. <view style="
  12. display: flex;
  13. justify-content: center;
  14. align-items: center;
  15. width: 750rpx;
  16. position: absolute;
  17. bottom: 60rpx;
  18. z-index: 99;">
  19. <button @click="start" style="
  20. width: 200rpx;
  21. border-radius: 50%;
  22. background-color: #3282FF;
  23. height: 80rpx;"><text style="color: #FFFFFF;font-size: 15px">轨迹回放</text></button>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. var cxy = 0;
  30. export default {
  31. data() {
  32. return {
  33. windowHeight: 0,
  34. latitude: '',
  35. longitude: '',
  36. covers: [{
  37. id: 1,
  38. width: 20,
  39. height: 20,
  40. // rotate: 270,
  41. latitude: 41.1059556749132,
  42. longitude: 123.0674815538194,
  43. iconPath: '/static/img/location/point.png',
  44. callout: {
  45. content: "辽C·6L650", // 车牌信息
  46. display: "ALWAYS",
  47. fontWeight: "bold",
  48. color: "#5A7BEE", //文本颜色
  49. fontSize: "12px",
  50. bgColor: "#ffffff", //背景色
  51. padding: 5, //文本边缘留白
  52. textAlign: "center",
  53. },
  54. anchor: {
  55. x: 0.5,
  56. y: 0.5,
  57. },
  58. }],
  59. map:null,
  60. timer: null,
  61. isStart: false,
  62. playIndex:1,
  63. id: 0, // 使用 marker点击事件 需要填写id
  64. // 标记点
  65. // covers: [{
  66. // id: 1,
  67. // width: 42,
  68. // height: 47,
  69. // rotate: 270,
  70. // latitude: 34.259428,
  71. // longitude: 108.947040,
  72. // iconPath: 'http://cdn.zhoukaiwen.com/car.png',
  73. // callout: {
  74. // content: "陕A·88888", // 车牌信息
  75. // display: "ALWAYS",
  76. // fontWeight: "bold",
  77. // color: "#5A7BEE", //文本颜色
  78. // fontSize: "12px",
  79. // bgColor: "#ffffff", //背景色
  80. // padding: 5, //文本边缘留白
  81. // textAlign: "center",
  82. // },
  83. // anchor: {
  84. // x: 0.5,
  85. // y: 0.5,
  86. // },
  87. // }],
  88. // 线
  89. polyline: [],
  90. // 坐标数据
  91. coordinate: [],
  92. }
  93. },
  94. onLoad(options) {
  95. var that = this
  96. var systemInfo = uni.getSystemInfoSync()
  97. that.map = uni.createMapContext('map');
  98. console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>')
  99. console.log(systemInfo)
  100. that.windowHeight = systemInfo.windowHeight;
  101. //别的页面跳转传入
  102. // if(!!options.index) {
  103. // console.log('有轨迹索引:' + options.index)
  104. // that.jg(options.index)
  105. // } else {
  106. // console.log('无轨迹索引')
  107. // }
  108. //假数据
  109. that.jg()
  110. },
  111. onShow() {
  112. },
  113. methods: {
  114. jg(index) {
  115. var that = this
  116. // var list = app.globalData.trajectorylist[index]
  117. //假数据
  118. var list = [[104.11262817072013,30.58785571038842],[104.11267016098672,30.58788768673709],[104.11268815623596,30.58788066891832],[104.11272314665139,30.587855630019803],[104.11279812588855,30.587800545961333],[104.11281311969452,30.58771450139777],[104.11258617640551,30.587675679257952],[104.11212028996098,30.58776109839399],[104.11163339873552,30.587873534907622],[104.11121648332397,30.587970900871422],[104.11088654434462,30.58803718111346],[104.11057359625593,30.5880494237874],[104.11035163167045,30.588107611602812],[104.11024364743112,30.58811169322907],[104.11003067627313,30.58809484349796],[104.10992868974834,30.588101920349402],[104.1096837213051,30.58816211904157],[104.1092867680256,30.58831545600633],[104.10867082122292,30.588373898597393],[104.10795585967642,30.58840137615305],[104.10718087301872,30.58838485075459],[104.10645885948344,30.58835226218315],[104.1058518289909,30.58832559008871],[104.10535179085741,30.58830984992133],[104.10490874746588,30.58831007585494],[104.10462871486894,30.5882982095888],[104.1042916703609,30.58827336187798],[104.10382859953164,30.5882105520039],[104.10323649353396,30.58811677576343],[104.10263336885944,30.58804899732469],[104.10219126619663,30.58799714824715],[104.10202022179054,30.5878971746662],[104.10200521168947,30.587659092186442],[104.10202320865245,30.58737898215278],[104.10210022255824,30.587190884351102],[104.1021852414007,30.58712582869989],[104.10237128095089,30.58696669958113],[104.1025383137222,30.58677556451472],[104.10263332902122,30.58656544976139],[104.10267033436695,30.586465398255452],[104.10267133425926,30.586453393436912],[104.10269133817472,30.58643837996155],[104.1026753353411,30.58646139479639],[104.10268033642215,30.58646139281006],[104.10264032757779,30.58645540645753],[104.1026453295588,30.586488416639042],[104.10262632662739,30.586533440733213],[104.10257831950132,30.586660506445092],[104.10249530538262,30.58682359897764],[104.10233827394386,30.58699072105156],[104.10216523674897,30.5871318383939],[104.10206321458746,30.58723191316259],[104.10201320871903,30.58747402090636],[104.10201321630461,30.58775712547563],[104.10213625111113,30.58792914363932],[104.10245632762741,30.587981041400113],[104.10302645079821,30.58804383658719],[104.10349554035973,30.58809665724075],[104.1037615865323,30.5881305524741],[104.10387060438723,30.588141507517992],[104.10396661964624,30.588151467586552],[104.10430166906984,30.5881733201544],[104.10483873662507,30.588193067436162],[104.10550880171273,30.58822473624297],[104.10622084728116,30.58825436039147],[104.10694886915907,30.5882919550277],[104.10767086576674,30.58831652467279],[104.10836183865004,30.58830607829725],[104.10890580085373,30.588270701811272],[104.10925077027441,30.58826846368635],[104.1093437605644,30.58824839138817],[104.10946074788933,30.58822730142722],[104.10966872267439,30.58814812458102],[104.10995368602772,30.58808289516164],[104.11038862441845,30.58804155961188],[104.11092653467065,30.587934112263753],[104.11156041124947,30.58778355996879],[104.11223026082467,30.58762095597985],[104.11291008746153,30.58745932433694],[104.11357289826498,30.58729668743599],[104.11419770193609,30.58714407005203],[104.11475451240712,30.58701050671756],[104.11518035811253,30.5869050657829],[104.11539027910668,30.586852845511082],[104.11546025213438,30.58682776884644],[104.11560519757073,30.586849636598252],[104.11539927835331,30.586949872632832],[104.11493744974922,30.58706335444194],[104.11444462235875,30.58718785987891],[104.11398477357619,30.587299320430862],[104.1134929250277,30.58742380497047],[104.11306804788724,30.58755922547424],[104.11288010276677,30.58773545198354],[104.11278513005412,30.58783056811525],[104.11271514909583,30.587870642348832],[104.11259118025207,30.58786574528161],[104.11251819885757,30.5878848136816],[104.11249120591842,30.58790084223964],[104.11253619441777,30.58788479856955],[104.11254819134263,30.58788078700801],[104.11254819134263,30.58788078700801],[104.11255019044545,30.58786577978076],[104.11255019044545,30.58786577978076]]
  119. var coordinate = []
  120. var latitude_list = []
  121. var longitude_list = []
  122. console.log(list)
  123. for(var i = 0; i < list.length; i++) {
  124. var item = {
  125. latitude: list[i][1],
  126. longitude: list[i][0],
  127. }
  128. coordinate.push(item)
  129. latitude_list.push(list[i][1])
  130. longitude_list.push(list[i][0])
  131. }
  132. console.log(coordinate)
  133. that.coordinate = coordinate
  134. if(list.length > 1) {
  135. var px_latitude = latitude_list.sort(function(a, b){
  136. return a-b;
  137. })
  138. var px_longitude = longitude_list.sort(function(a, b){
  139. return a-b;
  140. })
  141. that.latitude = (px_latitude[px_latitude.length - 1] + px_latitude[0]) / 2
  142. that.longitude = (px_longitude[px_longitude.length - 1] + px_longitude[0]) / 2
  143. console.log(that.latitude)
  144. console.log(that.longitude)
  145. } else {
  146. that.latitude = that.coordinate[0].latitude
  147. that.longitude = that.coordinate[0].longitude
  148. }
  149. that.covers = [{
  150. id: 1,
  151. width: 20,
  152. height: 20,
  153. // rotate: 270,
  154. latitude: that.coordinate[0].latitude,
  155. longitude: that.coordinate[0].longitude,
  156. iconPath: '/static/img/location/point.png',
  157. callout: {
  158. content: "辽C·6L650", // 车牌信息
  159. display: "ALWAYS",
  160. fontWeight: "bold",
  161. color: "#5A7BEE", //文本颜色
  162. fontSize: "12px",
  163. bgColor: "#ffffff", //背景色
  164. padding: 5, //文本边缘留白
  165. textAlign: "center",
  166. },
  167. anchor: {
  168. x: 0.5,
  169. y: 0.5,
  170. },
  171. }]
  172. that.polyline = [{
  173. points: that.coordinate,
  174. color: 'red',
  175. width: 4,
  176. dottedLine: false,
  177. }];
  178. },
  179. start() {
  180. var that = this
  181. that.isStart = true;
  182. let data = that.coordinate;
  183. let len = data.length;
  184. // var list = []
  185. cxy = setInterval(() => {
  186. console.log(that.playIndex + '/' + len)
  187. if(that.playIndex == len) {
  188. clearInterval(cxy);
  189. console.log('okokok');
  190. // uni.showToast({
  191. // title: '播放完成',
  192. // duration: 1500,
  193. // icon: 'none',
  194. // mask: false
  195. // });
  196. that.playIndex = 0;
  197. that.isStart = false;
  198. } else {
  199. let datai = data[that.playIndex];
  200. that.map.translateMarker({
  201. markerId: 1,
  202. autoRotate:true,
  203. // rotate: 90,
  204. destination: {
  205. longitude: datai.longitude, // 车辆即将移动到的下一个点的经度
  206. latitude: datai.latitude, // 车辆即将移动到的下一个点的纬度
  207. },
  208. duration: 250,
  209. complete: function(){
  210. that.playIndex++;
  211. },
  212. animationEnd: function() {
  213. // 轨迹回放完成
  214. // list.push({
  215. // longitude: data[that.playIndex - 1].longitude,
  216. // latitude: data[that.playIndex - 1].latitude
  217. // })
  218. // that.polyline = [{
  219. // points: that.coordinate,
  220. // color: 'red',
  221. // width: 4,
  222. // dottedLine: false,
  223. // },
  224. // {
  225. // points: list,
  226. // color: 'green',
  227. // width: 4,
  228. // dottedLine: false,
  229. // },
  230. // ];
  231. },
  232. fail(e) {
  233. // 轨迹回放失败
  234. uni.showToast({
  235. title: '播放失败',
  236. duration: 1500,
  237. icon: 'none',
  238. mask: false
  239. });
  240. },
  241. });
  242. }
  243. }, 250)
  244. },
  245. }
  246. }
  247. </script>
  248. <style>
  249. /* page {
  250. background-color: #25263A;
  251. } */
  252. </style>