indexMap.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div class="positionBox">
  3. <div id="allmap"></div>
  4. </div>
  5. </template>
  6. <script>
  7. import { travelpath } from "@/api/orderManagement";
  8. import AMapLoader from "@amap/amap-jsapi-loader";
  9. export default {
  10. name: "app",
  11. data() {
  12. return {
  13. map: null,
  14. path: [],
  15. path1: [
  16. [116.405289, 39.904987],
  17. [113.964458, 40.54664],
  18. [111.47836, 41.135964],
  19. [108.949297, 41.670904],
  20. [106.380111, 42.149509],
  21. [103.774185, 42.56996],
  22. [101.135432, 42.930601],
  23. [98.46826, 43.229964],
  24. [95.777529, 43.466798],
  25. [93.068486, 43.64009],
  26. [90.34669, 43.749086],
  27. [87.61792, 43.793308],
  28. ],
  29. path2: [
  30. [117.405289, 40.904987],
  31. [114.964458, 41.54664],
  32. [112.47836, 42.135964],
  33. [109.949297, 43.670904],
  34. [107.380111, 44.149509],
  35. [104.774185, 43.56996],
  36. [102.135432, 43.930601],
  37. [99.46826, 44.229964],
  38. [96.777529, 44.466798],
  39. [94.068486, 44.64009],
  40. [91.34669, 44.749086],
  41. [88.61792, 44.793308],
  42. ],
  43. };
  44. },
  45. props: ["radio", "orderid"],
  46. watch: {
  47. radio: function (val1, val2) {
  48. debugger;
  49. if (val1 == 1) {
  50. var that = this;
  51. travelpath({ orderId: that.orderid })
  52. .then((response) => {
  53. that.path1 = [];
  54. var patharr = JSON.parse(response.data.longitudeLatitude);
  55. // console.log(JSON.parse(response.data.longitudeLatitude),11111111)
  56. for (let i = 0; i < patharr.length; i++) {
  57. that.path1.push([patharr[i].longitude, patharr[i].latitude]);
  58. }
  59. that.path = that.path1;
  60. that.loadmap();
  61. })
  62. .catch(() => {
  63. // console.log(121212)
  64. });
  65. // this.path = this.path1
  66. } else {
  67. var that = this;
  68. travelpath({ orderId: that.orderid })
  69. .then((response) => {
  70. that.path2 = [];
  71. var patharr = JSON.parse(response.data.longitudeLatitude);
  72. // console.log(JSON.parse(response.data.longitudeLatitude),11111111)
  73. for (let i = 0; i < patharr.length; i++) {
  74. that.path2.push([patharr[i].longitude, patharr[i].latitude]);
  75. }
  76. that.path = that.path2;
  77. that.loadmap();
  78. })
  79. .catch(() => {
  80. // console.log(121212)
  81. });
  82. // travelpath({orderId:this.orderid}).then(response => {
  83. // console.log(response)
  84. // })
  85. // .catch(() => {
  86. // })
  87. // this.path = this.path2
  88. }
  89. // this.loadmap();
  90. },
  91. },
  92. methods: {
  93. loadmap() {
  94. return new Promise((reslove, reject) => {
  95. AMapLoader.load({
  96. key: "211dd6f989e719022aaf47ddb0659c47", // 申请好的Web端开发者Key,首次调用 load 时必填
  97. // version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
  98. plugins: ["AMap.ToolBar", "AMap.Scale", "AMap.Geocoder"], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
  99. AMapUI: {
  100. // 是否加载 AMapUI,缺省不加载
  101. version: "1.1", // AMapUI 缺省 1.1
  102. plugins: [], // 需要加载的 AMapUI ui插件
  103. },
  104. })
  105. .then((AMap) => {
  106. this.map = new AMap.Map("allmap", {
  107. resizeEnable: true,
  108. zoom: 10,
  109. // center: [116.397428, 39.90923] //中心点坐标
  110. });
  111. //地图控件
  112. this.map.addControl(new AMap.Scale());
  113. this.map.addControl(new AMap.ToolBar());
  114. this.map.setZoom(14); //设置缩放大小
  115. this.trajectory();
  116. reslove();
  117. })
  118. .catch((e) => {
  119. console.log(e, "高德地图加载失败");
  120. reject(e);
  121. });
  122. });
  123. },
  124. // 轨迹
  125. trajectory() {
  126. AMapUI.load(["ui/misc/PathSimplifier", "lib/$"], (PathSimplifier, $) => {
  127. if (!PathSimplifier.supportCanvas) {
  128. alert("当前环境不支持 Canvas!");
  129. return;
  130. }
  131. let pathSimplifierIns = new PathSimplifier({
  132. zIndex: 100,
  133. //autoSetFitView:false,
  134. map: this.map, //所属的地图实例
  135. getPath: function (pathData, pathIndex) {
  136. return pathData.path;
  137. },
  138. getHoverTitle: function (pathData, pathIndex, pointIndex) {
  139. if (pointIndex >= 0) {
  140. //point
  141. return (
  142. pathData.name +
  143. ",点:" +
  144. pointIndex +
  145. "/" +
  146. pathData.path.length
  147. );
  148. }
  149. return pathData.name + ",点数量" + pathData.path.length;
  150. },
  151. renderOptions: {
  152. renderAllPointsIfNumberBelow: 100, //绘制路线节点,如不需要可设置为-1
  153. },
  154. });
  155. window.pathSimplifierIns = pathSimplifierIns;
  156. //设置数据
  157. pathSimplifierIns.setData([
  158. {
  159. name: "路线0",
  160. path: this.path,
  161. },
  162. ]);
  163. //对第一条线路(即索引 0)创建一个巡航器
  164. let trajectory = pathSimplifierIns.createPathNavigator(0, {
  165. loop: true, //循环播放
  166. speed: 100, //巡航速度,单位千米/小时
  167. });
  168. trajectory.start();
  169. });
  170. },
  171. },
  172. mounted() {
  173. var that = this;
  174. // console.log(this.orderid)
  175. this.$nextTick(function () {
  176. travelpath({ orderId: that.orderid })
  177. .then((response) => {
  178. that.path1 = [];
  179. if (response.data) {
  180. var patharr = JSON.parse(response.data.longitudeLatitude);
  181. // console.log(JSON.parse(response.data.longitudeLatitude),11111111)
  182. for (let i = 0; i < patharr.length; i++) {
  183. that.path1.push([patharr[i].longitude, patharr[i].latitude]);
  184. }
  185. that.path = that.path1;
  186. }
  187. that.loadmap();
  188. })
  189. .catch(() => {
  190. // console.log(121212)
  191. });
  192. });
  193. },
  194. };
  195. </script>
  196. <style scoped>
  197. #allmap {
  198. width: 100%;
  199. height: calc(100vh - 150px);
  200. }
  201. </style>