|
@@ -7,7 +7,9 @@ class Amap extends React.Component {
|
7
|
7
|
|
8
|
8
|
constructor(props) {
|
9
|
9
|
super(props);
|
10
|
|
-
|
|
10
|
+ this.state = {
|
|
11
|
+ markerPosition: { longitude: 120, latitude: 35 },
|
|
12
|
+ }
|
11
|
13
|
// 高德地图 Marker 实例
|
12
|
14
|
this.markerInstance = undefined
|
13
|
15
|
// 高德地图 Map 实例
|
|
@@ -78,40 +80,25 @@ class Amap extends React.Component {
|
78
|
80
|
this.markerInstance = markerInstance
|
79
|
81
|
},
|
80
|
82
|
}
|
81
|
|
- this.markerPosition = { longitude: 120, latitude: 30 };
|
82
|
|
- const { value } = this.props
|
83
|
|
- console.log('项目地图 value', value)
|
84
|
|
-
|
85
|
|
-
|
86
|
|
-
|
87
|
|
- this.setMapPosition.bind(this)
|
|
83
|
+ // this.markerPosition = { longitude: 120, latitude: 30 };
|
88
|
84
|
}
|
89
|
85
|
|
90
|
86
|
componentDidUpdate(prevProps) {
|
91
|
87
|
const { value } = this.props
|
92
|
|
- // console.log('项目地图 value', value)
|
93
|
|
- console.log('this.markerInstance: ', this.markerInstance, this.props)
|
94
|
88
|
if (this.props.value !== prevProps.value) {
|
95
|
89
|
if (value) {
|
96
|
|
- console.log('项目地图 value', value)
|
97
|
|
- this.setMapPosition(value)
|
|
90
|
+ const temp = value.split(',')
|
|
91
|
+ this.setState({ markerPosition: { longitude: temp[1], latitude: temp[0] } })
|
98
|
92
|
}
|
99
|
93
|
}
|
100
|
94
|
}
|
101
|
95
|
|
102
|
|
- setMapPosition(value) {
|
103
|
|
- console.log('获取this:', this.markerInstance)
|
104
|
|
- if (this.markerInstance) {
|
105
|
|
- // this.markerInstance.setPosition(value)
|
106
|
|
- }
|
107
|
|
- }
|
108
|
|
-
|
109
|
96
|
render() {
|
110
|
97
|
return (
|
111
|
98
|
<>
|
112
|
99
|
<div style={{ width: '100%', height: '400px', position: 'relative' }}>
|
113
|
100
|
<Map events={this.amapEvents} amapkey="f0d1d4f82432504003ebf46e5e36ff03">
|
114
|
|
- <Marker position={this.markerPosition} events={this.markerEvents} />
|
|
101
|
+ <Marker position={this.state.markerPosition} events={this.markerEvents} />
|
115
|
102
|
</Map>
|
116
|
103
|
{
|
117
|
104
|
<div className={styles.infoBox}>
|