hch-position.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. if(this.painter.wait != 0) return new Promise();
  120. // this.painter.show = false;
  121. // this.painter.base.views[1].src = "https://zhengda.oss-cn-chengdu.aliyuncs.com/golf/images/15.png";
  122. this.painter.base.views[1].src = imgUrl;
  123. // this.painter.show = true;
  124. this.painter.wait = 1;
  125. return new Promise(resolve=>{
  126. let timer = setInterval(()=>{
  127. if(this.painter.wait === 0){
  128. clearInterval(timer);
  129. resolve(this.painter.path);
  130. }else if(this.painter.wait <= 3000){
  131. this.painter.wait += 10
  132. }else{
  133. clearInterval(timer);
  134. this.painter.wait = 0;
  135. resolve(this.painter.path);
  136. }
  137. }, 10);
  138. })
  139. },
  140. // 点击标记点时触发,e.detail = {markerId}
  141. markertap(e, mode = true) {
  142. if(this.isActiveMarker === e.markerId || this.isMarkering) return;
  143. this.isMarkering = true;
  144. setTimeout(()=>{
  145. this.isMarkering = false
  146. }, 200)
  147. this.markersIn.forEach((item,index) => {
  148. if(e.markerId === item.id){
  149. this.isActiveMarker = item.id;
  150. item.iconPath = "";
  151. item.width="34rpx";
  152. item.height = "46rpx";
  153. this.latitude = item.latitude
  154. this.longitude = item.longitude
  155. this.generateImg(item.active.iconPath).then(()=>{
  156. // if(this.isActiveMarker != item.id) return;
  157. item.width = item.active.width;
  158. item.height = item.active.height;
  159. item.iconPath = this.painter.path;
  160. item.isActive = true;
  161. this.$set(this.markersIn, index, item);
  162. })
  163. this.isUpdate = false
  164. mode&&this.$emit('moveToMarkId',e.markerId)
  165. }else if(item.isActive||item.iconPath != item.noActive.iconPath){
  166. item.width = item.noActive.width;
  167. item.height = item.noActive.height;
  168. item.iconPath = item.noActive.iconPath;
  169. item.isActive = false;
  170. this.$set(this.markersIn, index, item);
  171. }
  172. })
  173. },
  174. //点击定位标时触发,e.detail = {longitude, latitude}
  175. anchorpointtap(e) {
  176. console.log('---->定位点', e.detail);
  177. },
  178. addMarkers() {
  179. this._mapContext.addMarkers({
  180. markers: this.markersIn,
  181. clear: false,
  182. complete(res) {
  183. console.log('addMarkers', res)
  184. }
  185. })
  186. },
  187. },
  188. watch:{
  189. 'markers': {
  190. handler(val,oldVal) {
  191. this.markersIn = this.markers.map(item=>{
  192. return item.marker;
  193. })
  194. },
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss" src="./hch.scss" scoped></style>