checkGPS.vue 25 KB

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