GeoJSONMultiLineString.fromMap constructor

GeoJSONMultiLineString.fromMap(
  1. Map<String, dynamic> map
)

Creates a new GeoJSONMultiLineString object from a map.

The map must include a 'type' key with the value 'MultiLineString' and a 'coordinates' key with an array of linear ring coordinate arrays.

Implementation

factory GeoJSONMultiLineString.fromMap(Map<String, dynamic> map) {
  assert(map.containsKey('type'), 'There MUST be contains key `type`');
  assert(['MultiLineString'].contains(map['type']), 'Invalid type');
  assert(map.containsKey('coordinates'),
      'There MUST be contains key `coordinates`');
  assert(map['coordinates'] is List,
      'There MUST be array of linear ring coordinate arrays.');
  final llll = map['coordinates'];
  final coords = <List<List<double>>>[];
  llll.forEach((lll) {
    assert(lll is List, 'There MUST be List');
    final rings = <List<double>>[];
    lll.forEach((ll) {
      assert(ll is List, 'There MUST be List');
      assert((ll as List).length > 1, 'There MUST be two or more element');
      final pos = ll.map((e) => e.toDouble()).cast<double>().toList();
      rings.add(pos);
    });
    coords.add(rings);
  });
  return GeoJSONMultiLineString(coords);
}