getIsochrones method

Future<GeoJsonFeatureCollection> getIsochrones({
  1. required List<Coordinate> locations,
  2. required List<int> range,
  3. List<String> attributes = const <String>[],
  4. String? id,
  5. bool intersections = false,
  6. int? interval,
  7. String locationType = 'start',
  8. Map<String, dynamic>? options,
  9. String rangeType = 'time',
  10. int? smoothing,
  11. String areaUnits = 'm',
  12. String units = 'm',
  13. ORSProfile? profileOverride,
})

Obtain Isochrone (areas of reachability) Data for the locations given as a List of Coordinate.

The Isochrone Service supports time and distance analysis for one single or multiple locations.

You may also specify the isochrone interval or provide multiple exact isochrone range values.

The isochrone service supports the following attributes: 'area', 'reachfactor', 'total_pop'.

Information about the endpoint, parameters, response etc. can be found at: https://openrouteservice.org/dev/#/api-docs/v2/isochrones/{profile}/post

Implementation

Future<GeoJsonFeatureCollection> getIsochrones({
  required List<Coordinate> locations,
  required List<int> range,
  List<String> attributes = const <String>[],
  String? id,
  bool intersections = false,
  int? interval,
  String locationType = 'start',
  Map<String, dynamic>? options,
  String rangeType = 'time',
  int? smoothing,
  String areaUnits = 'm',
  String units = 'm',
  ORSProfile? profileOverride,
}) async {
  // If a path parameter override is provided, use it.
  final ORSProfile chosenPathParam = profileOverride ?? _profile;

  // Build the request URL.
  final Uri uri = Uri.parse(
    '$_isochronesEndpointURL/${OpenRouteService.getProfileString(chosenPathParam)}',
  );

  // Ready data to be sent.
  final Map<String, dynamic> queryParameters = <String, dynamic>{
    'locations': locations
        .map<List<double>>(
          (coordinate) => <double>[coordinate.longitude, coordinate.latitude],
        )
        .toList(),
    'range': range,
    'attributes': attributes,
    'id': id,
    'intersections': intersections,
    'interval': interval,
    'location_type': locationType,
    'options': options,
    'range_type': rangeType,
    'smoothing': smoothing,
    'area_units': areaUnits,
    'units': units,
  }..removeWhere((key, value) => value == null);

  // Fetch and parse the data.
  final Map<String, dynamic> data =
      await _openRouteServicePost(uri: uri, data: queryParameters);
  return GeoJsonFeatureCollection.fromJson(data);
}