Road.fromOSRMJson constructor

Road.fromOSRMJson({
  1. required Map route,
})

Implementation

Road.fromOSRMJson({
  required Map route,
})  : distance = (double.parse(route["distance"].toString())) / 1000,
      duration = double.parse(route["duration"].toString()),
      polylineEncoded = route["geometry"].runtimeType == String
          ? route["geometry"] as String
          : null {
  if ( route["geometry"] != null && route["geometry"].runtimeType != String) {
    final List<List<dynamic>> listOfPoints =
        List.castFrom(route["geometry"]["coordinates"]);

    polyline = listOfPoints
        .map((e) => LngLat(
              lng: e.first,
              lat: e.last,
            ))
        .toList();
  }
  if ((route).containsKey("legs")) {
    final List<Map<String, dynamic>> mapLegs = List.castFrom(route["legs"]);
    mapLegs.asMap().forEach((indexLeg, leg) {
      final RoadLeg legRoad = RoadLeg(
        parseToDouble(leg["distance"]),
        parseToDouble(leg["duration"]),
      );
      details.roadLegs.add(legRoad);
      if ((leg).containsKey("steps")) {
        final List<Map<String, dynamic>> steps = List.castFrom(leg["steps"]);
        //RoadInstruction? lastNode;
        var lastName = "";
        final List<RoadStep> roadSteps = [];
        for (var step in steps) {
          final roadStep = RoadStep.fromJson(step);
          roadSteps.add(roadStep);
          // String instruction = OSRMManager.

          if (roadStep.maneuver.maneuverType != "new name" &&
              lastName != roadStep.name) {
            //   lastNode.distance += distance;
            //   lastNode.duration += duration;
            // } else {
            //instructions.add(roadInstruction);
            //lastNode = roadInstruction;
            lastName = roadStep.name;
          }
        }
        _roadLegs.add(roadSteps);
      }
    });
  }
}