import 'package:amap_flutter_map/amap_flutter_map.dart';
import 'package:amap_flutter_base/amap_flutter_base.dart';
import 'package:flutter/widgets.dart';

import 'package:farmer_client/utils/amap/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!,
        icon: BitmapDescriptor.fromIconPath("images/locationImage.png")
      );
      _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(32.687732, 112.08745)),
    );
  }

}