MultiLineString.fromJson constructor

  1. @override
MultiLineString.fromJson(
  1. Map<String, dynamic> json
)

Creates a MultiLineString from a valid GeoJSON object.

Example:

MultiLineString.fromJson({'type': 'Feature', 'geometry': {'type': 'MultiLineString', 'coordinates': [[[1, 2], [3, 4]]]}, 'properties': {}}); // MultiLineString([[Coordinate(1, 2), Coordinate(3, 4)]])

Implementation

@override
factory MultiLineString.fromJson(Map<String, dynamic> json) {
  if (json['geometry']['type'] != 'MultiLineString') {
    throw ArgumentError('json is not a MultiLineString');
  }

  dynamic coordinatesData = json['geometry']['coordinates'];
  if (coordinatesData is List<List<dynamic>>) {
    List<List<Coordinate>> coordinatesList = coordinatesData
        .map((line) =>
            line.map((point) => Coordinate.fromJson(point)).toList())
        .toList();
    return MultiLineString(coordinatesList,
        properties: Map<String, dynamic>.from(json['properties']));
  } else {
    throw ArgumentError('json is not a MultiLineString');
  }
}