init project
This commit is contained in:
123
example/lib/pages/interactive/map_gestures_options.dart
Normal file
123
example/lib/pages/interactive/map_gestures_options.dart
Normal file
@ -0,0 +1,123 @@
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:amap_map_example/widgets/amap_gridview.dart';
|
||||
import 'package:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class GesturesDemoPage extends BasePage {
|
||||
GesturesDemoPage(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> {
|
||||
///是否支持缩放手势
|
||||
bool _zoomGesturesEnabled = true;
|
||||
|
||||
///是否支持滑动手势
|
||||
bool _scrollGesturesEnabled = true;
|
||||
|
||||
///是否支持旋转手势
|
||||
bool _rotateGesturesEnabled = true;
|
||||
|
||||
///是否支持倾斜手势
|
||||
bool _tiltGesturesEnabled = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
rotateGesturesEnabled: _rotateGesturesEnabled,
|
||||
scrollGesturesEnabled: _scrollGesturesEnabled,
|
||||
tiltGesturesEnabled: _tiltGesturesEnabled,
|
||||
zoomGesturesEnabled: _zoomGesturesEnabled,
|
||||
);
|
||||
|
||||
//手势开关
|
||||
final List<Widget> gesturesOptions = [
|
||||
AMapSwitchButton(
|
||||
label: Text('旋转'),
|
||||
defaultValue: _rotateGesturesEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_rotateGesturesEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('滑动'),
|
||||
defaultValue: _scrollGesturesEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_scrollGesturesEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('倾斜'),
|
||||
defaultValue: _tiltGesturesEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_tiltGesturesEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('缩放'),
|
||||
defaultValue: _zoomGesturesEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_zoomGesturesEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
];
|
||||
Widget _gesturesOptiosWeidget() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('手势控制', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: AMapGradView(childrenWidgets: gesturesOptions),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: map,
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Container(
|
||||
child: _gesturesOptiosWeidget(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
138
example/lib/pages/interactive/map_ui_options.dart
Normal file
138
example/lib/pages/interactive/map_ui_options.dart
Normal file
@ -0,0 +1,138 @@
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:amap_map_example/widgets/amap_gridview.dart';
|
||||
import 'package:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MapUIDemoPage extends BasePage {
|
||||
MapUIDemoPage(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> {
|
||||
///显示路况开关
|
||||
bool _trafficEnabled = false;
|
||||
|
||||
///是否显示3D建筑物
|
||||
bool _buildingsEnabled = true;
|
||||
|
||||
///是否显示底图文字标注
|
||||
bool _labelsEnabled = true;
|
||||
|
||||
///是否显示指南针
|
||||
bool _compassEnabled = false;
|
||||
|
||||
///是否显示比例尺
|
||||
bool _scaleEnabled = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
trafficEnabled: _trafficEnabled,
|
||||
buildingsEnabled: _buildingsEnabled,
|
||||
compassEnabled: _compassEnabled,
|
||||
labelsEnabled: _labelsEnabled,
|
||||
scaleEnabled: _scaleEnabled,
|
||||
);
|
||||
|
||||
//ui控制
|
||||
final List<Widget> _uiOptions = [
|
||||
AMapSwitchButton(
|
||||
label: Text('显示路况'),
|
||||
defaultValue: _trafficEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_trafficEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('显示3D建筑物'),
|
||||
defaultValue: _buildingsEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_buildingsEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('显示指南针'),
|
||||
defaultValue: _compassEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_compassEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('显示地图文字'),
|
||||
defaultValue: _labelsEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_labelsEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('显示比例尺'),
|
||||
defaultValue: _scaleEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_scaleEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
Widget _uiOptionsWidget() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('UI操作', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: AMapGradView(childrenWidgets: _uiOptions),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: map,
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Container(
|
||||
child: _uiOptionsWidget(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
236
example/lib/pages/interactive/move_camera_demo.dart
Normal file
236
example/lib/pages/interactive/move_camera_demo.dart
Normal file
@ -0,0 +1,236 @@
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:amap_map_example/widgets/amap_gridview.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MoveCameraDemoPage extends BasePage {
|
||||
MoveCameraDemoPage(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> {
|
||||
AMapController? _mapController;
|
||||
String? _currentZoom;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget amap = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
onMapCreated: _onMapCreated,
|
||||
onCameraMove: _onCameraMove,
|
||||
onCameraMoveEnd: _onCameraMoveEnd,
|
||||
);
|
||||
List<Widget> _optionsWidget = [
|
||||
_createMyFloatButton('改变显示区域', _changeLatLngBounds),
|
||||
_createMyFloatButton('改变中心点', _changeCameraPosition),
|
||||
_createMyFloatButton('改变缩放级别到18', _changeCameraZoom),
|
||||
_createMyFloatButton('按照像素移动地图', _scrollBy),
|
||||
];
|
||||
|
||||
Widget _cameraOptions() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
child: AMapGradView(
|
||||
childrenWidgets: _optionsWidget,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints.expand(),
|
||||
child: Column(
|
||||
children: [
|
||||
ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minWidth: MediaQuery.of(context).size.width,
|
||||
minHeight: MediaQuery.of(context).size.height * 0.7),
|
||||
child: Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: amap,
|
||||
),
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
_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(),
|
||||
Container(
|
||||
child: _cameraOptions(),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
void _onMapCreated(AMapController controller) {
|
||||
setState(() {
|
||||
_mapController = controller;
|
||||
});
|
||||
}
|
||||
|
||||
//移动视野
|
||||
void _onCameraMove(CameraPosition cameraPosition) {}
|
||||
|
||||
//移动地图结束
|
||||
void _onCameraMoveEnd(CameraPosition cameraPosition) {
|
||||
setState(() {
|
||||
_currentZoom = '当前缩放级别:${cameraPosition.zoom}';
|
||||
});
|
||||
}
|
||||
|
||||
void _changeCameraPosition() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.newCameraPosition(
|
||||
CameraPosition(
|
||||
//中心点
|
||||
target: LatLng(31.230378, 121.473658),
|
||||
//缩放级别
|
||||
zoom: 13,
|
||||
//俯仰角0°~45°(垂直与地图时为0)
|
||||
tilt: 30,
|
||||
//偏航角 0~360° (正北方为0)
|
||||
bearing: 0),
|
||||
),
|
||||
animated: true,
|
||||
);
|
||||
}
|
||||
|
||||
//改变显示级别
|
||||
void _changeCameraZoom() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.zoomTo(18),
|
||||
animated: true,
|
||||
);
|
||||
}
|
||||
|
||||
//级别加1
|
||||
void _zoomIn() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.zoomIn(),
|
||||
animated: true,
|
||||
);
|
||||
}
|
||||
|
||||
//级别减1
|
||||
void _zoomOut() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.zoomOut(),
|
||||
animated: true,
|
||||
);
|
||||
}
|
||||
|
||||
//改变显示区域
|
||||
void _changeLatLngBounds() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.newLatLngBounds(
|
||||
LatLngBounds(
|
||||
southwest: LatLng(33.789925, 104.838326),
|
||||
northeast: LatLng(38.740688, 114.647472)),
|
||||
15.0),
|
||||
animated: true,
|
||||
);
|
||||
}
|
||||
|
||||
//按照像素移动
|
||||
void _scrollBy() {
|
||||
_mapController?.moveCamera(
|
||||
CameraUpdate.scrollBy(50, 50),
|
||||
animated: true,
|
||||
duration: 1000,
|
||||
);
|
||||
}
|
||||
|
||||
TextButton _createMyFloatButton(String label, VoidCallback onPressed) {
|
||||
return TextButton(
|
||||
onPressed: onPressed,
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
return Colors.blue;
|
||||
}),
|
||||
),
|
||||
child: Text(label),
|
||||
);
|
||||
}
|
||||
}
|
69
example/lib/pages/interactive/poi_click_demo.dart
Normal file
69
example/lib/pages/interactive/poi_click_demo.dart
Normal file
@ -0,0 +1,69 @@
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PoiClickDemoPage extends BasePage {
|
||||
PoiClickDemoPage(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> {
|
||||
Widget? _poiInfo;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget amap = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
touchPoiEnabled: true,
|
||||
onPoiTouched: _onPoiTouched,
|
||||
);
|
||||
return ConstrainedBox(
|
||||
constraints: BoxConstraints.expand(),
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: amap,
|
||||
),
|
||||
Positioned(
|
||||
top: 40,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: 50,
|
||||
child: Container(
|
||||
child: _poiInfo,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget showPoiInfo(AMapPoi poi) {
|
||||
return Container(
|
||||
alignment: Alignment.center,
|
||||
color: Color(0x8200CCFF),
|
||||
child: Text(
|
||||
'您点击了 ${poi.name}',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _onPoiTouched(AMapPoi poi) {
|
||||
setState(() {
|
||||
_poiInfo = showPoiInfo(poi);
|
||||
});
|
||||
}
|
||||
}
|
85
example/lib/pages/interactive/snapshot_demo.dart
Normal file
85
example/lib/pages/interactive/snapshot_demo.dart
Normal file
@ -0,0 +1,85 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SnapshotPage extends BasePage {
|
||||
SnapshotPage(String title, String subTitle) : super(title, subTitle);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _SnapShotBody();
|
||||
}
|
||||
}
|
||||
|
||||
class _SnapShotBody extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _SnapShotState();
|
||||
}
|
||||
|
||||
class _SnapShotState extends State<_SnapShotBody> {
|
||||
AMapController? _mapController;
|
||||
Uint8List? _imageBytes;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
onMapCreated: _onMapCreated,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: SizedBox(
|
||||
height: 40,
|
||||
width: 100,
|
||||
child: TextButton(
|
||||
child: Text('截屏'),
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all(RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10))),
|
||||
//文字颜色
|
||||
foregroundColor: MaterialStateProperty.all(Colors.white),
|
||||
//水波纹颜色
|
||||
overlayColor: MaterialStateProperty.all(Colors.blueAccent),
|
||||
//背景颜色
|
||||
backgroundColor: MaterialStateProperty.resolveWith((states) {
|
||||
//设置按下时的背景颜色
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return Colors.blueAccent;
|
||||
}
|
||||
//默认背景颜色
|
||||
return Colors.blue;
|
||||
}),
|
||||
),
|
||||
onPressed: () async {
|
||||
final imageBytes = await _mapController?.takeSnapshot();
|
||||
setState(() {
|
||||
_imageBytes = imageBytes;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(color: Colors.blueGrey[50]),
|
||||
child: _imageBytes != null ? Image.memory(_imageBytes!) : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_onMapCreated(AMapController controller) {
|
||||
_mapController = controller;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user