gpsRouteDialog.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <el-dialog
  3. @closed="closedDialog"
  4. :visible.sync="dialog"
  5. append-to-body
  6. direction="rtl"
  7. :fullscreen=true
  8. >
  9. <baidu-map class="bm-view" :center="center" :zoom="zoom" @ready="init"
  10. v-loading="loading"
  11. element-loading-text="数据加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. >
  15. <bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-map-type>
  16. <bm-control :offset="searchControlOffset">
  17. <div id="searchbox">
  18. <div id="searchbox-container">
  19. <div id="sole-searchbox-content" class="searchbox-content">
  20. <el-date-picker
  21. v-model="timeRange"
  22. type="datetimerange"
  23. :picker-options="pickerOptions"
  24. range-separator="至"
  25. start-placeholder="开始日期"
  26. end-placeholder="结束日期"
  27. align="right">
  28. </el-date-picker>
  29. </div>
  30. </div>
  31. <el-button type="info" id="search-button" @click="queryStudentRoute" >搜索</el-button>
  32. </div>
  33. </bm-control>
  34. <bm-control anchor="BMAP_ANCHOR_TOP_RIGHT" :offset="listControlOffset">
  35. <div id="route-container">
  36. <el-table
  37. class="ontop-route-table"
  38. ref="singleTable"
  39. :data="Routedata"
  40. height="480"
  41. highlight-current-row
  42. @row-click="clickStudentRow"
  43. @current-change="handleCurrentChange"
  44. style="width: 100%">
  45. <el-table-column
  46. type="index"
  47. width="40"
  48. align="center">
  49. </el-table-column>
  50. <el-table-column label="定位列表" >
  51. <template slot-scope="record">
  52. <div>
  53. {{record.row.PassTime}}&nbsp;&nbsp;<i v-if="record.row.WifiAddress" class="wifi_icon">W</i><i v-else class="gps_icon">G</i><br/>
  54. <div v-if="record.row.WifiAddress"> {{record.row.WifiAddress}}</div>
  55. <div v-else> {{record.row.Address}}</div>
  56. </div>
  57. </template>
  58. </el-table-column>
  59. </el-table>
  60. </div>
  61. </bm-control>
  62. </baidu-map>
  63. </el-dialog>
  64. </template>
  65. <script>
  66. export default {
  67. props: ["displayVisible","activeRfid"],
  68. data() {
  69. return {
  70. loading: false,
  71. dialog: false,
  72. title:'轨迹地图',
  73. Routedata:[
  74. {
  75. PassTime:'2022-05-25 15:11:11',
  76. Address:'浙江省杭州市滨江区华城和瑞科技广场',
  77. Latitude:30.192001,
  78. Longitude:120.20121,
  79. },
  80. {
  81. PassTime:'2022-05-25 15:11:11',
  82. Address:'浙江省杭州市滨江区滨安路跟江虹路交叉口',
  83. Latitude:30.192797,
  84. Longitude:120.207067,
  85. },
  86. {
  87. PassTime:'2022-05-24 15:11:11',
  88. Address:'浙江省杭州市滨江区江虹小区东门',
  89. Latitude:30.202219,
  90. Longitude:120.208827,
  91. },
  92. ],
  93. map: null,
  94. center: '杭州市滨江区',
  95. zoom: 19,
  96. searchControlOffset:{},
  97. listControlOffset:{},
  98. route_type:'All',
  99. filterTrack:false,
  100. markerIcons: 'https://rlfd.oss-cn-hangzhou.aliyuncs.com/smart_tool/beng.png',
  101. pickerOptions: {
  102. shortcuts: [
  103. {
  104. text: '3小时内',
  105. onClick(picker) {
  106. const end = new Date();
  107. const start = new Date();
  108. start.setTime(start.getTime() - 3600 * 1000 * 3);
  109. picker.$emit('pick', [start, end]);
  110. }
  111. }, {
  112. text: '6小时内',
  113. onClick(picker) {
  114. const end = new Date();
  115. const start = new Date();
  116. start.setTime(start.getTime() - 3600 * 1000 * 6);
  117. picker.$emit('pick', [start, end]);
  118. }
  119. }, {
  120. text: '12小时内',
  121. onClick(picker) {
  122. const end = new Date();
  123. const start = new Date();
  124. start.setTime(start.getTime() - 3600 * 1000 * 12);
  125. picker.$emit('pick', [start, end]);
  126. }
  127. }, {
  128. text: '24小时内',
  129. onClick(picker) {
  130. const end = new Date();
  131. const start = new Date();
  132. start.setTime(start.getTime() - 3600 * 1000 * 24);
  133. picker.$emit('pick', [start, end]);
  134. }
  135. }, {
  136. text: '2天内',
  137. onClick(picker) {
  138. const end = new Date();
  139. const start = new Date();
  140. start.setTime(start.getTime() - 3600 * 1000 * 24 * 2);
  141. picker.$emit('pick', [start, end]);
  142. }
  143. }, {
  144. text: '3天内',
  145. onClick(picker) {
  146. const end = new Date();
  147. const start = new Date();
  148. start.setTime(start.getTime() - 3600 * 1000 * 24 * 3);
  149. picker.$emit('pick', [start, end]);
  150. }
  151. }]
  152. },
  153. timeRange: [new Date(new Date().toLocaleDateString()), new Date(new Date(new Date().toLocaleDateString()).getTime() + (24 * 60 * 60 * 1000)-1000)],
  154. trackMarkers:[],
  155. currentRow: null,
  156. };
  157. },
  158. mounted(){
  159. this.dialog = this.displayVisible;
  160. this.$nextTick(() => {
  161. // const query = { device_number: this.activeRfid}
  162. // this.$http.get('map/queryDeviceCurLocation',{ params: query }).then(res=>{
  163. // let pointInfo=res.data
  164. // var trackPoint = new BMap.Point(pointInfo.longitude, pointInfo.latitude);
  165. // let pointType = "terminus";
  166. // var pointIcon = new BMap.Icon(this.markerIcons[pointType], new BMap.Size(27, 32));
  167. // pointIcon.iconAnchor = new BMap.Point(5, 5);
  168. // pointIcon.shadow = "";
  169. // let trackMarker = new BMap.Marker(trackPoint, { icon: pointIcon });
  170. // this.map.addOverlay(trackMarker);
  171. // this.center=trackPoint
  172. // //this.map.centerAndZoom(trackPoint, 19);
  173. // this.queryStudentRoute();
  174. // }).catch(e => {
  175. // // this.loading = false;
  176. // });
  177. let topTables = document.getElementsByClassName('ontop-route-table');
  178. topTables.forEach(item => {
  179. item.onwheel = function(e) {
  180. e.stopPropagation();
  181. }
  182. })
  183. })
  184. },
  185. methods: {
  186. init({ BMap, map }) {
  187. this.map = map;
  188. // 初始化地图,设置中心点坐标
  189. // map.centerAndZoom("杭州市滨江区", 15);
  190. this.searchControlOffset=new BMap.Size(20, 20)
  191. this.listControlOffset=new BMap.Size(20, 40)
  192. // 添加鼠标滚动缩放
  193. map.enableScrollWheelZoom();
  194. //临时写的
  195. this.queryStudentRoute()
  196. },
  197. queryStudentRoute(){
  198. let that=this
  199. this.loading = true;
  200. setTimeout(function(){
  201. that.DrawMapLine(that.Routedata);
  202. that.loading = false;
  203. }, 2000);
  204. // const query = { active_rfid: this.activeRfid,time_range:this.timeRange,route_type:this.route_type,filter_track:this.filterTrack,}
  205. // this.$http.get('map/queryStudentRouteGps',{ params: query,timeout:60000}).then(res=>{
  206. // this.map.clearOverlays()
  207. // let data=[]
  208. // let trackLength=res.data.length
  209. // if(trackLength>0){
  210. // for (var i = 0; i < trackLength; i++){
  211. // let item=res.data[i]
  212. // // var myGeo = new BMap.Geocoder();
  213. // // // 根据坐标得到地址描述
  214. // // myGeo.getLocation(new BMap.Point(item.Longitude,item.Latitude), function(result){
  215. // // item['Address']=result.address
  216. // // });
  217. // // data.push(item)
  218. // item['index']=i
  219. // data[i]=item
  220. // }
  221. // this.DrawMapLine(data)
  222. // }
  223. // this.Routedata=data
  224. // this.loading = false;
  225. // })
  226. // .catch(e => {
  227. // this.loading = false;
  228. // });
  229. },
  230. DrawMapLine(data){
  231. var pointType = "node";//点类型
  232. var pointLogLat = new BMap.Point(data[0].Longitude, data[0].Latitude);//终点
  233. var trackCount=data.length
  234. // this.center=pointLogLat
  235. this.map.centerAndZoom(pointLogLat, 19);
  236. var onLineCoordinates = [];
  237. for (var i = trackCount-1; i >= 0; i--)
  238. {
  239. //线上的点
  240. pointLogLat = new BMap.Point(data[i].Longitude, data[i].Latitude);
  241. onLineCoordinates.push(pointLogLat);
  242. var pointMarker = this.CreatePointMarkers(data[i]);
  243. this.trackMarkers.push(pointMarker);
  244. }
  245. var sy = new BMap.Symbol(BMap_Symbol_SHAPE_BACKWARD_OPEN_ARROW, {
  246. scale: 0.6,//图标缩放大小
  247. strokeColor:'#fff',//设置矢量图标的线填充颜色
  248. strokeWeight: '2',//设置线宽
  249. });
  250. var icons = new BMap.IconSequence(sy, '10', '30');
  251. //画线
  252. // var polyline = new BMap.Polyline(onLineCoordinates,{
  253. // enableEditing: false,//是否启用线编辑,默认为false
  254. // enableClicking: true,//是否响应点击事件,默认为true
  255. // icons:[icons],
  256. // strokeWeight:'4',//折线的宽度,以像素为单位
  257. // strokeOpacity: 0.8,//折线的透明度,取值范围0 - 1
  258. // strokeColor:"blue" //折线颜色
  259. // });
  260. // this.map.addOverlay(polyline);
  261. //最佳视野
  262. this.map.setViewport(onLineCoordinates);
  263. },
  264. CreatePointMarkers(pointInfo)
  265. {
  266. // console.log(pType)
  267. var _this=this
  268. var trackMarker;
  269. var trackPoint = new BMap.Point(pointInfo.Longitude, pointInfo.Latitude);
  270. var pointIcon = new BMap.Icon(this.markerIcons, new BMap.Size(32, 32));
  271. pointIcon.setImageSize(new BMap.Size(32, 32));
  272. // var pointIcon = new BMap.Icon(this.markerIcons[pType], new BMap.Size(27, 32));
  273. //描点,创建标注
  274. pointIcon.iconAnchor = new BMap.Point(5, 5);
  275. pointIcon.shadow = "";
  276. trackMarker = new BMap.Marker(trackPoint, { icon: pointIcon });
  277. trackMarker.addEventListener("click", function ()
  278. {
  279. // if(pointInfo.SignalType=='WiFi'){
  280. var content ='<p>经过时间:' + pointInfo.PassTime + '</p><p>地址:' + pointInfo.WifiAddress + '</p>'
  281. var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
  282. _this.map.centerAndZoom(trackPoint, 19);
  283. _this.map.openInfoWindow(infoWindow,trackPoint);
  284. // }else{
  285. // var myGeo = new BMap.Geocoder();
  286. // // 根据坐标得到地址描述
  287. // myGeo.getLocation(new BMap.Point(pointInfo.Longitude,pointInfo.Latitude), function(result){
  288. // let index=pointInfo['index']
  289. // pointInfo['Address']=result.address
  290. // _this.Routedata[index]=pointInfo
  291. // var trackPoint = new BMap.Point(pointInfo.Longitude, pointInfo.Latitude);
  292. // var content ='<p>经过时间:' + pointInfo.PassTime + '</p><p>地址:' + pointInfo.Address + '</p>'
  293. // var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
  294. // _this.map.centerAndZoom(trackPoint, 19);
  295. // _this.map.openInfoWindow(infoWindow,trackPoint);
  296. // });
  297. // // var content ='<p>经过时间:' + pointInfo.PassTime + '</p><p>地址:' + pointInfo.Address + '</p><p>定位类型:' + pointInfo.SignalType + '</p>'
  298. // }
  299. });
  300. this.map.addOverlay(trackMarker);
  301. return trackMarker;
  302. },
  303. clickStudentRow(row, column, event){
  304. let that=this
  305. let index=row['index']
  306. let item=row
  307. // if(row['WifiAddress']){
  308. item['Address']=row['Address']
  309. that.Routedata[index]=item
  310. var trackPoint = new BMap.Point(row['Longitude'], row['Latitude']);
  311. var content ='<p>经过时间:' + item.PassTime + '</p><p>地址:' + item.Address + '</p>'
  312. var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
  313. that.map.centerAndZoom(trackPoint, 19);
  314. // that.map.panTo(trackPoint)
  315. that.map.openInfoWindow(infoWindow,trackPoint);
  316. // }else{
  317. // var myGeo = new BMap.Geocoder();
  318. // // 根据坐标得到地址描述
  319. // myGeo.getLocation(new BMap.Point(item.Longitude,item.Latitude), function(result){
  320. // item['Address']=result.address
  321. // that.Routedata[index]=item
  322. // var trackPoint = new BMap.Point(item.Longitude, item.Latitude);
  323. // var content ='<p>经过时间:' + item.PassTime + '</p><p>地址:' + item.Address + '</p>'
  324. // var infoWindow = new BMap.InfoWindow(content); // 创建信息窗口对象
  325. // that.map.centerAndZoom(trackPoint, 19);
  326. // // that.map.panTo(trackPoint)
  327. // that.map.openInfoWindow(infoWindow,trackPoint);
  328. // });
  329. // }
  330. },
  331. handleCurrentChange(val) {
  332. this.currentRow = val;
  333. },
  334. closedDialog() {
  335. // this.dialog = false;
  336. this.$emit("formCancel");
  337. }
  338. }
  339. };
  340. </script>
  341. <style>
  342. .el-select-dropdown{
  343. z-index:9999 !important;
  344. }
  345. </style>
  346. <style lang="scss" scoped>
  347. .el-drawer span:focus {
  348. outline: none;
  349. }
  350. .bm-view {
  351. width: 100%;
  352. height: calc(100vh - 40px);
  353. margin-top:10px;
  354. }
  355. #route-container{
  356. width:280px;
  357. height: 500px;
  358. background-color: #fafafa;
  359. }
  360. #searchbox {
  361. border-radius: 2px;
  362. width: 464px;
  363. position: relative;
  364. z-index: 5;
  365. display: flex;
  366. }
  367. #searchbox #searchbox-container {
  368. display: flex;
  369. position: relative;
  370. z-index: 2;
  371. pointer-events: auto;
  372. width: 400px;
  373. float: left;
  374. box-sizing: border-box;
  375. }
  376. #sole-searchbox-content {
  377. position: relative;
  378. }
  379. .searchbox-content {
  380. width: 400px;
  381. border-bottom:none !important;
  382. border-radius: 2px 0 0 2px;
  383. background: #fff;
  384. }
  385. #sole-searchbox-content #sole-input,
  386. #searchType {
  387. box-sizing: border-box;
  388. border: 0;
  389. padding: 9px 0;
  390. border-left: 10px solid transparent;
  391. border-right: 10px solid transparent;
  392. line-height: 20px;
  393. font-size: 14px;
  394. height: 38px;
  395. color: #333;
  396. position: relative;
  397. border-radius: 2px 0 0 2px;
  398. }
  399. #sole-input {
  400. width: 250px;
  401. }
  402. #sole-input:focus {
  403. outline: none;
  404. }
  405. #search-button{
  406. border-top-left-radius:0px !important;
  407. border-bottom-left-radius:0px !important;
  408. }
  409. .wifi_icon{
  410. display:inline-block;
  411. width:18px;
  412. height:18px;
  413. border-radius:9px;
  414. background:#1296db;
  415. color:#FFF;
  416. text-align:center;
  417. line-height:18px;
  418. }
  419. .gps_icon{
  420. display:inline-block;
  421. width:18px;
  422. height:18px;
  423. border-radius:9px;
  424. background:#1afa29;
  425. color:#FFF;
  426. text-align:center;
  427. line-height:18px;
  428. }
  429. </style>