checkGPS.vue 29 KB

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