魏熙美 5 лет назад
Родитель
Сommit
1040bd3f74
1 измененных файлов: 7 добавлений и 20 удалений
  1. 7
    20
      src/pages/building/list/add/components/amap.jsx

+ 7
- 20
src/pages/building/list/add/components/amap.jsx Просмотреть файл

7
 
7
 
8
   constructor(props) {
8
   constructor(props) {
9
     super(props);
9
     super(props);
10
-    
10
+    this.state = {
11
+      markerPosition: { longitude: 120, latitude: 35 },
12
+    }
11
     // 高德地图 Marker 实例
13
     // 高德地图 Marker 实例
12
     this.markerInstance = undefined
14
     this.markerInstance = undefined
13
     // 高德地图 Map 实例
15
     // 高德地图 Map 实例
78
         this.markerInstance = markerInstance
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
   componentDidUpdate(prevProps) {
86
   componentDidUpdate(prevProps) {
91
     const { value } = this.props
87
     const { value } = this.props
92
-    // console.log('项目地图 value', value)
93
-    console.log('this.markerInstance: ', this.markerInstance, this.props)
94
     if (this.props.value !== prevProps.value) {
88
     if (this.props.value !== prevProps.value) {
95
       if (value) {
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
   render() {
96
   render() {
110
     return (
97
     return (
111
       <>
98
       <>
112
         <div style={{ width: '100%', height: '400px', position: 'relative' }}>
99
         <div style={{ width: '100%', height: '400px', position: 'relative' }}>
113
           <Map events={this.amapEvents} amapkey="f0d1d4f82432504003ebf46e5e36ff03">
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
           </Map>
102
           </Map>
116
           {
103
           {
117
           <div className={styles.infoBox}>
104
           <div className={styles.infoBox}>