checkGPS.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  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({
  485. message:"车牌号不能为空!",
  486. offset:40,
  487. type:"warning",
  488. showClose:true
  489. });
  490. return;
  491. }
  492. if (that.time == null && that.time.length != 2) {
  493. this.$message.error("请选择时间");
  494. return;
  495. }
  496. if (that.time != null && that.time.length == 2) {
  497. if (that.time[1].getTime() - that.time[0].getTime() > 86400000 * 3) {
  498. this.$message.error("时间查询范围不能超过3天");
  499. // that.time = [];
  500. return;
  501. } else if (that.time[1].getTime() < that.time[0].getTime()) {
  502. this.$message.error("开始时间要大于结束时间,请重新选择!");
  503. // that.time = [];
  504. return;
  505. }
  506. }
  507. that.axios
  508. .post("/api/v1/otms/fullPathVisualizationByCarNumber", {
  509. capacityNumber: that.carNumber,
  510. startTime: that.formatDate(that.time[0], "yyyy-MM-dd hh:mm:ss"),
  511. endTime: that.formatDate(that.time[1], "yyyy-MM-dd hh:mm:ss")
  512. })
  513. .then(res => {
  514. if (res.data.data == "-1") {
  515. this.$message.error("运输订单未关闭,自提车辆无权查看!");
  516. } else if (res.data.data.startAndEndRoutes) {
  517. console.log("res.data.data:",res.data.data);
  518. that.listPath = res.data.data.startAndEndRoutes;
  519. that.initMap([105.602725, 37.076636]);
  520. } else {
  521. this.$message({
  522. message:"车辆没有开启GPS或尚未注册!",
  523. offset:40,
  524. type:"warning",
  525. showClose:true
  526. });
  527. }
  528. });
  529. },
  530. //初始化地图
  531. initMap(lonlat) {
  532. lazyAMapApiLoaderInstance.load().then(() => {
  533. let that = this;
  534. that.map = new AMap.Map("amap-container", {
  535. //设置地图容器id
  536. viewMode: "2D", //是否为2D地图模式
  537. zoom: 10, //初始化地图级别
  538. center: lonlat //初始化地图中心点位置
  539. });
  540. //初始化
  541. that.initGeocoder();
  542. //初始化巡航轨迹和巡航器
  543. that.initPathSimplifier();
  544. //初始化起点、当前点、当前点
  545. that.initThreeMarker();
  546. //初始化当前点标记
  547. //that.initCustomMarkes(that.carNumber+"("+that.listPath[0].miled+")",that.listPath[0].currentPointName,that.listPath[0].currentPoint.lon,that.listPath[0].currentPoint.lat)
  548. that.initEndline();
  549. });
  550. },
  551. //结束点
  552. initEndline() {
  553. let that = this;
  554. that.initPolyline(that.listPath[0].estimatePath, "#FF0000");
  555. },
  556. //创建起点终点当前点
  557. initThreeMarker() {
  558. let that = this;
  559. that.listPath.forEach((element, index) => {
  560. //起点名称
  561. that.getStartPointName([
  562. element.runRoute[0].lon,
  563. element.runRoute[0].lat
  564. ]);
  565. //开始标记点
  566. if (element.startPoint.lon != "" && element.startPoint.lat != "") {
  567. that.initMarkes(
  568. 20,
  569. 35,
  570. require("@/assets/img/start.png"),
  571. element.startPoint.lon,
  572. element.startPoint.lat,
  573. "起点"
  574. );
  575. }
  576. //结束标记点
  577. if (
  578. element.endPoint != {} &&
  579. element.endPoint != "" &&
  580. element.endPoint != null
  581. ) {
  582. that.initMarkes(20,35,require('@/assets/img/end.png'),element.endPoint.lon,element.endPoint.lat,'终点');
  583. //终点名称
  584. that.getEndPointName([element.endPoint.lon, element.endPoint.lat]);
  585. } else {
  586. that.initMarkes(20,35,require('@/assets/img/end.png'),element.runRoute[element.runRoute.length-1].lon,element.runRoute[element.runRoute.length-1].lat,'终点');
  587. //终点名称
  588. that.getEndPointName([
  589. element.runRoute[element.runRoute.length - 1].lon,
  590. element.runRoute[element.runRoute.length - 1].lat
  591. ]);
  592. }
  593. });
  594. },
  595. //初始化窗体
  596. initCustomMarkes(title, details, lon, lat) {
  597. let that = this;
  598. //自定义窗体内容
  599. var content = [
  600. "<div style='top:1px;width: 200px; background-color: rgba(22, 160, 133, 1);' ><font color='white'>" +
  601. title +
  602. "</font>",
  603. "<div style='background-color:rgba(22, 160, 133, 1);'><font color='white'>" +
  604. details +
  605. "</font></div></div>"
  606. ];
  607. // 创建 infoWindow 实例
  608. infoWindow = new AMap.InfoWindow({
  609. content: content.join("<br>") //传入 dom 对象,或者 html 字符串
  610. });
  611. // 打开信息窗体
  612. infoWindow.open(that.map, [lon, lat]);
  613. },
  614. //初始化预计轨迹
  615. initPolyline(path, color) {
  616. let that = this;
  617. console.log("path:",path);
  618. //预计轨迹
  619. var endLine = new AMap.Polyline({
  620. map: that.map, //地图组件
  621. path: path, //预计轨迹
  622. isOutline: true,
  623. outlineColor: color, //轨迹颜色
  624. borderWeight: 0,
  625. strokeColor: "#FF0000",
  626. strokeOpacity: 1,
  627. strokeWeight: 5,
  628. // 折线样式还支持 'dashed'
  629. strokeStyle: "solid",
  630. // strokeStyle是dashed时有效
  631. strokeDasharray: [10, 5],
  632. lineJoin: "round",
  633. lineCap: "round",
  634. zIndex: 50
  635. });
  636. that.map.setFitView([[endLine]]);
  637. },
  638. initParkingMarkes(weight, height, image, lon, lat, title) {
  639. let that = this;
  640. //图标标记点
  641. let pointicon = new AMap.Icon({
  642. size: new AMap.Size(weight, height), // 图标尺寸
  643. image: image, // Icon的图像
  644. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  645. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  646. });
  647. // 创建一个 Marker 实例:
  648. var pointmarker = new AMap.Marker({
  649. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  650. icon: pointicon,
  651. title: title
  652. });
  653. that.parkMark.push(pointmarker);
  654. // 将创建的点标记添加到已有的地图实例:
  655. that.map.add(pointmarker);
  656. },
  657. //创建离线和停车的标记
  658. initLeaveMarkes(weight, height, image, lon, lat, title) {
  659. let that = this;
  660. //图标标记点
  661. let pointicon = new AMap.Icon({
  662. size: new AMap.Size(weight, height), // 图标尺寸
  663. image: image, // Icon的图像
  664. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  665. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  666. });
  667. // 创建一个 Marker 实例:
  668. var pointmarker = new AMap.Marker({
  669. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  670. icon: pointicon,
  671. title: title
  672. });
  673. that.leaveMark.push(pointmarker);
  674. // 将创建的点标记添加到已有的地图实例:
  675. that.map.add(pointmarker);
  676. },
  677. //创建简单的标记
  678. initMarkes(weight, height, image, lon, lat, title) {
  679. let that = this;
  680. //图标标记点
  681. let pointicon = new AMap.Icon({
  682. size: new AMap.Size(weight, height), // 图标尺寸
  683. image: image, // Icon的图像
  684. imageOffset: new AMap.Pixel(0, 0), // 图像相对展示区域的偏移量,适于雪碧图等
  685. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  686. });
  687. // 创建一个 Marker 实例:
  688. var pointmarker = new AMap.Marker({
  689. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  690. icon: pointicon,
  691. title: title
  692. });
  693. // 将创建的点标记添加到已有的地图实例:
  694. that.map.add(pointmarker);
  695. },
  696. //创建轨迹和巡航器
  697. initPathSimplifier() {
  698. let that = this;
  699. // ...你的操作
  700. new AMapUI.load(["ui/misc/PathSimplifier"], PathSimplifier => {
  701. if (!PathSimplifier.supportCanvas) {
  702. alert("当前环境不支持 Canvas!");
  703. return;
  704. }
  705. //创建轨迹和巡航器
  706. // 创建组件实例
  707. that.pathSimplifierIns = new PathSimplifier({
  708. map: that.map,
  709. zIndex: 100, // 图层叠加顺序
  710. data: that.listPath, // 巡航路径
  711. // 获取巡航路径中的路径坐标数组
  712. getPath: (pathData, pathIndex) => {
  713. return pathData.runPath;
  714. },
  715. //鼠标悬浮停时显示消息
  716. getHoverTitle: function(pathData, pathIndex, pointIndex) {
  717. //返回鼠标悬停时显示的信息
  718. if (pointIndex >= 0) {
  719. if (pathData.runRoute[pointIndex].gtm !== "undefined") {
  720. //鼠标悬停在某个轨迹节点上
  721. return (
  722. pathData.runRoute[pointIndex].gtm +
  723. ",速度" +
  724. pathData.runRoute[pointIndex].spd +
  725. "千米/小时"
  726. );
  727. }
  728. }
  729. },
  730. //设置轨迹样式
  731. renderOptions: {
  732. //轨迹线的样式
  733. pathLineStyle: {
  734. strokeStyle: "black", //路径颜色
  735. lineWidth: 6,
  736. dirArrowStyle: true
  737. }
  738. }
  739. });
  740. // 创建巡航器
  741. that.pathNavigator = that.pathSimplifierIns.createPathNavigator(0, {
  742. loop: true, // 是否循环
  743. speed: that.speed, // 速度(km/h)
  744. pathNavigatorStyle: {
  745. width: 20, //车辆图片宽度
  746. height: 40, //车辆图片高度
  747. content: PathSimplifier.Render.Canvas.getImageContent(
  748. require("@/assets/img/smallcar.png"),
  749. onload,
  750. onerror
  751. ), //车辆图片
  752. strokeStyle: null,
  753. fillStyle: null
  754. }
  755. });
  756. //开启巡航
  757. that.pathNavigator.start();
  758. //开始事件监听
  759. that.pathNavigator.on("start resume", function() {});
  760. //暂停事件监听
  761. that.pathNavigator.on("stop pause", function() {});
  762. //移动事件监听
  763. that.pathNavigator.on("move", function(data, value) {
  764. that.updateLable(value);
  765. });
  766. });
  767. },
  768. //实时展示
  769. updateLable(value) {
  770. let that = this;
  771. that.point = value.dataItem.pointIndex;
  772. that.runRoute = value.dataItem.pathData.runRoute[that.point];
  773. that.sliderVal =
  774. (value.dataItem.pointIndex / value.dataItem.pathData.runRoute.length) *
  775. 100;
  776. },
  777. //逆解码函数
  778. initGeocoder() {
  779. let that = this;
  780. console.log("initGeocoder");
  781. AMap.plugin("AMap.Geocoder", function() {
  782. that.geocoder = new AMap.Geocoder({
  783. radius: 1000,
  784. extensions: "all"
  785. });
  786. console.log(that.geocoder);
  787. });
  788. },
  789. // 关闭信息窗口
  790. closeinfo() {
  791. infoWindow.close();
  792. },
  793. openInfo() {
  794. let lon = null;
  795. let lat = null;
  796. this.listPath.forEach(e => {
  797. if (e.endPoint != {} && e.endPoint != "" && e.endPoint != null) {
  798. lon = e.endPoint.lon;
  799. lat = e.endPoint.lat;
  800. } else {
  801. lon = e.runRoute[e.runRoute.length - 1].lon;
  802. lat = e.runRoute[e.runRoute.length - 1].lat;
  803. }
  804. });
  805. infoWindow.open(this.map, [lon, lat]);
  806. },
  807. //时间格式转换
  808. formatDate(date, fmt) {
  809. if (/(y+)/.test(fmt)) {
  810. fmt = fmt.replace(
  811. RegExp.$1,
  812. (date.getFullYear() + "").substr(4 - RegExp.$1.length)
  813. );
  814. }
  815. let o = {
  816. "M+": date.getMonth() + 1,
  817. "d+": date.getDate(),
  818. "h+": date.getHours(),
  819. "m+": date.getMinutes(),
  820. "s+": date.getSeconds()
  821. };
  822. for (let k in o) {
  823. if (new RegExp(`(${k})`).test(fmt)) {
  824. let str = o[k] + "";
  825. fmt = fmt.replace(
  826. RegExp.$1,
  827. RegExp.$1.length === 1 ? str : ("00" + str).substr(str.length)
  828. );
  829. }
  830. }
  831. return fmt;
  832. }
  833. }
  834. };
  835. </script>
  836. <style>
  837. .inputStyle {
  838. position: absolute;
  839. width: 200px;
  840. left: 50px;
  841. }
  842. .controller {
  843. width: 100%;
  844. height: 70px;
  845. background: white;
  846. position: absolute;
  847. z-index: 99;
  848. top: 0;
  849. left: 0;
  850. }
  851. .in_transit_information {
  852. width: 220px;
  853. float: left;
  854. height: 40px;
  855. }
  856. .in_transit_information3 {
  857. float: right;
  858. height: 40px;
  859. width: 180px;
  860. }
  861. .in_transit_information2 {
  862. height: 40px;
  863. float: left;
  864. width: 580px;
  865. }
  866. .container {
  867. width: 100%;
  868. height: 100%;
  869. }
  870. span.item_details2 {
  871. position: relative;
  872. top: 20px;
  873. }
  874. .date_picker_style {
  875. position: relative;
  876. left: 50px;
  877. }
  878. .item_details {
  879. position: relative;
  880. top: 5px;
  881. height: 0px;
  882. left: 0px;
  883. }
  884. #amap-container {
  885. position: relative;
  886. width: 100%;
  887. height: 100%;
  888. overflow: hidden;
  889. margin: 0;
  890. font-family: "微软雅黑";
  891. }
  892. /* 进度条 */
  893. .mySlider {
  894. width: 150px;
  895. height: 20px;
  896. display: inline-block;
  897. position: relative;
  898. left: 32px;
  899. }
  900. /* 进度条 */
  901. .mySlider2 {
  902. width: 400px;
  903. height: 20px;
  904. display: inline-block;
  905. position: relative;
  906. left: 32px;
  907. }
  908. .play {
  909. position: relative;
  910. left: 28px;
  911. }
  912. .quickly {
  913. float: right;
  914. position: relative;
  915. left: -20px;
  916. top: 10px;
  917. }
  918. .pause {
  919. position: relative;
  920. left: 28px;
  921. }
  922. .passed-time {
  923. position: relative;
  924. left: 5px;
  925. }
  926. .end-time {
  927. position: relative;
  928. left: 5px;
  929. }
  930. .map-times {
  931. position: relative;
  932. width: 40px;
  933. }
  934. .searchstyle {
  935. position: relative;
  936. left: 5px;
  937. }
  938. .map-control {
  939. float: left;
  940. width: 270px;
  941. }
  942. .driving_information {
  943. height: 40px;
  944. width: 240px;
  945. float: left;
  946. }
  947. </style>
  948. <style lang="scss" scoped>
  949. .btnx {
  950. z-index: 1000;
  951. position: fixed;
  952. bottom: 10px;
  953. right: 10px;
  954. }
  955. </style>