drawRoad method

Future<RoadInfo> drawRoad(
  1. GeoPoint start,
  2. GeoPoint end, {
  3. RoadType roadType = RoadType.car,
  4. List<GeoPoint>? interestPoints,
  5. RoadOption? roadOption,
})
inherited

Implementation

Future<RoadInfo> drawRoad(
  GeoPoint start,
  GeoPoint end, {
  RoadType roadType = RoadType.car,
  List<GeoPoint>? interestPoints,
  RoadOption? roadOption,
}) async {
  final geoPoints = [start, end];
  if (interestPoints != null && interestPoints.isNotEmpty) {
    geoPoints.insertAll(1, interestPoints);
  }
  final waypoints = geoPoints.toLngLatList();
  final road = await manager.getRoute(
    request: routing.OSRMRequest.route(
      waypoints: waypoints,
      routingType: switch (roadType) {
        RoadType.car => routing.RoutingType.car,
        RoadType.foot => routing.RoutingType.foot,
        RoadType.bike => routing.RoutingType.bike,
      },
      geometries: routing.Geometries.geojson,
    ),
  );
  final path = road.polyline ?? const <routing.LngLat>[];
  final routeJs = path.mapToListGeoJS();

  var roadInfo = RoadInfo();
  final roadConfig =
      roadOption ?? defaultRoadOption ?? const RoadOption.empty();
  debugPrint(roadOption?.toString());

  interop.drawRoad(
    mapIdMixin.toJS,
    roadInfo.key.toJS,
    routeJs.toJS,
    (interestPoints?.toListGeoPointJs() ?? []).toJS,
    roadConfig.toRoadOptionJS,
  );
  final instructions = road.instructions;
  roadInfo = roadInfo.copyWith(
    duration: road.duration,
    distance: road.distance,
    instructions: instructions
        .map((e) => Instruction(
              instruction: e.instruction,
              geoPoint: e.location.toGeoPoint(),
            ))
        .toList(),
    route: path.mapToListGeoPoints(),
  );
  roadsWebCache[roadInfo.key] = roadInfo;
  return roadInfo;
}