1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
import 'package:amap_flutter_map_example/base_page.dart';
import 'package:amap_flutter_map_example/const_config.dart';
import 'package:flutter/material.dart';
import 'package:amap_flutter_map/amap_flutter_map.dart';
class ShowMapPage extends BasePage {
ShowMapPage(String title, String subTitle) : super(title, subTitle);
@override
Widget build(BuildContext context) {
return _ShowMapPageBody();
}
}
class _ShowMapPageBody extends StatefulWidget {
@override
State<StatefulWidget> createState() => _ShowMapPageState();
}
class _ShowMapPageState extends State<_ShowMapPageBody> {
List<Widget> _approvalNumberWidget = <Widget>[];
var _searchController = TextEditingController();
List<PoiItem> _poiList = [];
List<InputTipsItem> _inputTipsList = [];
@override
Widget build(BuildContext context) {
final AMapWidget map = AMapWidget(
apiKey: ConstConfig.amapApiKeys,
onMapCreated: onMapCreated,
onCameraMoveEnd: onCameraMoveEnd,
onMapSearchPOI: onMapSearchPOI,
onMapSearchInputTips: onMapSearchInput,
onMapSearchRegeocode: onMapSearchRegeocode,
);
return ConstrainedBox(
constraints: BoxConstraints.expand(),
child: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: map,
),
Positioned(
right: 10,
bottom: 15,
child: Container(
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: _approvalNumberWidget),
),
),
Positioned(
child: Container(
constraints: BoxConstraints(maxHeight: 260.0),
padding: EdgeInsets.symmetric(horizontal: 20.0),
color: Color(0xC0FFFFFF),
child: Column(
children: [
Row(
children: [
showSelectSearch(),
Expanded(
child: TextField(
controller: _searchController,
maxLines: 1,
textInputAction: TextInputAction.search,
decoration: InputDecoration(
hintText: "搜索",
),
onSubmitted: (value) {
switch (selectedSearch) {
case "inputTips":
_mapController.searchInput(value);
break;
default: // "poi"
_mapController.searchPoi(value,0);
}
},
),
),
],
),
Expanded(
child: ListView.builder(
itemCount: selectedSearch == "inputTips"
? _inputTipsList.length
: _poiList.length,
itemBuilder: (BuildContext context, int index) {
return itemWidget(index);
},
),
),
],
),
),
)
],
),
);
}
late AMapController _mapController;
void onMapCreated(AMapController controller) {
setState(() {
_mapController = controller;
getApprovalNumber();
});
}
void onCameraMoveEnd(CameraPosition position) {
print("经纬度: ${position.target.longitude}, ${position.target.latitude}");
_mapController.searchPoi("",1,latitude: position.target.latitude,longitude: position.target.longitude);
}
void onMapSearchPOI(PoiResult poi) {
_poiList.clear();
if (poi.poiList != null && poi.poiList!.length > 0) {
_poiList.addAll(poi.poiList!);
}
setState(() {});
}
void onMapSearchInput(InputTipsResult tips) {
_inputTipsList.clear();
if (tips.inputTipsList != null && tips.inputTipsList!.length > 0) {
_inputTipsList.addAll(tips.inputTipsList!);
}
setState(() {});
}
void onMapSearchRegeocode(RegeocodeResult result) {
print('----- result = ${result.province} ${result.city} ${result.district} ${result.town} ${result.street} ${result.address}');
}
Widget itemWidget(int index) {
switch (selectedSearch) {
case "inputTips":
var data = _inputTipsList[index];
return InkWell(
onTap: () {
_mapController.searchRegeocode(
data.latitude?.toDouble() ?? 39.963142,
data.longitude?.toDouble() ?? 116.382644);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("${data.district}${data.address}${data.name}"),
PopupMenuDivider(),
],
),
);
default: // "poi"
var data = _poiList[index];
return InkWell(
onTap: () {
_mapController.searchRegeocode(
data.latitude?.toDouble() ?? 39.963142,
data.longitude?.toDouble() ?? 116.382644);
},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"${data.provinceName} ${data.cityName} ${data.adName} ${data.snippet} ${data.title}"),
PopupMenuDivider(),
],
),
);
}
}
/// 获取审图号
void getApprovalNumber() async {
//普通地图审图号
String mapContentApprovalNumber =
(await _mapController.getMapContentApprovalNumber())!;
//卫星地图审图号
String satelliteImageApprovalNumber =
(await _mapController.getSatelliteImageApprovalNumber())!;
var map = await _mapController.getVisibleRegion();
print(map); //获取地图可视区域
setState(() {
_approvalNumberWidget.add(Text(mapContentApprovalNumber));
_approvalNumberWidget.add(Text(satelliteImageApprovalNumber));
});
print('地图审图号(普通地图): $mapContentApprovalNumber');
print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
}
var selectedSearch = "poi";
Widget showSelectSearch() {
return Row(
children: [
Container(
width: 50.0,
child: PopupMenuButton<String>(
iconSize: 0.0,
child: Text(
"$selectedSearch",
textAlign: TextAlign.center,
style: TextStyle(overflow: TextOverflow.ellipsis),
),
offset: Offset(-50.0, 50.0),
onSelected: (value) {
print('----- value = $value');
selectedSearch = value;
setState(() {});
},
itemBuilder: (context) {
return <PopupMenuEntry<String>>[
PopupMenuItem<String>(
value: 'poi',
child: Text('poi', textAlign: TextAlign.center),
),
PopupMenuDivider(),
PopupMenuItem<String>(
value: 'inputTips',
child: Text('inputTips', textAlign: TextAlign.center),
),
];
},
),
),
Icon(Icons.arrow_drop_down),
],
);
}
}