fromJson static method

GeographyGeometryCollection fromJson(
  1. dynamic value
)

Returns a deserialized GeographyGeometryCollection from various formats.

Handles:

Implementation

static GeographyGeometryCollection fromJson(dynamic value) {
  if (value is GeographyGeometryCollection) return value;
  if (value is Uint8List) {
    return GeographyGeometryCollection.fromBinary(value);
  }
  if (value is String) return _fromEwkt(value);
  if (value is Map) {
    final srid = value['srid'] as int? ?? Geography.defaultSrid;
    // Each element is already a serialized geography (EWKT or map).
    final rawGeoms = value['geometries'] as List;
    final geoms = rawGeoms.map<Geography>((g) {
      if (g is String) return _geomFromEwktString(g);
      if (g is Map) return _geomFromMap(g);
      throw ArgumentError('Cannot deserialize geometry element: $g');
    }).toList();
    return GeographyGeometryCollection(geometries: geoms, srid: srid);
  }
  throw ArgumentError(
    'Cannot deserialize ${value.runtimeType} as GeographyGeometryCollection',
  );
}