addPolyline method

Future<void> addPolyline (List<LatLng> points, { double width, Color strokeColor: Colors.black })

添加线

在点points的位置添加线, 可以设置宽度width和颜色strokeColor

Implementation

Future<void> addPolyline(
  List<LatLng> points, {
  double width,
  Color strokeColor = Colors.black,
}) {
  return platform(
    android: (pool) async {
      final map = await _androidController.getMap();

      // 构造折线点
      List<com_amap_api_maps_model_LatLng> latLngList = [];
      for (final point in points) {
        final latLng = await ObjectFactory_Android
            .createcom_amap_api_maps_model_LatLng__double__double(
                point.lat, point.lng);
        latLngList.add(latLng);
      }

      // 构造折线参数
      final polylineOptions = await ObjectFactory_Android
          .createcom_amap_api_maps_model_PolylineOptions__();

      // 添加参数
      await polylineOptions.addAll(latLngList);
      if (width != null) {
        await polylineOptions.width(width);
      }
      if (strokeColor != null) {
        await polylineOptions
            .color(Int32List.fromList([strokeColor.value])[0]);
      }

      // 设置参数
      await map.addPolyline(polylineOptions);

      pool
        ..add(map)
        ..add(polylineOptions)
        ..addAll(latLngList);
    },
    ios: (pool) async {
      await _iosController.set_delegate(_IOSMapDelegate());

      // 构造折线点
      List<CLLocationCoordinate2D> latLngList = [];
      for (final point in points) {
        final latLng = await ObjectFactory_iOS.createCLLocationCoordinate2D(
            point.lat, point.lng);
        latLngList.add(latLng);
      }

      // 构造折线参数
      final polyline = await MAPolyline.polylineWithCoordinatesCount(
          latLngList, latLngList.length);

      // 宽度和颜色需要设置到STACK里去
      if (width != null)
        await ObjectFactory_iOS.pushStackJsonable('width', width);
      if (strokeColor != null)
        await ObjectFactory_iOS.pushStackJsonable(
            'strokeColor', strokeColor.value);

      // 设置参数
      await _iosController.addOverlay(polyline);

      pool
        ..add(polyline)
        ..addAll(latLngList);
    },
  );
}