Gis.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view class="gis-card" ref="mapContainer" id="gis-card">
  3. <map id="map" ref="map" :show-location="true" :style="{height:contentHeight+'px'}" class="gis-card__content"
  4. :latitude="latitude" :longitude="longitude" :markers="covers" :polyline="polylines">
  5. </map>
  6. <!-- <view v-for="(item,index) in logs" :key="index+item">
  7. {{item}}
  8. </view>
  9. <view class="gis-card__action">
  10. <u-button text="回放" @click="handleTransformHistory" type="primary" size="mini"></u-button>
  11. </view> -->
  12. </view>
  13. </template>
  14. <script>
  15. import {
  16. forIn,
  17. takeRight,
  18. keys,
  19. map,
  20. first,
  21. isEmpty
  22. } from 'lodash-es';
  23. import markerIcon from '@/static/pest.png';
  24. //walk_lnglat_list 行走轨迹数组字段
  25. export default {
  26. props: {
  27. dataSource: {
  28. type: Object,
  29. default: () => ({})
  30. }
  31. },
  32. data() {
  33. return {
  34. latitude: 34.809478,
  35. longitude: 113.666798,
  36. /**
  37. * {
  38. id: 1,
  39. latitude: 34.809478,
  40. longitude: 113.666798,
  41. iconPath: markerIcon
  42. }
  43. */
  44. covers: [],
  45. allLocationDatasource: {
  46. '20230211': []
  47. },
  48. logs: [],
  49. contentHeight: 0,
  50. polylines: [],
  51. _mapContext: null
  52. }
  53. },
  54. onShow() {
  55. console.warn('任务详情 --------- 更新')
  56. },
  57. created() {
  58. console.warn('-------------------- created ------------121313313 gis')
  59. },
  60. mounted() {
  61. console.warn('-------------------- mounted ------------121313313 gis')
  62. console.log(this.$refs.map, 'on ready', this.dataSource.walk_lnglat_list)
  63. this.contentHeight = 600;
  64. this._mapContext = uni.createMapContext('map', this);
  65. console.log(uni.createMapContext('map', this), '------------------ map context 1')
  66. this.init();
  67. this.$nextTick(() => {
  68. console.log('next tick')
  69. console.warn('------------------ map context')
  70. // this.contentHeight = this.$refs['mapContainer'].$el && this.$refs['mapContainer'].$el
  71. // .clientHeight || 300;
  72. // this.contentHeight = 300;
  73. // console.warn(this.contentHeight, 'warn =sdsafafasf')
  74. // this.setCenterPosition()
  75. })
  76. },
  77. methods: {
  78. init() {
  79. const lines = map(this.dataSource.walk_lnglat_list, item => {
  80. const paths = map(item, locationData => {
  81. return {
  82. latitude: locationData.lat,
  83. longitude: locationData.lng,
  84. }
  85. })
  86. return {
  87. points: paths,
  88. color: '#409eff',
  89. width: 20
  90. }
  91. })
  92. console.warn(lines, 'polylines')
  93. this.polylines = lines
  94. this.updateStartLocation();
  95. },
  96. updateStartLocation() {
  97. const {
  98. lng,
  99. lat
  100. } = first(this.dataSource.walk_lnglat_list[0]) || {}
  101. this.latitude = lat;
  102. this.longitude = lng;
  103. this._mapContext.moveToLocation({
  104. latitude: lat,
  105. longitude: lng
  106. })
  107. // this.covers = [{
  108. // id: 1,
  109. // latitude: lat,
  110. // longitude: lng,
  111. // iconPath: markerIcon
  112. // }]
  113. },
  114. setCenterPosition() {
  115. uni.getLocation({
  116. type: 'gcj02',
  117. altitude: true,
  118. geocode: true,
  119. success: (res) => {
  120. console.warn(res, 'get location')
  121. console.log('当前位置的经度1:' + res.longitude);
  122. console.log('当前位置的纬度1:' + res.latitude);
  123. this.logs.push(`center-position:当前位置的经度${res.longitude};当前位置的纬度${res.latitude}`)
  124. this.latitude = res.latitude;
  125. this.longitude = res.longitude;
  126. // this._mapContext.moveToLocation({
  127. // latitude: res.latitude,
  128. // longitude: res.longitude
  129. // })
  130. // this.covers = [{
  131. // id: 1,
  132. // latitude: res.latitude,
  133. // longitude: res.longitude,
  134. // }]
  135. },
  136. fail: (err) => {
  137. console.warn(err, 'get location error')
  138. this.logs.push(err && err.errMsg)
  139. }
  140. });
  141. },
  142. handleTransformHistory() {
  143. const markerID = this.covers[0] && this.covers[0].id
  144. console.log('--------------- transform history', markerID)
  145. // const linePointDataList = map(this.dataSource.walk_lnglat_list[0] || [], item => {
  146. // return {
  147. // latitude: item.lat,
  148. // longitude: item.lng,
  149. // }
  150. // })
  151. // console.warn(linePointDataList, 'transform history', this._mapContext)
  152. // this._mapContext.moveAlong({
  153. // markerId: markerID,
  154. // path: linePointDataList,
  155. // duration: 30000,
  156. // success() {
  157. // console.log('scucess ----------------------121313')
  158. // },
  159. // fail(err) {
  160. // console.error(err)
  161. // },
  162. // complete() {
  163. // console.log('move complete ----------------------')
  164. // }
  165. // })
  166. },
  167. }
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. .gis-card {
  172. position: relative;
  173. flex: 1 1 auto;
  174. width: 100%;
  175. height: 100%;
  176. // background-color: #f00;
  177. &__content {
  178. width: 100%;
  179. height: 100%;
  180. // background-color: #00f;
  181. }
  182. &__action {
  183. position: fixed;
  184. bottom: 0;
  185. }
  186. }
  187. </style>