GeoJSONMultiPolygon.fromMap constructor
Constructs a GeoJSONMultiPolygon from a map.
The map must contain a 'type' key with the value 'MultiPolygon', and a 'coordinates' key with the value being a list of Polygon coordinate arrays.
Implementation
factory GeoJSONMultiPolygon.fromMap(Map<String, dynamic> map) {
assert(map.containsKey('type'), 'There MUST be contains key `type`');
assert(['MultiPolygon'].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 Polygon coordinate arrays.');
final lllll = map['coordinates'];
final coords = <List<List<List<double>>>>[];
lllll.forEach((llll) {
final polygon = <List<List<double>>>[];
assert(llll is List, 'There MUST be List');
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);
});
polygon.add(rings);
});
coords.add(polygon);
});
return GeoJSONMultiPolygon(coords);
}