GeoJSONPolygon.fromMap constructor

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

The constructor from map

Implementation

factory GeoJSONPolygon.fromMap(Map<String, dynamic> map) {
  assert(map.containsKey('type'), 'There MUST be contains key `type`');
  assert(['Polygon'].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 GeoJSONPolygon(coords);
}