currentLocation.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div class="container">
  3. <div id="amap-container"></div>
  4. <div class="controller">
  5. <div class="in_transit_information">
  6. <span class="item_details">车牌号:</span>
  7. <el-input style="width: 120px;" class="inputStyle" v-model.trim="carNumber"> </el-input>
  8. <el-button type="primary" class="searchstyle" @click="initData">查询</el-button>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import { shallowRef } from "@vue/reactivity";
  15. import { lazyAMapApiLoaderInstance } from "vue-amap";
  16. import { sjTime, stringToDate } from "@/utils/sharedJsFile";
  17. import Slider from "./slider.vue";
  18. Vue.use(Slider);
  19. import Vue from "vue";
  20. export default {
  21. name: "PathView",
  22. setup() {
  23. const map = shallowRef(null);
  24. return {
  25. map
  26. };
  27. },
  28. watch: {
  29. speedVal: {
  30. deep: true,
  31. handler(val, oldVal) {
  32. let that = this;
  33. if (that.pathNavigator != null) {
  34. that.pathNavigator.setSpeed(100 * val);
  35. }
  36. }
  37. }
  38. },
  39. data() {
  40. return {
  41. //查询车牌号
  42. carNumber: "",
  43. //地图组件
  44. map:null,
  45. };
  46. },
  47. created() {
  48. let that =this;
  49. that.initMap(105.602725,37.076636)
  50. },
  51. mounted() {},
  52. methods: {
  53. //初始化数据
  54. initData() {
  55. let that = this;
  56. if (that.carNumber == "") {
  57. this.$message.error("车牌号不能为空!");
  58. return;
  59. }
  60. that.axios
  61. .get("/api/v1/otms/getCurrentLocation?capcityNumber="+that.carNumber)
  62. .then(res => {
  63. console.log(res.data.data)
  64. if(res.data.data=='-1'){
  65. this.$message.error('自提车辆无权查看!');
  66. }else if(res.data.data.status!='1006'){
  67. console.log("res.data.data.status")
  68. that.map.setCenter([res.data.data.result.lon,res.data.data.result.lat]);
  69. //画车
  70. that.initMarkes( 45,60, require("@/assets/img/car1.png"),res.data.data.result.lon,res.data.data.result.lat,"现在所在位置");
  71. //显示窗体
  72. that.initCustomMarkes(that.carNumber,res.data.data.result.adr,res.data.data.result.lon,res.data.data.result.lat);
  73. }else{
  74. this.$message.error("车辆暂时无GPS");
  75. }
  76. });
  77. },
  78. //初始化地图
  79. initMap(lon,lat) {
  80. lazyAMapApiLoaderInstance.load().then(() => {
  81. let that = this;
  82. that.map = new AMap.Map("amap-container", {
  83. //设置地图容器id
  84. viewMode: "2D", //是否为2D地图模式
  85. zoom: 18, //初始化地图级别
  86. center: [lon,lat] //初始化地图中心点位置105.602725,37.076636
  87. });
  88. });
  89. },
  90. //创建简单的标记
  91. initMarkes(weight, height, image, lon, lat, title) {
  92. let that = this;
  93. //图标标记点
  94. let pointicon = new AMap.Icon({
  95. size: new AMap.Size(weight, height), // 图标尺寸
  96. image: image, // Icon的图像
  97. imageOffset: new AMap.Pixel(2, 10), // 图像相对展示区域的偏移量,适于雪碧图等
  98. imageSize: new AMap.Size(weight, height) // 根据所设置的大小拉伸或压缩图片
  99. });
  100. // 创建一个 Marker 实例:
  101. var pointmarker = new AMap.Marker({
  102. position: new AMap.LngLat(lon, lat), // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
  103. icon: pointicon,
  104. title: title
  105. });
  106. // 将创建的点标记添加到已有的地图实例:
  107. that.map.add(pointmarker);
  108. },
  109. //初始化窗体
  110. initCustomMarkes(title, details, lon, lat) {
  111. let that = this;
  112. //自定义窗体内容
  113. var content = [
  114. "<div style='top:1px;width: 180px; background-color: rgba(0, 0, 0, 1);' ><font color='white'>" +
  115. title +
  116. "</font>",
  117. "<div style='background-color:rgba(255, 255, 255, 0.5);'><font color='white'>" +
  118. details +
  119. "</font></div></div>"
  120. ];
  121. // 创建 infoWindow 实例
  122. var infoWindow = new AMap.InfoWindow({
  123. content: content.join("<br>"),//传入 dom 对象,或者 html 字符串
  124. offset:new AMap.Pixel(0,-20)//修改信息差窗体偏移
  125. });
  126. // 打开信息窗体
  127. infoWindow.open(that.map, [lon, lat]);
  128. },
  129. }
  130. };
  131. </script>
  132. <style>
  133. .inputStyle {
  134. position: absolute;
  135. width: 200px;
  136. left: 50px;
  137. }
  138. .controller {
  139. width: 100%;
  140. height: 70px;
  141. background: white;
  142. position: absolute;
  143. z-index: 99;
  144. top: 0;
  145. left: 0;
  146. }
  147. .in_transit_information {
  148. width: 320px;
  149. float: left;
  150. height: 40px;
  151. }
  152. .container {
  153. width: 100%;
  154. height: 100%;
  155. }
  156. span.item_details2 {
  157. position: relative;
  158. top: 20px;
  159. }
  160. .date_picker_style {
  161. position: relative;
  162. left: 50px;
  163. }
  164. .item_details {
  165. position: relative;
  166. top: 5px;
  167. height: 0px;
  168. left: 0px;
  169. }
  170. #amap-container {
  171. position: relative;
  172. width: 100%;
  173. height: 100%;
  174. overflow: hidden;
  175. margin: 0;
  176. font-family: "微软雅黑";
  177. }
  178. /* 进度条 */
  179. .mySlider {
  180. width: 150px;
  181. height: 20px;
  182. display: inline-block;
  183. position: relative;
  184. left: 32px;
  185. }
  186. /* 进度条 */
  187. .mySlider2 {
  188. width: 400px;
  189. height: 20px;
  190. display: inline-block;
  191. position: relative;
  192. left: 32px;
  193. }
  194. .play {
  195. position: relative;
  196. left: 28px;
  197. }
  198. .quickly {
  199. float: right;
  200. position: relative;
  201. left: -20px;
  202. top: 10px;
  203. }
  204. .pause {
  205. position: relative;
  206. left: 28px;
  207. }
  208. .passed-time {
  209. position: relative;
  210. left: 5px;
  211. }
  212. .end-time {
  213. position: relative;
  214. left: 5px;
  215. }
  216. .map-times {
  217. position: relative;
  218. width: 40px;
  219. }
  220. .searchstyle {
  221. position: relative;
  222. left: 45px;
  223. }
  224. .map-control {
  225. float: left;
  226. width: 270px;
  227. }
  228. .driving_information {
  229. height: 40px;
  230. width: 240px;
  231. float: left;
  232. }
  233. </style>