hch-position.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view style="height:100%;">
  3. <view class="page-body" style="height:100%;">
  4. <view class="page-section page-section-gap" style="height:100%;">
  5. <map scale="9" 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: 100%;"
  6. :latitude="innerGeo.latitude"
  7. :longitude="innerGeo.longitude"
  8. :markers="markersIn"
  9. :layerStyle="mapStyle"
  10. @markertap='markertap'
  11. @anchorpointtap='anchorpointtap'
  12. @updated="rendered"
  13. >
  14. </map>
  15. </view>
  16. <lPainter
  17. style="position: fixed;left:0px;top: -500px;"
  18. isRenderImage
  19. :board="painter.base"
  20. @success="canvasSuccess"
  21. @fail="canvasFail"
  22. />
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. import lPainter from '@/components/lime-painter/index.vue'
  28. export default {
  29. components:{
  30. lPainter
  31. },
  32. props: {
  33. markers: {
  34. type: Array,
  35. default: [{
  36. marker:{
  37. id: 1,
  38. latitude: 30.6034799,
  39. longitude: 104.1132550,
  40. // iconPath: "../../static/hch-position/门店.png",
  41. width: '38rpx',
  42. height: '40rpx',
  43. joinCluster: true, // 指定了该参数才会参与聚合
  44. callout: {
  45. content: "门店1号店",
  46. borderRadius: 10,
  47. padding: 5,
  48. display: "ALWAYS",
  49. transform: "tranlateY(20px)"
  50. }
  51. },
  52. },
  53. ]
  54. },
  55. geo:{
  56. type: Object,
  57. default:{
  58. latitude:30.6034799,
  59. longitude:104.1132550,
  60. }
  61. }
  62. },
  63. data() {
  64. return {
  65. updateMode: true,
  66. isisMarkering: false,
  67. isActiveMarker: 0,
  68. isActiveMarkerIndex: -1,
  69. innerGeo:{
  70. latitude: 30.6034799,
  71. longitude: 104.1132550,
  72. },
  73. mapStyle: 1, //个性化地图
  74. markersIn: [],
  75. isUpdate: false,
  76. painter:{
  77. wait: 0,
  78. base:{
  79. width: '42px',
  80. height: '48px',
  81. views:[
  82. {
  83. type: 'image',
  84. src: '../../static/icon/late02.png',
  85. css: {
  86. left: '0px',
  87. top: '0px',
  88. width: '42px',
  89. height: '48px',
  90. }
  91. },
  92. {
  93. type: 'image',
  94. src: '',
  95. css: {
  96. left: '3.5px',
  97. top: '2px',
  98. width: '35px',
  99. height: '35px',
  100. borderRadius: '17.5px'
  101. }
  102. }
  103. ]
  104. },
  105. path:""
  106. },
  107. }
  108. },
  109. onReady() {
  110. this._mapContext = uni.createMapContext("map", this);
  111. this.innerGeo = Object.assign(this.geo)
  112. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  113. this._mapContext.initMarkerCluster({
  114. enableDefaultStyle: false,
  115. zoomOnClick: true,
  116. gridSize: 60,
  117. complete(res) {
  118. console.log('initMarkerCluster', res)
  119. }
  120. });
  121. this._mapContext.on("markerClusterCreate", (e) => {
  122. console.log("markerClusterCreate", e);
  123. });
  124. // this.addMarkers();
  125. },
  126. methods: {
  127. goLocation(la,lo){
  128. this.innerGeo = {
  129. latitude:la,
  130. longitude:lo
  131. }
  132. },
  133. // 点击标记点时触发,e.detail = {markerId}
  134. markertap(index, mode = true, isQt = false) {
  135. this.updateMode = mode
  136. if(typeof index == 'object'){
  137. index = index.markerId
  138. }
  139. if(!isQt){
  140. if(this.painter.wait != 0) return;
  141. if(this.isActiveMarkerIndex === index) return;
  142. }
  143. if(this.markersIn[this.isActiveMarkerIndex]){
  144. this.markersIn[this.isActiveMarkerIndex].width = '34rpx';
  145. this.markersIn[this.isActiveMarkerIndex].height = '40rpx';
  146. this.markersIn[this.isActiveMarkerIndex].iconPath = '../../static/icon/late02.png';
  147. }
  148. this.isActiveMarkerIndex = index;
  149. this.innerGeo = {
  150. latitude: this.markersIn[this.isActiveMarkerIndex].latitude,
  151. longitude: this.markersIn[this.isActiveMarkerIndex].longitude
  152. }
  153. this.painter.wait = 1;
  154. this.painter.base.views[1].src = this.markersIn[this.isActiveMarkerIndex].activeIconPath + `?v=${(new Date()).getTime()}`
  155. console.log(this.painter.base.views[1].src)
  156. // this.$set(this.painter.base.views, 2, {
  157. // type: 'image',
  158. // src: this.markersIn[this.isActiveMarkerIndex].activeIconPath,
  159. // css: {
  160. // left: '3.5px',
  161. // top: '2px',
  162. // width: '35px',
  163. // height: '35px',
  164. // borderRadius: '17.5px'
  165. // }
  166. // })
  167. },
  168. canvasSuccess(e){
  169. if(this.isActiveMarkerIndex == -1)return;
  170. this.markersIn[this.isActiveMarkerIndex].width = '82rpx';
  171. this.markersIn[this.isActiveMarkerIndex].height = '90rpx';
  172. this.markersIn[this.isActiveMarkerIndex].iconPath = e;
  173. this.markersIn = Object.assign(this.markersIn);
  174. this.painter.wait=0;
  175. uni.vibrateShort({});
  176. this.updateMode&&this.$emit('moveToMarkId',this.isActiveMarkerIndex);
  177. },
  178. canvasFail(){
  179. if(this.isActiveMarkerIndex == -1)return;
  180. this.markersIn[this.isActiveMarkerIndex].width = '80rpx';
  181. this.markersIn[this.isActiveMarkerIndex].height = '90rpx';
  182. this.markersIn[this.isActiveMarkerIndex].iconPath = "";
  183. this.markersIn = Object.assign(this.markersIn);
  184. this.painter.wait=0
  185. uni.vibrateShort({});
  186. this.updateMode&&this.$emit('moveToMarkId',this.isActiveMarkerIndex);
  187. },
  188. //点击定位标时触发,e.detail = {longitude, latitude}
  189. anchorpointtap(e) {
  190. console.log('---->定位点', e.detail);
  191. },
  192. addMarkers() {
  193. this._mapContext.addMarkers({
  194. markers: this.markersIn,
  195. clear: false,
  196. complete(res) {
  197. console.log('addMarkers', res)
  198. }
  199. })
  200. },
  201. updateContent(hotelList,mode=false){
  202. const temp = Object.assign(hotelList);
  203. if(mode){
  204. this.markersIn = temp.map((item, index)=>{
  205. item.marker.id = index;
  206. return item.marker;
  207. })
  208. }else{
  209. const conpentate = this.markersIn.length;
  210. this.markersIn.push(...temp.map((item, index)=>{
  211. item.marker.id = index + conpentate;
  212. return item.marker;
  213. }))
  214. }
  215. },
  216. rendered(){
  217. if(this.markersIn.length > 0){
  218. this.$emit('rendered');
  219. }
  220. }
  221. },
  222. watch:{
  223. 'geo':{
  224. handler(v){
  225. this.innerGeo = Object.assign(this.geo)
  226. },
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang="scss" src="./hch.scss" scoped></style>