Polygon.fromJson constructor
Polygon.fromJson(
- Map<String, dynamic> json
)
Creates a Polygon from a GeoJSON Map.
Implementation
@override
factory Polygon.fromJson(Map<String, dynamic> json) {
if (json['geometry']['type'] != 'Polygon') {
throw ArgumentError('json is not a Polygon');
}
List<LinearRing> rings = (json['geometry']['coordinates'] as List)
.map((shape) => LinearRing((shape as List)
.map((c) => Coordinate.fromJson((c as List)
.map((e) => (e is int ? e.toDouble() : e as double))
.toList()))
.toList()))
.toList();
return Polygon(rings,
properties: Map<String, dynamic>.from(json['properties']));
}