Point.fromJson constructor
Creates a Point from a GeoJSON Map.
Example:
Point.fromJson({
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [1, 2]
},
'properties': {'name': 'point'}
});
Implementation
@override
factory Point.fromJson(Map<String, dynamic> json) {
if (json['geometry'] == null) {
throw ArgumentError('json does not contain geometry');
} else if (json['geometry']['type'] != 'Point') {
throw ArgumentError('json is not a Point');
} else if (json['geometry']['coordinates'] == null ||
json['geometry']['coordinates'].isEmpty) {
throw ArgumentError('json does not contain coordinates');
}
return Point(
Coordinate(json['geometry']['coordinates'][1],
json['geometry']['coordinates'][0]),
properties: Map<String, dynamic>.from(json['properties']),
);
}