init project
This commit is contained in:
78
example/lib/pages/map/change_map_type.dart
Normal file
78
example/lib/pages/map/change_map_type.dart
Normal file
@ -0,0 +1,78 @@
|
||||
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_radio_group.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ChangeMapTypePage extends BasePage {
|
||||
ChangeMapTypePage(String title, String subTitle) : super(title, subTitle);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _PageBody();
|
||||
}
|
||||
|
||||
class _PageBody extends StatefulWidget {
|
||||
_PageBody({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_PageBodyState createState() => _PageBodyState();
|
||||
}
|
||||
|
||||
class _PageBodyState extends State<_PageBody> {
|
||||
//地图类型
|
||||
late MapType _mapType;
|
||||
final Map<String, MapType> _radioValueMap = {
|
||||
'普通地图': MapType.normal,
|
||||
'卫星地图': MapType.satellite,
|
||||
'导航地图': MapType.navi,
|
||||
'公交地图': MapType.bus,
|
||||
'黑夜模式': MapType.night,
|
||||
};
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_mapType = MapType.normal;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//创建地图
|
||||
final AMapWidget map = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
//地图类型属性
|
||||
mapType: _mapType,
|
||||
);
|
||||
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: AMapRadioGroup(
|
||||
groupLabel: '地图样式',
|
||||
groupValue: _mapType,
|
||||
radioValueMap: _radioValueMap,
|
||||
onChanged: (value) => {
|
||||
//改变当前地图样式为选中的样式
|
||||
setState(() {
|
||||
_mapType = value as MapType;
|
||||
})
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
94
example/lib/pages/map/custom_map_style.dart
Normal file
94
example/lib/pages/map/custom_map_style.dart
Normal file
@ -0,0 +1,94 @@
|
||||
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:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class CustomMapStylePage extends BasePage {
|
||||
CustomMapStylePage(String title, String subTitle) : super(title, subTitle);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => _CustomMapStyleBody();
|
||||
}
|
||||
|
||||
class _CustomMapStyleBody extends StatefulWidget {
|
||||
_CustomMapStyleBody({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CustomMapStyleState createState() => _CustomMapStyleState();
|
||||
}
|
||||
|
||||
class _CustomMapStyleState extends State<_CustomMapStyleBody> {
|
||||
bool _mapCreated = false;
|
||||
|
||||
CustomStyleOptions _customStyleOptions = CustomStyleOptions(false);
|
||||
//加载自定义地图样式
|
||||
void _loadCustomData() async {
|
||||
ByteData styleByteData = await rootBundle.load('assets/style.data');
|
||||
_customStyleOptions.styleData = styleByteData.buffer.asUint8List();
|
||||
ByteData styleExtraByteData =
|
||||
await rootBundle.load('assets/style_extra.data');
|
||||
_customStyleOptions.styleExtraData =
|
||||
styleExtraByteData.buffer.asUint8List();
|
||||
//如果需要加载完成后直接展示自定义地图,可以通过setState修改CustomStyleOptions的enable为true
|
||||
// setState(() {
|
||||
// _customStyleOptions.enabled = true;
|
||||
// });
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadCustomData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
onMapCreated: onMapCreated,
|
||||
customStyleOptions: _customStyleOptions,
|
||||
);
|
||||
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: map,
|
||||
),
|
||||
Positioned(
|
||||
top: 30,
|
||||
child: Container(
|
||||
color: Color(0xFF00BFFF),
|
||||
child: AMapSwitchButton(
|
||||
label: Text(
|
||||
'自定义地图',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
defaultValue: _customStyleOptions.enabled,
|
||||
onSwitchChanged: (value) => {
|
||||
if (_mapCreated)
|
||||
{
|
||||
setState(() {
|
||||
_customStyleOptions.enabled = value;
|
||||
})
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onMapCreated(AMapController controller) {
|
||||
_mapCreated = true;
|
||||
}
|
||||
}
|
34
example/lib/pages/map/limit_map_bounds.dart
Normal file
34
example/lib/pages/map/limit_map_bounds.dart
Normal file
@ -0,0 +1,34 @@
|
||||
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 LimitMapBoundsPage extends BasePage {
|
||||
LimitMapBoundsPage(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> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget amap = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
limitBounds: LatLngBounds(
|
||||
southwest: LatLng(39.83309, 116.290176),
|
||||
northeast: LatLng(39.99951, 116.501663)),
|
||||
);
|
||||
return Container(
|
||||
child: amap,
|
||||
);
|
||||
}
|
||||
}
|
426
example/lib/pages/map/map_all_config.dart
Normal file
426
example/lib/pages/map/map_all_config.dart
Normal file
@ -0,0 +1,426 @@
|
||||
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:amap_map_example/widgets/amap_switch_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
|
||||
class AllMapConfigDemoPage extends BasePage {
|
||||
AllMapConfigDemoPage(String title, String subTitle) : super(title, subTitle);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return _MapUiBody();
|
||||
}
|
||||
}
|
||||
|
||||
class _MapUiBody extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() => _MapUiBodyState();
|
||||
}
|
||||
|
||||
class _MapUiBodyState extends State<_MapUiBody> {
|
||||
//默认显示在北京天安门
|
||||
static final CameraPosition _kInitialPosition = const CameraPosition(
|
||||
target: LatLng(39.909187, 116.397451),
|
||||
zoom: 10.0,
|
||||
);
|
||||
|
||||
///地图类型
|
||||
MapType _mapType = MapType.normal;
|
||||
|
||||
///显示路况开关
|
||||
bool _trafficEnabled = false;
|
||||
|
||||
/// 地图poi是否允许点击
|
||||
bool _touchPoiEnabled = false;
|
||||
|
||||
///是否显示3D建筑物
|
||||
bool _buildingsEnabled = true;
|
||||
|
||||
///是否显示底图文字标注
|
||||
bool _labelsEnabled = true;
|
||||
|
||||
///是否显示指南针
|
||||
bool _compassEnabled = false;
|
||||
|
||||
///是否显示比例尺
|
||||
bool _scaleEnabled = true;
|
||||
|
||||
///是否支持缩放手势
|
||||
bool _zoomGesturesEnabled = true;
|
||||
|
||||
///是否支持滑动手势
|
||||
bool _scrollGesturesEnabled = true;
|
||||
|
||||
///是否支持旋转手势
|
||||
bool _rotateGesturesEnabled = true;
|
||||
|
||||
///是否支持倾斜手势
|
||||
bool _tiltGesturesEnabled = true;
|
||||
|
||||
late AMapController _controller;
|
||||
|
||||
CustomStyleOptions _customStyleOptions = CustomStyleOptions(false);
|
||||
|
||||
///自定义定位小蓝点
|
||||
MyLocationStyleOptions _myLocationStyleOptions =
|
||||
MyLocationStyleOptions(false);
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadCustomData();
|
||||
}
|
||||
|
||||
void _loadCustomData() async {
|
||||
ByteData styleByteData = await rootBundle.load('assets/style.data');
|
||||
_customStyleOptions.styleData = styleByteData.buffer.asUint8List();
|
||||
ByteData styleExtraByteData =
|
||||
await rootBundle.load('assets/style_extra.data');
|
||||
_customStyleOptions.styleExtraData =
|
||||
styleExtraByteData.buffer.asUint8List();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
///必须正确设置的合规隐私声明,否则SDK不会工作,会造成地图白屏等问题。
|
||||
privacyStatement: ConstConfig.amapPrivacyStatement,
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
initialCameraPosition: _kInitialPosition,
|
||||
mapType: _mapType,
|
||||
trafficEnabled: _trafficEnabled,
|
||||
buildingsEnabled: _buildingsEnabled,
|
||||
compassEnabled: _compassEnabled,
|
||||
labelsEnabled: _labelsEnabled,
|
||||
scaleEnabled: _scaleEnabled,
|
||||
touchPoiEnabled: _touchPoiEnabled,
|
||||
rotateGesturesEnabled: _rotateGesturesEnabled,
|
||||
scrollGesturesEnabled: _scrollGesturesEnabled,
|
||||
tiltGesturesEnabled: _tiltGesturesEnabled,
|
||||
zoomGesturesEnabled: _zoomGesturesEnabled,
|
||||
onMapCreated: onMapCreated,
|
||||
customStyleOptions: _customStyleOptions,
|
||||
myLocationStyleOptions: _myLocationStyleOptions,
|
||||
onLocationChanged: _onLocationChanged,
|
||||
onCameraMove: _onCameraMove,
|
||||
onCameraMoveEnd: _onCameraMoveEnd,
|
||||
onTap: _onMapTap,
|
||||
onLongPress: _onMapLongPress,
|
||||
onPoiTouched: _onMapPoiTouched,
|
||||
);
|
||||
|
||||
Widget _mapTypeRadio(String label, MapType radioValue) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(label),
|
||||
Radio(
|
||||
value: radioValue,
|
||||
groupValue: _mapType,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_mapType = value as MapType;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
final List<Widget> _mapTypeList = [
|
||||
_mapTypeRadio('普通地图', MapType.normal),
|
||||
_mapTypeRadio('卫星地图', MapType.satellite),
|
||||
_mapTypeRadio('导航地图', MapType.navi),
|
||||
_mapTypeRadio('公交地图', MapType.bus),
|
||||
_mapTypeRadio('黑夜模式', MapType.night),
|
||||
];
|
||||
|
||||
//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;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('点击Poi'),
|
||||
defaultValue: _touchPoiEnabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_touchPoiEnabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
AMapSwitchButton(
|
||||
label: Text('自定义地图'),
|
||||
defaultValue: _customStyleOptions.enabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_customStyleOptions.enabled = value;
|
||||
})
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
//手势开关
|
||||
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 _mapTypeOptions() {
|
||||
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: createGridView(_mapTypeList),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _myLocationStyleContainer() {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(5),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
// Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
AMapSwitchButton(
|
||||
label:
|
||||
Text('定位小蓝点', style: TextStyle(fontWeight: FontWeight.w600)),
|
||||
defaultValue: _myLocationStyleOptions.enabled,
|
||||
onSwitchChanged: (value) => {
|
||||
setState(() {
|
||||
_myLocationStyleOptions.enabled = 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: createGridView(_uiOptions),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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: createGridView(gesturesOptions),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _optionsItem() {
|
||||
return Column(
|
||||
children: [
|
||||
_mapTypeOptions(),
|
||||
_myLocationStyleContainer(),
|
||||
_uiOptionsWidget(),
|
||||
_gesturesOptiosWeidget(),
|
||||
TextButton(
|
||||
child: const Text('moveCamera到首开'),
|
||||
onPressed: _moveCameraToShoukai,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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: _optionsItem(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onMapCreated(AMapController controller) {
|
||||
setState(() {
|
||||
_controller = controller;
|
||||
printApprovalNumber();
|
||||
});
|
||||
}
|
||||
|
||||
void printApprovalNumber() async {
|
||||
String mapContentApprovalNumber =
|
||||
(await _controller.getMapContentApprovalNumber())!;
|
||||
String satelliteImageApprovalNumber =
|
||||
(await _controller.getSatelliteImageApprovalNumber())!;
|
||||
print('地图审图号(普通地图): $mapContentApprovalNumber');
|
||||
print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
|
||||
}
|
||||
|
||||
Widget createGridView(List<Widget> widgets) {
|
||||
return GridView.count(
|
||||
primary: false,
|
||||
physics: new NeverScrollableScrollPhysics(),
|
||||
//水平子Widget之间间距
|
||||
crossAxisSpacing: 1.0,
|
||||
//垂直子Widget之间间距
|
||||
mainAxisSpacing: 0.5,
|
||||
//一行的Widget数量
|
||||
crossAxisCount: 2,
|
||||
//宽高比
|
||||
childAspectRatio: 4,
|
||||
children: widgets,
|
||||
shrinkWrap: true);
|
||||
}
|
||||
|
||||
//移动地图中心点到首开广场
|
||||
void _moveCameraToShoukai() {
|
||||
_controller.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
|
||||
target: LatLng(39.993306, 116.473004),
|
||||
zoom: 18,
|
||||
tilt: 30,
|
||||
bearing: 30)));
|
||||
}
|
||||
|
||||
void _onLocationChanged(AMapLocation location) {
|
||||
print('_onLocationChanged ${location.toJson()}');
|
||||
}
|
||||
|
||||
void _onCameraMove(CameraPosition cameraPosition) {
|
||||
print('onCameraMove===> ${cameraPosition.toMap()}');
|
||||
}
|
||||
|
||||
void _onCameraMoveEnd(CameraPosition cameraPosition) {
|
||||
print('_onCameraMoveEnd===> ${cameraPosition.toMap()}');
|
||||
}
|
||||
|
||||
void _onMapTap(LatLng latLng) {
|
||||
print('_onMapTap===> ${latLng.toJson()}');
|
||||
}
|
||||
|
||||
void _onMapLongPress(LatLng latLng) {
|
||||
print('_onMapLongPress===> ${latLng.toJson()}');
|
||||
}
|
||||
|
||||
void _onMapPoiTouched(AMapPoi poi) {
|
||||
print('_onMapPoiTouched===> ${poi.toJson()}');
|
||||
}
|
||||
}
|
52
example/lib/pages/map/map_my_location.dart
Normal file
52
example/lib/pages/map/map_my_location.dart
Normal file
@ -0,0 +1,52 @@
|
||||
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';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class MyLocationPage extends BasePage {
|
||||
MyLocationPage(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> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_requestLocaitonPermission();
|
||||
}
|
||||
|
||||
@override
|
||||
void reassemble() {
|
||||
super.reassemble();
|
||||
_requestLocaitonPermission();
|
||||
}
|
||||
|
||||
void _requestLocaitonPermission() async {
|
||||
PermissionStatus status = await Permission.location.request();
|
||||
print('permissionStatus=====> $status');
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget amap = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
myLocationStyleOptions: MyLocationStyleOptions(
|
||||
true,
|
||||
circleFillColor: Colors.lightBlue,
|
||||
circleStrokeColor: Colors.blue,
|
||||
circleStrokeWidth: 1,
|
||||
),
|
||||
);
|
||||
return Container(
|
||||
child: amap,
|
||||
);
|
||||
}
|
||||
}
|
141
example/lib/pages/map/min_max_zoom.dart
Normal file
141
example/lib/pages/map/min_max_zoom.dart
Normal file
@ -0,0 +1,141 @@
|
||||
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 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,
|
||||
);
|
||||
}
|
||||
}
|
42
example/lib/pages/map/multi_map.dart
Normal file
42
example/lib/pages/map/multi_map.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map/amap_map.dart';
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MultiMapDemoPage extends BasePage {
|
||||
MultiMapDemoPage(String title, String subTitle) : super(title, subTitle);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const _MultiMapDemoBody();
|
||||
}
|
||||
}
|
||||
|
||||
class _MultiMapDemoBody extends StatefulWidget {
|
||||
const _MultiMapDemoBody();
|
||||
@override
|
||||
State<StatefulWidget> createState() => _MultiMapDemoState();
|
||||
}
|
||||
|
||||
class _MultiMapDemoState extends State<_MultiMapDemoBody> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Expanded(child: AMapWidget()),
|
||||
Padding(padding: EdgeInsets.all(5.0)),
|
||||
//第二个地图指定初始位置为上海
|
||||
Expanded(
|
||||
child: AMapWidget(
|
||||
initialCameraPosition:
|
||||
CameraPosition(target: LatLng(31.230378, 121.473658)),
|
||||
)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
76
example/lib/pages/map/show_map_page.dart
Normal file
76
example/lib/pages/map/show_map_page.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'package:amap_map_example/base_page.dart';
|
||||
import 'package:amap_map_example/const_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:amap_map/amap_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>[];
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final AMapWidget map = AMapWidget(
|
||||
apiKey: ConstConfig.amapApiKeys,
|
||||
onMapCreated: onMapCreated,
|
||||
);
|
||||
|
||||
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: map,
|
||||
),
|
||||
Positioned(
|
||||
right: 10,
|
||||
bottom: 15,
|
||||
child: Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: _approvalNumberWidget),
|
||||
))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
late AMapController _mapController;
|
||||
void onMapCreated(AMapController controller) {
|
||||
setState(() {
|
||||
_mapController = controller;
|
||||
getApprovalNumber();
|
||||
});
|
||||
}
|
||||
|
||||
/// 获取审图号
|
||||
void getApprovalNumber() async {
|
||||
//普通地图审图号
|
||||
String mapContentApprovalNumber =
|
||||
(await _mapController.getMapContentApprovalNumber())!;
|
||||
//卫星地图审图号
|
||||
String satelliteImageApprovalNumber =
|
||||
(await _mapController.getSatelliteImageApprovalNumber())!;
|
||||
setState(() {
|
||||
_approvalNumberWidget.add(Text(mapContentApprovalNumber));
|
||||
_approvalNumberWidget.add(Text(satelliteImageApprovalNumber));
|
||||
});
|
||||
print('地图审图号(普通地图): $mapContentApprovalNumber');
|
||||
print('地图审图号(卫星地图): $satelliteImageApprovalNumber');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user