|
@@ -18,8 +18,9 @@ class Amap extends React.Component {
|
18
|
18
|
this.amapEvents = {
|
19
|
19
|
created: mapInstance => {
|
20
|
20
|
console.log('高德地图 Map 实例创建成功;如果你要亲自对实例进行操作,可以从这里开始。比如:');
|
21
|
|
- console.log(mapInstance.getZoom());
|
|
21
|
+ console.log('缩放级别:', mapInstance.getZoom());
|
22
|
22
|
this.mapInstance = mapInstance
|
|
23
|
+
|
23
|
24
|
|
24
|
25
|
AMap.plugin(['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.CitySearch'], () => {
|
25
|
26
|
// 实例化Autocomplete
|
|
@@ -33,7 +34,7 @@ class Amap extends React.Component {
|
33
|
34
|
// 无需再手动执行search方法,autoComplete会根据传入input对应的DOM动态触发search
|
34
|
35
|
|
35
|
36
|
const placeSearch = new AMap.PlaceSearch({
|
36
|
|
- city: '南京',
|
|
37
|
+ // city: '南京',
|
37
|
38
|
map: mapInstance,
|
38
|
39
|
})
|
39
|
40
|
|
|
@@ -59,6 +60,8 @@ class Amap extends React.Component {
|
59
|
60
|
// document.getElementById('info').innerHTML = '您当前所在城市:'+cityinfo;
|
60
|
61
|
// 地图显示当前城市
|
61
|
62
|
mapInstance.setBounds(citybounds);
|
|
63
|
+ // 需要在设置坐标成功后,重新设置 缩放级别
|
|
64
|
+ // mapInstance.setZoom(15)
|
62
|
65
|
}
|
63
|
66
|
}
|
64
|
67
|
})
|
|
@@ -89,6 +92,9 @@ class Amap extends React.Component {
|
89
|
92
|
if (value) {
|
90
|
93
|
const temp = value.split(',')
|
91
|
94
|
this.setState({ markerPosition: { longitude: temp[1], latitude: temp[0] } })
|
|
95
|
+
|
|
96
|
+ // 需要在设置坐标成功后,重新设置 缩放级别
|
|
97
|
+ this.mapInstance.setZoom(15)
|
92
|
98
|
}
|
93
|
99
|
}
|
94
|
100
|
}
|
|
@@ -97,7 +103,8 @@ class Amap extends React.Component {
|
97
|
103
|
return (
|
98
|
104
|
<>
|
99
|
105
|
<div style={{ width: '100%', height: '400px', position: 'relative' }}>
|
100
|
|
- <Map events={this.amapEvents} amapkey="f0d1d4f82432504003ebf46e5e36ff03">
|
|
106
|
+ {/* zoom={15} 设置后,无效,不知道什么原因,必须手动设置 */}
|
|
107
|
+ <Map plugins={['ToolBar']} events={this.amapEvents} amapkey="f0d1d4f82432504003ebf46e5e36ff03" center={this.state.markerPosition}>
|
101
|
108
|
<Marker position={this.state.markerPosition} events={this.markerEvents} />
|
102
|
109
|
</Map>
|
103
|
110
|
{
|