PhotonFeature.fromJson constructor

PhotonFeature.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory PhotonFeature.fromJson(Map<String, dynamic> json) {
  final coordinates = json['geometry']['coordinates'] as List<dynamic>;
  final center = LatLng(coordinates[1], coordinates[0]);

  final properties = json['properties'];

  final osmType = properties['osm_type'];

  List<LatLng>? extent;
  if (osmType == 'R') {
    final jsonExtent = properties['extent'] as List<dynamic>;
    extent = [
      LatLng(jsonExtent[1], jsonExtent[0]),
      LatLng(jsonExtent[3], jsonExtent[2])
    ];
  }

  return PhotonFeature(
      coordinates: center,
      osmId: properties['osm_id'],
      osmKey: properties['osm_key'],
      osmType: osmType,
      osmValue: properties['osm_value'],
      type: properties['type'],
      extent: extent,
      country: properties['country'],
      countryIsoCode: properties['countrycode'],
      name: properties['name'],
      street: properties['street'],
      houseNumber: properties['housenumber'],
      postcode: properties['postcode'],
      district: properties['district'],
      city: properties['city'],
      county: properties['county'],
      state: properties['state']);
}