hch-position.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. console.log(index)
  136. this.updateMode = mode
  137. if(typeof index == 'object'){
  138. index = index.markerId
  139. }
  140. if(!isQt){
  141. if(this.painter.wait != 0) return;
  142. if(this.isActiveMarkerIndex === index) return;
  143. }
  144. if(this.markersIn[this.isActiveMarkerIndex]){
  145. this.markersIn[this.isActiveMarkerIndex].width = '34rpx';
  146. this.markersIn[this.isActiveMarkerIndex].height = '40rpx';
  147. this.markersIn[this.isActiveMarkerIndex].iconPath = '../../static/icon/late02.png';
  148. }
  149. this.isActiveMarkerIndex = index;
  150. this.innerGeo = {
  151. latitude: this.markersIn[this.isActiveMarkerIndex].latitude,
  152. longitude: this.markersIn[this.isActiveMarkerIndex].longitude
  153. }
  154. this.painter.wait = 1;
  155. this.$set(this.painter.base.views, 2, {
  156. type: 'image',
  157. src: this.markersIn[this.isActiveMarkerIndex].activeIconPath,
  158. css: {
  159. left: '3.5px',
  160. top: '2px',
  161. width: '35px',
  162. height: '35px',
  163. borderRadius: '17.5px'
  164. }
  165. })
  166. },
  167. canvasSuccess(e){
  168. if(this.isActiveMarkerIndex == -1)return;
  169. this.markersIn[this.isActiveMarkerIndex].width = '82rpx';
  170. this.markersIn[this.isActiveMarkerIndex].height = '90rpx';
  171. this.markersIn[this.isActiveMarkerIndex].iconPath = e;
  172. this.markersIn = Object.assign(this.markersIn);
  173. this.painter.wait=0;
  174. uni.vibrateShort({});
  175. this.updateMode&&this.$emit('moveToMarkId',this.isActiveMarkerIndex);
  176. },
  177. canvasFail(){
  178. if(this.isActiveMarkerIndex == -1)return;
  179. this.markersIn[this.isActiveMarkerIndex].width = '80rpx';
  180. this.markersIn[this.isActiveMarkerIndex].height = '90rpx';
  181. this.markersIn[this.isActiveMarkerIndex].iconPath = "";
  182. this.markersIn = Object.assign(this.markersIn);
  183. this.painter.wait=0
  184. uni.vibrateShort({});
  185. this.updateMode&&this.$emit('moveToMarkId',this.isActiveMarkerIndex);
  186. },
  187. //点击定位标时触发,e.detail = {longitude, latitude}
  188. anchorpointtap(e) {
  189. console.log('---->定位点', e.detail);
  190. },
  191. addMarkers() {
  192. this._mapContext.addMarkers({
  193. markers: this.markersIn,
  194. clear: false,
  195. complete(res) {
  196. console.log('addMarkers', res)
  197. }
  198. })
  199. },
  200. updateContent(hotelList,mode=false){
  201. const temp = Object.assign(hotelList);
  202. if(mode){
  203. this.markersIn = temp.map((item, index)=>{
  204. item.marker.id = index;
  205. return item.marker;
  206. })
  207. }else{
  208. const conpentate = this.markersIn.length;
  209. this.markersIn.push(...temp.map((item, index)=>{
  210. item.marker.id = index + conpentate;
  211. return item.marker;
  212. }))
  213. }
  214. },
  215. rendered(){
  216. if(this.markersIn.length > 0){
  217. this.$emit('rendered');
  218. }
  219. }
  220. },
  221. watch:{
  222. 'geo':{
  223. handler(v){
  224. this.innerGeo = Object.assign(this.geo)
  225. },
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" src="./hch.scss" scoped></style>