mapValue.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div>
  3. <div id="mapValue" :style="`height:${height || 300}px`"></div>
  4. <!--控制条-->
  5. <div class="map-control" v-if="isStart && !!point.length">
  6. <div class="clickIco">
  7. <i class="zoniot_font zoniot-icon-kaishi" v-if="palyStayus == 0" @click="navgControl('start')"></i>
  8. <i class="zoniot_font zoniot-icon-tingzhi" v-else-if="palyStayus == 2" @click="navgControl('pause')"></i>
  9. <i class="zoniot_font zoniot-icon-kaishi" v-else-if="palyStayus == 1" @click="navgControl('resume')"></i>
  10. </div>
  11. <el-slider
  12. class="slider"
  13. v-model="sliderVal"
  14. :show-tooltip="false"
  15. :format-tooltip="hideFormat"
  16. :step="0.0001"
  17. :disabled="beforeInit"
  18. @change="carReLocate"
  19. ></el-slider>
  20. <el-select v-model="times">
  21. <el-option :value="1" label="1倍速"></el-option>
  22. <el-option :value="2" label="2倍速"></el-option>
  23. <el-option :value="3" label="3倍速"></el-option>
  24. <el-option :value="4" label="4倍速"></el-option>
  25. </el-select>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import functionJs from './pathSimplifierIns';
  31. export default {
  32. props: ['point', 'isStart', 'height'],
  33. mixins: [functionJs],
  34. data() {
  35. return {
  36. marker: '',
  37. markerArr: [],
  38. polyline: null
  39. };
  40. },
  41. watch: {
  42. point: {
  43. handler() {
  44. if (!!this.map) {
  45. this.lineArr = [];
  46. // 判断当前是否有绘制点位清除
  47. if (this.markerArr.length > 0) {
  48. this.map.remove(this.markerArr);
  49. this.markerArr = [];
  50. }
  51. // 判断当前是否有巡航路线清除
  52. if (!!this.pathSimplifierIns) {
  53. this.pathSimplifierIns.setData([]);
  54. this.pathSimplifierIns = null;
  55. }
  56. // 判断当前是否有轨迹清除
  57. if (!!this.polyline) {
  58. this.map.remove(this.polyline);
  59. this.polyline = null;
  60. }
  61. // 先初始化点位信息
  62. this.point.map((item, index) => {
  63. this.addIcon(item, index);
  64. });
  65. this.setMap();
  66. }
  67. },
  68. deep: true,
  69. immediate: true
  70. }
  71. },
  72. methods: {
  73. init() {
  74. this.map = new AMap.Map('mapValue', {
  75. resizeEnable: true, //是否监控地图容器尺寸变化
  76. zoom: 11 //初始化地图层级
  77. });
  78. },
  79. //绘制点位信息
  80. addIcon(e, index) {
  81. let lineArr = [e.longitude, e.latitude];
  82. this.marker = new AMap.Marker({
  83. icon: this.icon,
  84. position: lineArr
  85. });
  86. this.marker.setLabel({
  87. offset: new AMap.Pixel(-22, 40),
  88. content: `巡更点:${index + 1}`
  89. });
  90. this.markerArr.push(this.marker);
  91. this.lineArr.push(lineArr);
  92. },
  93. // 添加点位 添加路线到地图
  94. setMap() {
  95. this.map.add(this.markerArr);
  96. this.map.setFitView();
  97. // 大于一个点创建 巡航路线
  98. if (this.point.length > 1) {
  99. // 是否巡航开启
  100. if (this.isStart) {
  101. this.$nextTick(() => {
  102. this.initPlayBox();
  103. this.beforeInit = true;
  104. this.initLineArr(true);
  105. });
  106. } else {
  107. this.addPolyline();
  108. }
  109. }
  110. },
  111. //轨迹路线
  112. addPolyline() {
  113. this.polyline = new AMap.Polyline({
  114. map: this.map,
  115. path: this.lineArr,
  116. showDir: true,
  117. strokeColor: '#28F', //线颜色
  118. // strokeOpacity: 1, //线透明度
  119. strokeWeight: 6 //线宽
  120. // strokeStyle: "solid" //线样式
  121. });
  122. }
  123. },
  124. created() {
  125. this.$nextTick(() => {
  126. this.init();
  127. });
  128. }
  129. };
  130. </script>
  131. <style scoped lang="scss">
  132. #mapValue {
  133. width: 100%;
  134. /deep/ .amap-marker-label {
  135. border: 0 none;
  136. background-color: #fff;
  137. white-space: nowrap;
  138. box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.3);
  139. border-radius: 5px;
  140. }
  141. /deep/ .amap-marker-label:before {
  142. position: absolute;
  143. border: 5px solid transparent;
  144. border-bottom-color: #fff;
  145. top: -10px;
  146. left: 43%;
  147. content: '';
  148. width: 0;
  149. height: 0;
  150. }
  151. }
  152. .my-autocomplete {
  153. li {
  154. line-height: normal;
  155. padding: 7px;
  156. .name {
  157. text-overflow: ellipsis;
  158. overflow: hidden;
  159. span {
  160. font-size: 12px;
  161. color: #b4b4b4;
  162. }
  163. }
  164. }
  165. }
  166. .map-control {
  167. display: flex;
  168. justify-content: space-between;
  169. margin-top: 20px;
  170. .clickIco i {
  171. font-size: 30px;
  172. line-height: 31px;
  173. }
  174. .slider {
  175. width: calc(100% - 270px);
  176. }
  177. }
  178. </style>