Geometry.fromJson constructor

Geometry.fromJson(
  1. Map<String, dynamic> json
)

Creates either a Point, LineString, Polygon, MultiPoint, MultiLineString or MultiPolygon from JSON data.

Implementation

factory Geometry.fromJson(Map<String, dynamic> json) {
  final type = json['type'];
  final coordinates = json['coordinates'];

  if (type == 'Point') {
    return Point.fromJson(coordinates);
  }

  if (type == 'LineString') {
    return LineString.fromJson(coordinates);
  }

  if (type == 'Polygon') {
    return Polygon.fromJson(coordinates);
  }

  if (type == 'MultiPoint') {
    return MultiPoint.fromJson(coordinates);
  }

  if (type == 'MultiLineString') {
    return MultiLineString.fromJson(coordinates);
  }

  if (type == 'MultiPolygon') {
    return MultiPolygon.fromJson(coordinates);
  }

  throw Exception('Invalid type: $type.');
}