mapValue.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div>
  3. <div id="mapValue" ></div>
  4. <!--控制条-->
  5. <div class="map-control" v-if="isStart">
  6. <div class="clickIco" @click="startAnimation()">
  7. <i class="zoniot_font" :class="isSta?'zoniot-icon-kaishi':'zoniot-icon-tingzhi'"></i>
  8. </div>
  9. <el-slider
  10. class="slider"
  11. v-model="sliderVal"
  12. :format-tooltip="hideFormat"
  13. :step="0.0001"
  14. ></el-slider>
  15. <el-select v-model="speed">
  16. <el-option :value="1000" label="1倍速"></el-option>
  17. <el-option :value="1500" label="1.5倍速"></el-option>
  18. <el-option :value="2000" label="2倍速"></el-option>
  19. <el-option :value="3000" label="3倍速"></el-option>
  20. </el-select>
  21. </div>
  22. </div>
  23. </template>
  24. <script>
  25. export default {
  26. props: ['point','isStart'],
  27. data() {
  28. return {
  29. map: '',
  30. marker: '',
  31. icon: 'https://webapi.amap.com/theme/v1.3/markers/n/mark_b.png',
  32. markerArr: [],
  33. lineArr: [],
  34. marker2: '',
  35. speed: 1000,
  36. sliderVal: 0,
  37. isSta: true
  38. };
  39. },
  40. watch: {
  41. point(e) {
  42. this.point.map((item, index) => {
  43. let tag = false;
  44. if (index == this.point.length - 1) {
  45. tag = true;
  46. }
  47. if (!!this.map) {
  48. this.addIcon(item, tag);
  49. }
  50. });
  51. },
  52. speed(e) {
  53. this.startAnimation(e);
  54. }
  55. },
  56. methods: {
  57. init() {
  58. this.map = new AMap.Map('mapValue', {
  59. resizeEnable: true, //是否监控地图容器尺寸变化
  60. zoom: 11 //初始化地图层级
  61. });
  62. },
  63. addIcon(e, is) {
  64. let _this = this;
  65. let lineArr = [e.longitude, e.latitude];
  66. this.marker = new AMap.Marker({
  67. icon: this.icon,
  68. position: lineArr
  69. });
  70. this.map.add(this.marker);
  71. this.markerArr.push(this.marker);
  72. this.lineArr.push(lineArr);
  73. this.map.setFitView();
  74. if (is) {
  75. this.initLineArr();
  76. }
  77. },
  78. initLineArr() {
  79. let _this = this;
  80. this.marker2 = new AMap.Marker({
  81. map: _this.map,
  82. position: _this.lineArr[0],
  83. icon: 'https://webapi.amap.com/images/car.png',
  84. offset: new AMap.Pixel(-26, -13),
  85. autoRotation: true,
  86. angle: -90
  87. });
  88. // 绘制轨迹
  89. let polyline = new AMap.Polyline({
  90. map: this.map,
  91. path: _this.lineArr,
  92. showDir: true,
  93. strokeColor: '#28F', //线颜色
  94. // strokeOpacity: 1, //线透明度
  95. strokeWeight: 6 //线宽
  96. // strokeStyle: "solid" //线样式
  97. });
  98. let passedPolyline = new AMap.Polyline({
  99. map: _this.map,
  100. // path: lineArr,
  101. strokeColor: '#AF5', //线颜色
  102. // strokeOpacity: 1, //线透明度
  103. strokeWeight: 6 //线宽
  104. // strokeStyle: "solid" //线样式
  105. });
  106. this.marker2.on('moving', e => {
  107. passedPolyline.setPath(e.passedPath);
  108. });
  109. this.marker2.on('moveend', e => {
  110. this.isSta = true;
  111. });
  112. },
  113. startAnimation(time) {
  114. let _this = this;
  115. this.isSta = false;
  116. this.marker2.moveAlong(
  117. this.lineArr,
  118. time | 1000,
  119. e => {
  120. this.sliderVal = e * 100;
  121. return e;
  122. },
  123. false
  124. );
  125. }
  126. },
  127. created() {
  128. this.$nextTick(() => {
  129. this.init();
  130. });
  131. }
  132. };
  133. </script>
  134. <style scoped lang="scss">
  135. /* --------------------------------高德地图样式----------------------------- */
  136. #mapValue {
  137. // margin-top: 20px;
  138. width: 100%;
  139. height: 300px;
  140. }
  141. .my-autocomplete {
  142. li {
  143. line-height: normal;
  144. padding: 7px;
  145. .name {
  146. text-overflow: ellipsis;
  147. overflow: hidden;
  148. span {
  149. font-size: 12px;
  150. color: #b4b4b4;
  151. }
  152. }
  153. }
  154. }
  155. .map-control {
  156. display: flex;
  157. justify-content: space-between;
  158. margin-top: 20px;
  159. .clickIco i {
  160. font-size: 30px;
  161. line-height: 31px;
  162. }
  163. .slider {
  164. width: calc(100% - 270px);
  165. }
  166. }
  167. </style>