hch-position.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. isActiveMarkerIndex: -1,
  59. latitude: 30.6034799,
  60. longitude: 104.1132550,
  61. mapStyle: 1, //个性化地图
  62. markersIn: [],
  63. isUpdate: false,
  64. painter:{
  65. wait: 0,
  66. base:{
  67. width: '42px',
  68. height: '48px',
  69. views:[
  70. {
  71. type: 'image',
  72. src: '../../static/icon/late02.png',
  73. css: {
  74. left: '0px',
  75. top: '0px',
  76. width: '42px',
  77. height: '48px',
  78. }
  79. },
  80. {
  81. type: 'image',
  82. src: '',
  83. css: {
  84. left: '3.5px',
  85. top: '2px',
  86. width: '35px',
  87. height: '35px',
  88. borderRadius: '17.5px'
  89. }
  90. }
  91. ]
  92. },
  93. path:""
  94. },
  95. }
  96. },
  97. onReady() {
  98. this._mapContext = uni.createMapContext("map", this);
  99. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  100. this._mapContext.initMarkerCluster({
  101. enableDefaultStyle: false,
  102. zoomOnClick: true,
  103. gridSize: 60,
  104. complete(res) {
  105. console.log('initMarkerCluster', res)
  106. }
  107. });
  108. this._mapContext.on("markerClusterCreate", (e) => {
  109. console.log("markerClusterCreate", e);
  110. });
  111. // this.addMarkers();
  112. },
  113. methods: {
  114. goLocation(la,lo){
  115. this.latitude = la
  116. this.longitude = lo
  117. },
  118. //生成图片
  119. generateImg(imgUrl){
  120. this.painter.base.views[1].src = imgUrl;
  121. this.painter.wait = 1;
  122. return new Promise(resolve=>{
  123. let timer = setInterval(()=>{
  124. if(this.painter.wait === 0){
  125. clearInterval(timer);
  126. resolve(this.painter.path);
  127. }else if(this.painter.wait <= 3000){
  128. this.painter.wait += 10
  129. }else{
  130. clearInterval(timer);
  131. this.painter.wait = 0;
  132. resolve(this.painter.path);
  133. }
  134. }, 10);
  135. })
  136. },
  137. // 点击标记点时触发,e.detail = {markerId}
  138. markertap(e, mode = true, isQt = false) {
  139. let index = 0;
  140. if(typeof e.index !== 'undefined'){
  141. index = e.index;
  142. }else if(typeof e.index === 'undefined'){
  143. index = e.markerId;
  144. }
  145. if(!isQt && (this.isActiveMarkerIndex === index || this.isMarkering)) return;
  146. this.isMarkering = true;
  147. setTimeout(()=>{
  148. this.isMarkering = false
  149. }, 200)
  150. const itemOld = this.markersIn[this.isActiveMarkerIndex];
  151. if(itemOld){
  152. itemOld.width = itemOld.noActive.width;
  153. itemOld.height = itemOld.noActive.height;
  154. itemOld.iconPath = itemOld.noActive.iconPath;
  155. itemOld.isActive = false;
  156. this.$set(this.markersIn, this.isActiveMarkerIndex, itemOld);
  157. }
  158. this.isActiveMarkerIndex = index;
  159. const item = this.markersIn[this.isActiveMarkerIndex];
  160. item.width = item.active.width;
  161. item.height = item.active.height;
  162. item.iconPath = this.painter.path;
  163. item.isActive = true;
  164. this.$set(this.markersIn, index, item);
  165. this.latitude = item.latitude
  166. this.longitude = item.longitude
  167. if(this.painter.wait != 0) return;
  168. this.generateImg(item.active.iconPath).then(()=>{
  169. // if(this.isActiveMarker != item.id) return;
  170. item.width = item.active.width;
  171. item.height = item.active.height;
  172. item.iconPath = this.painter.path;
  173. item.isActive = true;
  174. this.$set(this.markersIn, index, item);
  175. })
  176. mode&&this.$emit('moveToMarkId',index);
  177. },
  178. //点击定位标时触发,e.detail = {longitude, latitude}
  179. anchorpointtap(e) {
  180. console.log('---->定位点', e.detail);
  181. },
  182. addMarkers() {
  183. this._mapContext.addMarkers({
  184. markers: this.markersIn,
  185. clear: false,
  186. complete(res) {
  187. console.log('addMarkers', res)
  188. }
  189. })
  190. },
  191. },
  192. watch:{
  193. 'markers': {
  194. handler(val,oldVal) {
  195. const temp = Object.assign(this.markers);
  196. this.markersIn = temp.map((item, index)=>{
  197. item.marker.id = index;
  198. return item.marker;
  199. })
  200. },
  201. },
  202. }
  203. }
  204. </script>
  205. <style lang="scss" src="./hch.scss" scoped></style>