fromJson method
Implementation
@override
T fromJson(Object? object) {
final json = object as Map<String, dynamic>;
if (!json.containsKey('type')) {
throw Exception('Geometry is missing "type" key');
}
final type = json['type']!;
if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.point]) {
return GeoJsonPoint.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.multiPoint]) {
return GeoJsonMultiPoint.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.line]) {
return GeoJsonLine.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.multiLine]) {
return GeoJsonMultiLine.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.polygon]) {
return GeoJsonPolygon.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.multiPolygon]) {
return GeoJsonMultiPolygon.fromJson(json) as T;
} else if (type == _$GeoJsonGeometryTypeEnumMap[GeoJsonGeometryType.geometryCollection]) {
return GeoJsonGeometryCollection.fromJson(json) as T;
} else {
throw Exception('Invalid geometry type "$type"');
}
}