GeoJSON.fromMap constructor

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

Constructs a GeoJSON object from a map map.

Map must contain a member with the name "type". The value of the type member must be one of: "FeatureCollection", "Feature", "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection"

Implementation

factory GeoJSON.fromMap(Map<String, dynamic> map) {
  assert(map.containsKey('type'), 'There MUST be contains key `type`');
  assert(
      [
        'FeatureCollection',
        'Feature',
        'Point',
        'MultiPoint',
        'LineString',
        'MultiLineString',
        'Polygon',
        'MultiPolygon',
        'GeometryCollection'
      ].contains(map['type']),
      'Invalid type');

  final type = map['type'];
  late GeoJSON instance;
  switch (type) {
    case 'FeatureCollection':
      instance = GeoJSONFeatureCollection.fromMap(map);
      break;
    case 'Feature':
      instance = GeoJSONFeature.fromMap(map);
      break;
    case 'Point':
      instance = GeoJSONPoint.fromMap(map);
      break;
    case 'MultiPoint':
      instance = GeoJSONMultiPoint.fromMap(map);
      break;
    case 'LineString':
      instance = GeoJSONLineString.fromMap(map);
      break;
    case 'MultiLineString':
      instance = GeoJSONMultiLineString.fromMap(map);
      break;
    case 'Polygon':
      instance = GeoJSONPolygon.fromMap(map);
      break;
    case 'MultiPolygon':
      instance = GeoJSONMultiPolygon.fromMap(map);
      break;
    case 'GeometryCollection':
      instance = GeoJSONGeometryCollection.fromMap(map);
      break;
  }
  return instance;
}