|
@@ -2,6 +2,9 @@ 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
|
+
|
5
|
8
|
function ObjEqual (a = {}, b = {}) { return JSON.stringify(a) === JSON.stringify(b) }
|
6
|
9
|
|
7
|
10
|
export default class PoiAround extends Component {
|
|
@@ -13,17 +16,18 @@ export default class PoiAround extends Component {
|
13
|
16
|
|
14
|
17
|
componentWillReceiveProps (nextProps) {
|
15
|
18
|
if (this.map) {
|
16
|
|
- if (!ObjEqual(nextProps.markers, this.props.markers)) {
|
17
|
|
- const tk = setTimeout(() => {
|
18
|
|
- this.map.moveToLocation()
|
19
|
|
- console.log(this.map)
|
20
|
|
- clearTimeout(tk)
|
21
|
|
- }, 1000)
|
|
19
|
+ if (!ObjEqual(nextProps.markers, this.props.markers)) {
|
|
20
|
+ this.map.moveToLocation({
|
|
21
|
+ latitude: nextProps.latitude,
|
|
22
|
+ longitude: nextProps.longitude,
|
|
23
|
+ })
|
22
|
24
|
}
|
23
|
25
|
}
|
24
|
26
|
}
|
25
|
27
|
|
26
|
28
|
handleTap = (e) => {
|
|
29
|
+ if (e.markerId === centerProject) return;
|
|
30
|
+
|
27
|
31
|
const marker = this.props.markers.filter(x => x.id === e.markerId)[0]
|
28
|
32
|
this.props.onMarkerClick && this.props.onMarkerClick(marker)
|
29
|
33
|
}
|
|
@@ -43,6 +47,16 @@ export default class PoiAround extends Component {
|
43
|
47
|
}
|
44
|
48
|
})
|
45
|
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
|
+
|
46
|
60
|
return this.props.longitude && (
|
47
|
61
|
<Map
|
48
|
62
|
id="poi-around"
|