123456789101112131415161718192021222324252627282930313233343536373839404142 |
- import 'package:amap_flutter_map/amap_flutter_map.dart';
- import 'package:amap_flutter_base/amap_flutter_base.dart';
- import 'package:flutter/widgets.dart';
-
- import 'const_config.dart';
-
- // https://developer.amap.com/api/flutter/guide/map-flutter-plug-in/map-flutter-info
- class AMap extends StatelessWidget {
- late AMapController _mapController;
- final LatLng? position;
- final Map<String, Marker> _markers = Map<String, Marker>();
-
- AMap({Key? key, this.position }): super(key: key);
-
- void onMapCreated(AMapController controller) {
- _mapController = controller;
- }
-
- void _initMarkers() {
- if (null != position) {
- Marker marker = Marker(
- position: position!,
- //使用默认hue的方式设置Marker的图标
- icon: BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueOrange),
- );
- _markers[marker.id] = marker;
- }
- }
-
- @override
- Widget build(BuildContext context) {
- _initMarkers();
-
- return AMapWidget(
- privacyStatement: ConstConfig.amapPrivacyStatement,
- apiKey: ConstConfig.amapApiKeys,
- markers: Set<Marker>.of(_markers.values),
- initialCameraPosition: const CameraPosition(target: LatLng(31.230378, 121.473658)),
- );
- }
-
- }
|