NavigationIntersection.fromJson constructor

NavigationIntersection.fromJson(
  1. Map<String, dynamic> json
)

Implementation

NavigationIntersection.fromJson(Map<String, dynamic> json) {
  geometryIndex = (json['geometry_index'] as num?)?.toInt();
  inIndex = (json['in'] as num?)?.toInt();
  outIndex = (json['outIndex'] as num?)?.toInt();
  duration = (json['duration'] as num?)?.toDouble();

  if (json.containsKey('location') && json['location'] != null) {
    location = List<double>.from(
      json['location'] as List<dynamic>,
    );
  }
  if (json.containsKey('entry') && json['entry'] != null) {
    entry = List<bool>.from(
      json['entry'] as List<dynamic>,
    );
  }
  if (json.containsKey('bearings') && json['bearings'] != null) {
    bearings = List<int>.from(
      json['bearings'] as List<dynamic>,
    );
  }

  if (json.containsKey('lanes') && json['lanes'] != null) {
    lanes = List<NavigationIntersectionLane>.from(
      (json['lanes'] as List<dynamic>).map(
        (lane) => NavigationIntersectionLane.fromJson(
          lane as Map<String, dynamic>,
        ),
      ),
    );
  }

  if (json.containsKey('classes') && json['classes'] != null) {
    classes = List<NavigationIntersectionClass>.from(
      (json['classes'] as List<dynamic>).map(
        (classElement) {
          switch (classElement as String) {
            case 'ferry':
              return NavigationIntersectionClass.FERRY;
            case 'toll':
              return NavigationIntersectionClass.TOLL;
            case 'restricted':
              return NavigationIntersectionClass.RESTRICTED;
            case 'motorway':
              return NavigationIntersectionClass.MOTORWAY;
            case 'tunnel':
              return NavigationIntersectionClass.TUNNEL;
          }

          return NavigationIntersectionClass.UNKNOWN;
        },
      ),
    );
  }
}