ソースを参照

Merge branch 'v3.5.1' of http://git.ycjcjy.com/zhiyuxing/miniapp-v3 into v3.5.1

周立森 5 年 前
コミット
317f49fd12
共有1 個のファイルを変更した35 個の追加0 個の削除を含む
  1. 35
    0
      src/components/amap/PoiAround.js

+ 35
- 0
src/components/amap/PoiAround.js ファイルの表示

@@ -2,9 +2,32 @@ import Taro, { Component } from '@tarojs/taro'
2 2
 import { Map } from '@tarojs/components'
3 3
 import icons from './icons'
4 4
 
5
+const centerIcon = require('@assets/dingwei.png')
6
+const centerProject = 'project-999'
7
+
8
+function ObjEqual (a = {}, b = {}) { return JSON.stringify(a) === JSON.stringify(b) }
9
+
5 10
 export default class PoiAround extends Component {
11
+  map = null;
12
+
13
+  componentDidMount () {
14
+    this.map = wx.createMapContext('poi-around', this)
15
+  }
16
+
17
+  componentWillReceiveProps (nextProps) {
18
+    if (this.map) {
19
+      if (!ObjEqual(nextProps.markers, this.props.markers)) {
20
+        this.map.moveToLocation({
21
+          latitude: nextProps.latitude,
22
+          longitude: nextProps.longitude,
23
+        })
24
+      }
25
+    }
26
+  }
6 27
 
7 28
   handleTap = (e) => {
29
+    if (e.markerId === centerProject) return;
30
+
8 31
     const marker = this.props.markers.filter(x => x.id === e.markerId)[0]
9 32
     this.props.onMarkerClick && this.props.onMarkerClick(marker)
10 33
   }
@@ -24,9 +47,21 @@ export default class PoiAround extends Component {
24 47
       }
25 48
     })
26 49
 
50
+    // 最后放项目位置
51
+    markers.push({
52
+      id: centerProject,
53
+      latitude: this.props.latitude,
54
+      longitude: this.props.longitude,
55
+      iconPath: centerIcon,
56
+      width: 20,
57
+      height: 20,
58
+    })
59
+
27 60
     return this.props.longitude && (
28 61
       <Map
62
+        id="poi-around"
29 63
         showLocation
64
+        show-location={true}
30 65
         scale={12}
31 66
         markers={markers}
32 67
         longitude={this.props.longitude}