checkGPS.vue 30 KB

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