mapTest.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872
  1. <template>
  2. <div class="container">
  3. <div id="amap-container"></div>
  4. <div class="mapcontroller">
  5. <div class="in_transit_information">
  6. <label class="item_details">起点:{{ startPointName }}</label>
  7. <br />
  8. <label class="item_details">收货地址:{{ endPointName }}</label>
  9. <br />
  10. </div>
  11. <div class="driving_information2">
  12. <label class="item_details">时间:{{ runRoute.gtm }}</label>
  13. <br />
  14. <label class="item_details">车速:{{ runRoute.spd }}千米/小时</label>
  15. <br />
  16. <br />
  17. <!--控制条-->
  18. <div class="map-control" v-show="isActual">
  19. <!--播放暂停按钮-->
  20. <Icon
  21. v-if="!isPlay"
  22. class="play-icon play"
  23. type="ios-play"
  24. @click="
  25. isPlay = true
  26. play()
  27. navgControl(playIcon)
  28. "
  29. />
  30. <Icon
  31. v-else
  32. class="play-icon pause"
  33. type="ios-pause"
  34. @click="
  35. isPlay = false
  36. stop()
  37. navgControl('pause')
  38. "
  39. />
  40. <Icon class="play-icon quickly" type="ios-play" @click="addIndex()" />
  41. <!--已播放时间-->
  42. <!--进度条-->
  43. <div class="mySlider">
  44. <Slider
  45. class="map-slider"
  46. v-model="sliderVal"
  47. :tip-format="hideFormat"
  48. :step="0.0001"
  49. ></Slider>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <el-row>
  55. <el-button type="primary" @click="slow">慢速</el-button>
  56. <el-button type="success" @click="middle">中速</el-button>
  57. <el-button type="danger" @click="fast">快速</el-button>
  58. <el-button type="success" @click="addIndex" plain>快进</el-button>
  59. <el-button type="danger" @click="stop" plain>暂停</el-button>
  60. <el-button type="success" @click="play" plain>开始</el-button>
  61. <el-select
  62. style="width:100px"
  63. @change="changeParkingTime"
  64. v-model="parkingTime"
  65. placeholder="停车"
  66. >
  67. <el-option
  68. v-for="item in parkingOptions"
  69. :key="item.value"
  70. :label="item.label"
  71. :value="item.value"
  72. >
  73. </el-option>
  74. </el-select>
  75. <el-select
  76. style="width:100px"
  77. @change="changeLeaveTime"
  78. v-model="leaveTime"
  79. placeholder="离线"
  80. >
  81. <el-option
  82. v-for="item in parkingOptions"
  83. :key="item.value"
  84. :label="item.label"
  85. :value="item.value"
  86. >
  87. </el-option>
  88. </el-select>
  89. </el-row>
  90. <div class="btnx">
  91. <el-button type="primary" class="" @click="openInfo"
  92. >打开信息窗体</el-button
  93. >
  94. <el-button type="primary" class="" @click="closeinfo"
  95. >关闭信息窗口</el-button
  96. >
  97. </div>
  98. </div>
  99. </template>
  100. <script>
  101. import { shallowRef } from '@vue/reactivity'
  102. import { lazyAMapApiLoaderInstance } from 'vue-amap'
  103. import Slider from './slider.vue'
  104. import { getCookie } from '@/utils/util.js'
  105. Vue.use(Slider)
  106. import Vue from 'vue'
  107. var infoWindow
  108. export default {
  109. name: 'PathView',
  110. props: {
  111. orderNumber: '',
  112. capacityNumber: '',
  113. startPointName: '',
  114. endPointName: '',
  115. statusCode: ''
  116. },
  117. setup() {
  118. const map = shallowRef(null)
  119. return {
  120. map
  121. }
  122. },
  123. watch: {
  124. //监听车牌号变化
  125. orderNumber: {
  126. deep: true,
  127. handler(val, oldVal) {
  128. console.log(val)
  129. this.initData(val)
  130. }
  131. }
  132. },
  133. data() {
  134. return {
  135. ///che
  136. isTimesChoose: false,
  137. isActual: true,
  138. isPlay: false,
  139. passedTime: '12:02:10',
  140. sliderVal: 0,
  141. times: 1,
  142. totalTime: '11',
  143. speed: 10000,
  144. startTime: '',
  145. endTime: '',
  146. //选择停车时长
  147. parkingTime: null,
  148. //停车时长选择区间
  149. parkingOptions: [
  150. {
  151. value: 600000,
  152. label: '10分钟'
  153. },
  154. {
  155. value: 1200000,
  156. label: '20分钟'
  157. },
  158. {
  159. value: 1800000,
  160. label: '30分钟'
  161. },
  162. {
  163. value: 2400000,
  164. label: '40分钟'
  165. },
  166. {
  167. value: 3000000,
  168. label: '50分钟'
  169. },
  170. {
  171. value: 3600000,
  172. label: '60分钟'
  173. },
  174. {
  175. value: 36000000,
  176. label: '关闭'
  177. }
  178. ],
  179. //离线图标
  180. leaveMark: [],
  181. //停车图标
  182. parkMark: [],
  183. //选择离线时长
  184. leaveTime: null,
  185. //离线时长选择区间
  186. leaveOptions: [
  187. {
  188. value: 600000,
  189. label: '10分钟'
  190. },
  191. {
  192. value: 1200000,
  193. label: '20分钟'
  194. },
  195. {
  196. value: 1800000,
  197. label: '30分钟'
  198. },
  199. {
  200. value: 2400000,
  201. label: '40分钟'
  202. },
  203. {
  204. value: 3000000,
  205. label: '50分钟'
  206. },
  207. {
  208. value: 3600000,
  209. label: '60分钟'
  210. },
  211. {
  212. value: 36000000,
  213. label: '关闭'
  214. }
  215. ],
  216. //已行驶轨迹
  217. runRoute: {
  218. agl: '',
  219. gtm: '',
  220. hgt: '',
  221. lat: '',
  222. lon: '',
  223. mil: '',
  224. spd: ''
  225. },
  226. point: '',
  227. pointNext: '',
  228. loading: null,
  229. navgtrSpeed: 1,
  230. //地图中心位置
  231. centerPoint: {
  232. pointLat: '',
  233. pointLon: ''
  234. },
  235. //自定义窗体信息
  236. ctmarkes: {
  237. lat: '33.015888071433764',
  238. lon: '115.96995235868168',
  239. title: '豫SE8888',
  240. details: '安徽省阜阳市颍东区阜阳舜岳水泥公司,西北方向,155.1米'
  241. },
  242. //运输详情
  243. transportDetail: {
  244. //车牌号
  245. capacityNumber: '',
  246. //规划路线
  247. estimateRoute: [
  248. {
  249. lat: '33.015888071433764',
  250. lon: '115.96995235868168'
  251. }
  252. ],
  253. //规划线路
  254. estimatePath: [[114.03046212985384, 32.49786984660489]],
  255. //已行驶轨迹
  256. runRoute: [
  257. {
  258. agl: '44',
  259. gtm: '2022年03月09日 16:47:24',
  260. hgt: '13',
  261. lat: '32.906411535084985',
  262. lon: '115.76177868692135',
  263. mil: '429409.2',
  264. spd: '17.0'
  265. }
  266. ],
  267. runPath: [[114.03922119568348, 32.49746162481379]],
  268. //当前位置
  269. currentPointName: '中国达州市通川区',
  270. //当前位置经纬度
  271. currentPoint: {
  272. lat: '',
  273. lon: ''
  274. },
  275. //起点位置
  276. startPointName: '中国达州市通川区',
  277. //起点位置经纬度
  278. startPoint: {
  279. lon: '114.03922119568348',
  280. lat: '32.49746162481379'
  281. },
  282. //终点位置
  283. endPointName: '中国成都萧山',
  284. //终点位置经纬度
  285. endPoint: {
  286. lon: '115.96995737755431',
  287. lat: '33.01595479752097'
  288. },
  289. //自定义标记
  290. content: [],
  291. //异常位置
  292. abnormalLocation: []
  293. },
  294. listPath: [],
  295. //组件
  296. pathSimplifierIns: {},
  297. pathNavigator: {},
  298. //地图解析
  299. geocoder: null,
  300. currentPointName: ''
  301. }
  302. },
  303. created() {
  304. let that = this
  305. that.initData(that.orderNumber)
  306. },
  307. mounted() {},
  308. methods: {
  309. //停车时间改变
  310. changeParkingTime() {
  311. let that = this
  312. //清除之前的停车点
  313. that.hideParkingMark()
  314. //计算时间的点
  315. let calculationPoint = null
  316. that.listPath[0].runRoute.forEach(function(item, indexOf) {
  317. if (indexOf + 1 < that.listPath[0].runRoute.length) {
  318. //判断calculationPoint是否为空,如果是空的说明当前没有在计算停车时间
  319. if (calculationPoint == null && item.spd == '0.0') {
  320. calculationPoint = item
  321. } else if (calculationPoint != null && item.spd != '0.0') {
  322. let beforeTime = that.stringToDate(calculationPoint.gtm)
  323. let item2 = that.listPath[0].runRoute[indexOf]
  324. let afterTime = that.stringToDate(item2.gtm)
  325. let second = afterTime - beforeTime
  326. if (second > that.parkingTime) {
  327. let message = '停车:' + second / 60000
  328. that.initParkingMarkes(
  329. 20,
  330. 35,
  331. require('@/assets/img/park.png'),
  332. calculationPoint.lon,
  333. calculationPoint.lat,
  334. message.split('.')[0] + '分钟'
  335. )
  336. }
  337. calculationPoint = null
  338. }
  339. }
  340. })
  341. },
  342. //字符串转为Date
  343. stringToDate(dateString) {
  344. console.log(dateString)
  345. let dateStr = dateString
  346. .replace('年', '-')
  347. .replace('月', '-')
  348. .replace('日', '')
  349. return Date.parse(dateStr)
  350. },
  351. //停车所有离线图标
  352. hideParkingMark() {
  353. let that = this
  354. that.parkMark.forEach(function(item, indexOf) {
  355. item.hide()
  356. })
  357. },
  358. //离线时间改变时获得超过时间的点信息
  359. changeLeaveTime() {
  360. let that = this
  361. //关闭所有图标
  362. that.hideLeaveMark()
  363. that.listPath[0].runRoute.forEach(function(item, indexOf) {
  364. if (indexOf + 1 < that.listPath[0].runRoute.length) {
  365. let beforeTime = that.stringToDate(item.gtm)
  366. let item2 = that.listPath[0].runRoute[indexOf + 1]
  367. let afterTime = that.stringToDate(item2.gtm)
  368. let second = afterTime - beforeTime
  369. if (second > that.leaveTime) {
  370. let message = '离线:' + second / 60000
  371. that.initLeaveMarkes(
  372. 20,
  373. 35,
  374. require('@/assets/img/leave.png'),
  375. item2.lon,
  376. item2.lat,
  377. message.split('.')[0] + '分钟'
  378. )
  379. }
  380. }
  381. })
  382. },
  383. //关闭所有离线图标
  384. hideLeaveMark() {
  385. let that = this
  386. that.leaveMark.forEach(function(item, indexOf) {
  387. item.hide()
  388. })
  389. },
  390. slow() {
  391. console.log('slow')
  392. let that = this
  393. that.pathNavigator.setSpeed(1000)
  394. },
  395. middle() {
  396. console.log('middle')
  397. let that = this
  398. that.pathNavigator.setSpeed(10000)
  399. },
  400. fast() {
  401. console.log('fast')
  402. let that = this
  403. that.pathNavigator.setSpeed(100000)
  404. },
  405. play() {
  406. let that = this
  407. that.pathNavigator.resume()
  408. },
  409. stop() {
  410. let that = this
  411. that.pathNavigator.pause()
  412. },
  413. addIndex() {
  414. let that = this
  415. let increment = that.listPath[0].runPath.length * 0.1
  416. let result = that.point + increment
  417. if (result < that.listPath[0].runPath.length) {
  418. that.pathNavigator.start(that.point + increment)
  419. } else {
  420. that.pathNavigator.start(that.listPath[0].runPath.length - 1)
  421. }
  422. },
  423. ///che
  424. navgControl() {},
  425. hideFormat(value) {
  426. let that = this
  427. that.sliderVal = value
  428. },
  429. initParkingMarkes(weight, height, image, lon, lat, title) {
  430. let that = this
  431. //图标标记点
  432. let pointicon = new AMap.Icon({
  433. size: new AMap.Size(weight, height), // 图标尺寸
  434. image: image, // Icon的图像
  435. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  436. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  437. })
  438. // 创建一个 Marker 实例:
  439. var pointmarker = new AMap.Marker({
  440. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  441. icon: pointicon,
  442. title: title
  443. })
  444. that.parkMark.push(pointmarker)
  445. // 将创建的点标记添加到已有的地图实例:
  446. that.map.add(pointmarker)
  447. },
  448. //创建离线和停车的标记
  449. initLeaveMarkes(weight, height, image, lon, lat, title) {
  450. let that = this
  451. //图标标记点
  452. let pointicon = new AMap.Icon({
  453. size: new AMap.Size(weight, height), // 图标尺寸
  454. image: image, // Icon的图像
  455. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  456. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  457. })
  458. // 创建一个 Marker 实例:
  459. var pointmarker = new AMap.Marker({
  460. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  461. icon: pointicon,
  462. title: title
  463. })
  464. that.leaveMark.push(pointmarker)
  465. // 将创建的点标记添加到已有的地图实例:
  466. that.map.add(pointmarker)
  467. },
  468. initData(orderNumber) {
  469. let that = this
  470. if (this.map) {
  471. this.map.destroy()
  472. }
  473. that.axios
  474. .post('/api/v1/otms/fullPath?orderNumber=' + orderNumber)
  475. .then(res => {
  476. console.log(res.data)
  477. if (res.data.data == '-1') {
  478. this.$message.error('运输订单未关闭的自提车辆无权查看!')
  479. } else if (res.data.data.startAndEndRoutes != null) {
  480. that.listPath = res.data.data.startAndEndRoutes
  481. that.startTime = res.data.data.startAndEndRoutes[0].runRoute[0].gtm
  482. that.endTime =
  483. res.data.data.startAndEndRoutes[0].runRoute[
  484. res.data.data.startAndEndRoutes[0].runRoute.length - 1
  485. ].gtm
  486. that.initMap()
  487. } else {
  488. that.listPath = []
  489. this.$message.error('车辆没有开启GPS')
  490. }
  491. })
  492. },
  493. endline() {
  494. let that = this
  495. that.initPolyline(that.listPath[0].estimatePath, '#FF0000')
  496. },
  497. //创建起点终点当前点
  498. threeMarker() {
  499. let that = this
  500. that.listPath.forEach((element, index) => {
  501. //开始标记点
  502. if (element.startPoint.lon != '' && element.startPoint.lat != '') {
  503. that.initMarkes(
  504. 20,
  505. 35,
  506. require('@/assets/img/start.png'),
  507. element.startPoint.lon,
  508. element.startPoint.lat,
  509. '起点'
  510. )
  511. }
  512. //当前点
  513. that.getCurrentPointName([
  514. element.runRoute[element.runRoute.length - 1].lon,
  515. element.runRoute[element.runRoute.length - 1].lat
  516. ])
  517. //结束标记点
  518. // if (element.endPoint.lon != '' && element.endPoint.lat != '') {
  519. // that.initMarkes(
  520. // 20,
  521. // 35,
  522. // require('@/assets/img/end.png'),
  523. // element.endPoint.lon,
  524. // element.endPoint.lat,
  525. // '终点'
  526. // )
  527. // }
  528. })
  529. },
  530. //获得结束地址
  531. getCurrentPointName(lnglatXY) {
  532. let that = this
  533. that.geocoder.getAddress(lnglatXY, function(status, result) {
  534. if (status === 'complete' && result.info === 'OK') {
  535. that.currentPointName = result.regeocode.formattedAddress
  536. let content =
  537. that.statusCode +
  538. ':' +
  539. that.currentPointName +
  540. '<br/>' +
  541. '距离:' +
  542. that.listPath[0].miled +
  543. '<br/>' +
  544. '时间范围:' +
  545. that.startTime +
  546. ' 至 ' +
  547. that.endTime
  548. if (
  549. getCookie('orgCode') != 'wuliuyunshubu' &&
  550. getCookie('orgCode') != 'shichangxinxibu' &&
  551. getCookie('orgCode') != 'caiwubu'
  552. ) {
  553. content =
  554. that.statusCode +
  555. ':' +
  556. that.currentPointName +
  557. '<br/>' +
  558. '时间范围:' +
  559. that.startTime +
  560. ' 至 ' +
  561. that.endTime
  562. }
  563. that.initCustomMarkes(
  564. that.capacityNumber,
  565. content,
  566. lnglatXY[0],
  567. lnglatXY[1]
  568. )
  569. }
  570. })
  571. },
  572. //defualt数据
  573. defaultDate() {
  574. // let that=this;
  575. // that.pathNavigator.start(that.listPath[0].runPath.length)
  576. // that.pathNavigator.pause();
  577. },
  578. //初始化地图
  579. initMap() {
  580. lazyAMapApiLoaderInstance.load().then(() => {
  581. let that = this
  582. that.map = new AMap.Map('amap-container', {
  583. //设置地图容器id
  584. viewMode: '2D', //是否为2D地图模式
  585. zoom: 10, //初始化地图级别
  586. center: [105.602725, 37.076636] //初始化地图中心点位置
  587. })
  588. that.initGeocoder()
  589. that.initPathSimplifier()
  590. that.threeMarker()
  591. //that.initCustomMarkes(that.capacityNumber+"("+that.listPath[0].miled+")",that.listPath[0].currentPointName,that.listPath[0].currentPoint.lon,that.listPath[0].currentPoint.lat)
  592. //that.endline()//预估路径
  593. })
  594. },
  595. initCustomMarkes(title, details, lon, lat) {
  596. let that = this
  597. //自定义窗体内容
  598. var content = [
  599. "<div style='top:1px;width: 200px; background-color: rgba(22, 160, 133, 1);' ><font color='white'>" +
  600. title +
  601. '</font>',
  602. "<div style='background-color:(22, 160, 133, 1); ;'><font color='white'>" +
  603. details +
  604. '</font></div></div>'
  605. ]
  606. // 创建 infoWindow 实例
  607. infoWindow = new AMap.InfoWindow({
  608. content: content.join('<br>') //传入 dom 对象,或者 html 字符串
  609. })
  610. // 打开信息窗体
  611. infoWindow.open(that.map, [lon, lat])
  612. },
  613. // 关闭信息窗口
  614. closeinfo() {
  615. infoWindow.close()
  616. },
  617. openInfo() {
  618. let lon = null
  619. let lat = null
  620. console.log(this.listPath)
  621. this.listPath.forEach(e => {
  622. if (e.endPoint != {} && e.endPoint != '' && e.endPoint != null) {
  623. lon = e.endPoint.lon
  624. lat = e.endPoint.lat
  625. } else {
  626. lon = e.runRoute[e.runRoute.length - 1].lon
  627. lat = e.runRoute[e.runRoute.length - 1].lat
  628. }
  629. })
  630. infoWindow.open(this.map, [lon, lat])
  631. },
  632. initPolyline(path, color) {
  633. let that = this
  634. //预计轨迹
  635. var endLine = new AMap.Polyline({
  636. map: that.map,
  637. path: path,
  638. isOutline: true,
  639. outlineColor: color,
  640. borderWeight: 0,
  641. strokeColor: '#FF0000',
  642. strokeOpacity: 1,
  643. strokeWeight: 5,
  644. // 折线样式还支持 'dashed'
  645. strokeStyle: 'solid',
  646. // strokeStyle是dashed时有效
  647. strokeDasharray: [10, 5],
  648. lineJoin: 'round',
  649. lineCap: 'round',
  650. zIndex: 50
  651. })
  652. that.map.setFitView([[endLine]])
  653. },
  654. //创建简单的标记
  655. initMarkes(weight, height, image, lon, lat, title) {
  656. let that = this
  657. //图标标记点
  658. let pointicon = new AMap.Icon({
  659. size: new AMap.Size(weight, height), // 图标尺寸
  660. image: image, // Icon的图像
  661. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  662. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  663. })
  664. // 创建一个 Marker 实例:
  665. var pointmarker = new AMap.Marker({
  666. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  667. icon: pointicon,
  668. title: title
  669. })
  670. // 将创建的点标记添加到已有的地图实例:
  671. that.map.add(pointmarker)
  672. },
  673. //创建轨迹和巡航器
  674. initPathSimplifier() {
  675. let that = this
  676. // ...你的操作
  677. new AMapUI.load(['ui/misc/PathSimplifier'], PathSimplifier => {
  678. if (!PathSimplifier.supportCanvas) {
  679. alert('当前环境不支持 Canvas!')
  680. return
  681. }
  682. //创建轨迹和巡航器
  683. // 创建组件实例
  684. that.pathSimplifierIns = new PathSimplifier({
  685. map: that.map,
  686. zIndex: 100, // 图层叠加顺序
  687. data: that.listPath, // 巡航路径
  688. // 获取巡航路径中的路径坐标数组
  689. getPath: (pathData, pathIndex) => {
  690. return pathData.runPath
  691. },
  692. //鼠标悬浮停时显示消息
  693. getHoverTitle: function(pathData, pathIndex, pointIndex) {
  694. //返回鼠标悬停时显示的信息
  695. if (pointIndex >= 0) {
  696. if (pathData.runRoute[pointIndex].gtm !== 'undefined') {
  697. //鼠标悬停在某个轨迹节点上
  698. return (
  699. pathData.runRoute[pointIndex].gtm +
  700. ',速度' +
  701. pathData.runRoute[pointIndex].spd +
  702. '千米/小时'
  703. )
  704. }
  705. }
  706. },
  707. //设置轨迹样式
  708. renderOptions: {
  709. //轨迹线的样式
  710. pathLineStyle: {
  711. strokeStyle: 'black',
  712. lineWidth: 6,
  713. dirArrowStyle: true
  714. }
  715. }
  716. })
  717. // 创建巡航器
  718. that.pathNavigator = that.pathSimplifierIns.createPathNavigator(0, {
  719. loop: false, // 是否循环
  720. speed: that.speed, // 速度(km/h)
  721. pathNavigatorStyle: {
  722. width: 20,
  723. height: 40,
  724. content: PathSimplifier.Render.Canvas.getImageContent(
  725. require('@/assets/img/smallcar.png'),
  726. onload,
  727. onerror
  728. ),
  729. strokeStyle: null,
  730. fillStyle: null
  731. }
  732. })
  733. //开启巡航
  734. that.pathNavigator.start()
  735. that.defaultDate()
  736. //开始事件
  737. that.pathNavigator.on('start resume', function() {
  738. // that.navgtr._startTime = Date.now();
  739. // that.navgtr._startDist = this.getMovedDistance();
  740. })
  741. //暂停
  742. that.pathNavigator.on('stop pause', function() {
  743. // that.navgtr._movedTime = Date.now() - that.navgtr._startTime;
  744. // that.navgtr._movedDist = this.getMovedDistance() - that.navgtr._startDist;
  745. })
  746. that.pathNavigator.on('move', function(data, value) {
  747. that.updateLable(value)
  748. })
  749. })
  750. },
  751. updateLable(value) {
  752. let that = this
  753. that.point = value.dataItem.pointIndex
  754. that.runRoute = value.dataItem.pathData.runRoute[that.point]
  755. that.sliderVal =
  756. (value.dataItem.pointIndex / value.dataItem.pathData.runRoute.length) *
  757. 100
  758. },
  759. changeSpeed(value) {
  760. // console.log(value)
  761. // let that=this;
  762. // that.times=value;
  763. },
  764. playIcon() {
  765. console.log('nihoa')
  766. },
  767. //逆解码函数
  768. initGeocoder() {
  769. let that = this
  770. console.log('initGeocoder')
  771. AMap.plugin('AMap.Geocoder', function() {
  772. that.geocoder = new AMap.Geocoder({
  773. radius: 1000,
  774. extensions: 'all'
  775. })
  776. console.log(that.geocoder)
  777. })
  778. }
  779. }
  780. }
  781. </script>
  782. <style>
  783. .mapcontroller {
  784. width: 250px;
  785. height: 260px;
  786. background: white;
  787. position: absolute;
  788. z-index: 99;
  789. top: 0;
  790. left: 0;
  791. }
  792. .container {
  793. width: 100%;
  794. height: 100%;
  795. }
  796. .item_details {
  797. display: block;
  798. margin-top: 20px;
  799. position: relative;
  800. left: 30px;
  801. width: 200px;
  802. height: 0px;
  803. }
  804. #amap-container {
  805. position: relative;
  806. width: 100%;
  807. height: 100%;
  808. overflow: hidden;
  809. margin: 0;
  810. font-family: '微软雅黑';
  811. }
  812. .driving_information2 {
  813. position: relative;
  814. top: 70px;
  815. }
  816. .driving_information3 {
  817. position: absolute;
  818. z-index: 99;
  819. top: 0;
  820. left: 0;
  821. position: relative;
  822. top: 50px;
  823. }
  824. /* 进度条 */
  825. .mySlider {
  826. width: 150px;
  827. height: 20px;
  828. display: inline-block;
  829. position: relative;
  830. left: 32px;
  831. }
  832. .play {
  833. position: relative;
  834. left: 28px;
  835. }
  836. .quickly {
  837. float: right;
  838. position: relative;
  839. left: -20px;
  840. top: 10px;
  841. }
  842. .pause {
  843. position: relative;
  844. left: 28px;
  845. }
  846. .passed-time {
  847. position: relative;
  848. left: 5px;
  849. }
  850. .end-time {
  851. position: relative;
  852. left: 5px;
  853. }
  854. .map-times {
  855. position: relative;
  856. background-color: red;
  857. width: 40px;
  858. }
  859. </style>
  860. <style lang="scss" scoped>
  861. .btnx {
  862. z-index: 1000;
  863. position: fixed;
  864. bottom: 10px;
  865. right: 10px;
  866. }
  867. </style>