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
import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:amap_flutter_map_example/base_page.dart';
import 'package:amap_flutter_map_example/const_config.dart';
import 'package:flutter/material.dart';
class MinMaxZoomDemoPage extends BasePage {
MinMaxZoomDemoPage(String title, String subTitle) : super(title, subTitle);
@override
Widget build(BuildContext context) => _Body();
}
class _Body extends StatefulWidget {
_Body({Key? key}) : super(key: key);
@override
_BodyState createState() => _BodyState();
}
class _BodyState extends State<_Body> {
final double _minZoom = 10;
final double _maxZoom = 15;
String? _currentZoom;
late AMapController _mapController;
@override
Widget build(BuildContext context) {
final AMapWidget amap = AMapWidget(
apiKey: ConstConfig.amapApiKeys,
onMapCreated: _onMapCreated,
onCameraMove: _onCameraMove,
onCameraMoveEnd: _onCameraMoveEnd,
minMaxZoomPreference: MinMaxZoomPreference(_minZoom, _maxZoom),
);
return ConstrainedBox(
constraints: BoxConstraints.expand(),
child: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: amap,
),
Positioned(
top: 5,
left: 15,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: MediaQuery.of(context).size.width,
color: Colors.grey,
padding: EdgeInsets.all(5),
alignment: Alignment.centerLeft,
child: Text(
'当前限制的最小最大缩放级别是:[$_minZoom, $_maxZoom]',
style: TextStyle(color: Colors.blue),
),
),
_currentZoom != null
? Container(
width: MediaQuery.of(context).size.width,
color: Colors.grey,
padding: EdgeInsets.all(5),
alignment: Alignment.centerLeft,
child: Text(
_currentZoom!,
style: TextStyle(color: Colors.white),
))
: SizedBox(),
],
),
),
Positioned(
right: 5,
bottom: 5,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
InkResponse(
child: Container(
child: Icon(
Icons.add,
color: Colors.white,
),
width: 40,
height: 40,
color: Colors.blue,
),
onTap: _zoomIn,
),
InkResponse(
child: Container(
child: Icon(
Icons.remove,
color: Colors.white,
),
color: Colors.blue,
width: 40,
height: 40,
),
onTap: _zoomOut,
),
],
),
),
],
),
);
}
void _onMapCreated(AMapController controller) {
_mapController = controller;
}
//移动视野
void _onCameraMove(CameraPosition cameraPosition) {}
//移动地图结束
void _onCameraMoveEnd(CameraPosition cameraPosition) {
setState(() {
_currentZoom = '当前缩放级别:${cameraPosition.zoom}';
});
}
//级别加1
void _zoomIn() {
_mapController.moveCamera(
CameraUpdate.zoomIn(),
animated: true,
);
}
//级别减1
void _zoomOut() {
_mapController.moveCamera(
CameraUpdate.zoomOut(),
animated: true,
);
}
}