checkGPS.vue 27 KB

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