getOSRMRoad method

Future<OSRMRoad> getOSRMRoad(
  1. OSRMRequest request
)

Implementation

Future<OSRMRoad> getOSRMRoad(OSRMRequest request) async {
  final urlOption = request.encodeHeader();
  final response = await dio.get(dio.options.baseUrl + urlOption);
  final Map<String, dynamic> responseJson = Map.from(response.data);
  if (response.statusCode != null && response.statusCode! > 299 ||
      response.statusCode! < 200) {
    return OSRMRoad.withError();
  }
  final instructionsHelper =
      await loadInstructionHelperJson(language: request.languages);
  final computeData =
      (json: responseJson, request: request, helper: instructionsHelper);
  return compute(
    (message) async {
      final route = await switch (message.request.profile) {
        Profile.route => parseRoad(
            ParserRoadComputeArg(
              json: message.json,
              langCode: message.request.languages.code,
              alternative: request.hasAlternative ?? false,
            ),
          ),
        Profile.trip => parseTrip(
            ParserTripComputeArg(
              tripJson: message.json,
              langCode: message.request.languages.code,
            ),
          ),
      };
      final instructions = OSRMHelper.buildInstructions(
        road: route,
        instructionsHelper: message.helper,
      );
      return route.copyWith(
        instructions: instructions,
      );
    },
    computeData,
  );
}