hch-position.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <view>
  3. <view class="page-body">
  4. <view class="page-section page-section-gap">
  5. <map scale="10" ubkey='CQIBZ-P2MR5-PM3IB-QRKTX-SEVJE-GYF34' :showScale="false" :showLocation="true" :showCompass="false" enableZoom="true" enableScroll="true" enableBuilding="true" enable3D="true" id="myMap" style="width: 100%; height: 600px;"
  6. :latitude="latitude"
  7. :longitude="longitude"
  8. :markers="markersIn"
  9. :layerStyle="mapStyle"
  10. @markertap='markertap'
  11. @anchorpointtap='anchorpointtap'
  12. >
  13. </map>
  14. </view>
  15. <lPainter
  16. style="position: fixed;left:0px;top: -500px;"
  17. isRenderImage
  18. :board="painter.base"
  19. @success="(e)=>{painter.path = e; painter.wait=0}"
  20. />
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import lPainter from '@/components/lime-painter/index.vue'
  26. export default {
  27. components:{
  28. lPainter
  29. },
  30. props: {
  31. markers: {
  32. type: Array,
  33. default: [{
  34. marker:{
  35. id: 1,
  36. latitude: 30.6034799,
  37. longitude: 104.1132550,
  38. // iconPath: "../../static/hch-position/门店.png",
  39. width: '38rpx',
  40. height: '40rpx',
  41. joinCluster: true, // 指定了该参数才会参与聚合
  42. callout: {
  43. content: "门店1号店",
  44. borderRadius: 10,
  45. padding: 5,
  46. display: "ALWAYS",
  47. transform: "tranlateY(20px)"
  48. }
  49. },
  50. },
  51. ]
  52. }
  53. },
  54. data() {
  55. return {
  56. isisMarkering: false,
  57. isActiveMarker: 0,
  58. latitude: 30.6034799,
  59. longitude: 104.1132550,
  60. mapStyle: 1, //个性化地图
  61. markersIn: [],
  62. isUpdate: false,
  63. painter:{
  64. wait: 0,
  65. base:{
  66. width: '42px',
  67. height: '48px',
  68. views:[
  69. {
  70. type: 'image',
  71. src: '../../static/icon/late02.png',
  72. css: {
  73. left: '0px',
  74. top: '0px',
  75. width: '42px',
  76. height: '48px',
  77. }
  78. },
  79. {
  80. type: 'image',
  81. src: '',
  82. css: {
  83. left: '3.5px',
  84. top: '2px',
  85. width: '35px',
  86. height: '35px',
  87. borderRadius: '17.5px'
  88. }
  89. }
  90. ]
  91. },
  92. path:""
  93. },
  94. }
  95. },
  96. onReady() {
  97. this._mapContext = uni.createMapContext("map", this);
  98. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  99. this._mapContext.initMarkerCluster({
  100. enableDefaultStyle: false,
  101. zoomOnClick: true,
  102. gridSize: 60,
  103. complete(res) {
  104. console.log('initMarkerCluster', res)
  105. }
  106. });
  107. this._mapContext.on("markerClusterCreate", (e) => {
  108. console.log("markerClusterCreate", e);
  109. });
  110. // this.addMarkers();
  111. },
  112. methods: {
  113. goLocation(la,lo){
  114. this.latitude = la
  115. this.longitude = lo
  116. },
  117. //生成图片
  118. generateImg(imgUrl){
  119. this.painter.base.views[1].src = imgUrl;
  120. this.painter.wait = 1;
  121. return new Promise(resolve=>{
  122. let timer = setInterval(()=>{
  123. if(this.painter.wait === 0){
  124. clearInterval(timer);
  125. resolve(this.painter.path);
  126. }else if(this.painter.wait <= 3000){
  127. this.painter.wait += 10
  128. }else{
  129. clearInterval(timer);
  130. this.painter.wait = 0;
  131. resolve(this.painter.path);
  132. }
  133. }, 10);
  134. })
  135. },
  136. // 点击标记点时触发,e.detail = {markerId}
  137. markertap(e, mode = true, isQt = false) {
  138. if(!isQt && (this.isActiveMarker === e.markerId || this.isMarkering)) return;
  139. this.isMarkering = true;
  140. setTimeout(()=>{
  141. this.isMarkering = false
  142. }, 200)
  143. this.markersIn.forEach((item,index) => {
  144. if(e.markerId == item.id){
  145. this.isActiveMarker = item.id;
  146. item.iconPath = "";
  147. item.width="34rpx";
  148. item.height = "46rpx";
  149. this.latitude = item.latitude
  150. this.longitude = item.longitude
  151. if(this.painter.wait != 0) return;
  152. this.generateImg(item.active.iconPath).then(()=>{
  153. // if(this.isActiveMarker != item.id) return;
  154. item.width = item.active.width;
  155. item.height = item.active.height;
  156. item.iconPath = this.painter.path;
  157. item.isActive = true;
  158. this.$set(this.markersIn, index, item);
  159. })
  160. this.isUpdate = false
  161. mode&&this.$emit('moveToMarkId',e.markerId)
  162. }else if(item.isActive||item.iconPath != item.noActive.iconPath){
  163. item.width = item.noActive.width;
  164. item.height = item.noActive.height;
  165. item.iconPath = item.noActive.iconPath;
  166. item.isActive = false;
  167. this.$set(this.markersIn, index, item);
  168. }
  169. })
  170. },
  171. //点击定位标时触发,e.detail = {longitude, latitude}
  172. anchorpointtap(e) {
  173. console.log('---->定位点', e.detail);
  174. },
  175. addMarkers() {
  176. this._mapContext.addMarkers({
  177. markers: this.markersIn,
  178. clear: false,
  179. complete(res) {
  180. console.log('addMarkers', res)
  181. }
  182. })
  183. },
  184. },
  185. watch:{
  186. 'markers': {
  187. handler(val,oldVal) {
  188. this.markersIn = this.markers.map(item=>{
  189. return item.marker;
  190. })
  191. },
  192. },
  193. }
  194. }
  195. </script>
  196. <style lang="scss" src="./hch.scss" scoped></style>