BusShape.fromJson constructor
BusShape.fromJson(- Map<String, dynamic> json
)
Implementation
BusShape.fromJson(Map<String, dynamic> json) {
this.routeId = json['properties']['route_id'];
this.coordinates = [];
// check if single linestring or multi-linestring and handle differently
if (json['type'] == 'LineString') {
List<LatLng> linestring = [];
json['coordinates'].forEach((p) {
linestring.add(LatLng(p[1], p[0]));
});
coordinates.add(linestring);
} else {
json['coordinates'].forEach((l) {
List<LatLng> linestring = [];
l.forEach((p) {
linestring.add(LatLng(p[1], p[0]));
});
coordinates.add(linestring);
});
}
}