geofencePolygon method

Future<List<GeoJsonPoint>> geofencePolygon({
  1. required GeoJsonPolygon polygon,
  2. required List<GeoJsonPoint> points,
  3. bool disableStream = false,
  4. bool verbose = false,
})

Find all the GeoJsonPoint located in a GeoJsonPolygon from a list of points

Implementation

Future<List<GeoJsonPoint>> geofencePolygon(
    {required GeoJsonPolygon polygon,
    required List<GeoJsonPoint> points,
    bool disableStream = false,
    bool verbose = false}) async {
  final foundPoints = <GeoJsonPoint>[];
  final finished = Completer<void>();
  late Iso iso;
  iso = Iso(_geofencePolygonRunner, onDataOut: (dynamic data) {
    if (data is GeoJsonPoint) {
      final point = data;
      foundPoints.add(point);
      if (!disableStream) {
        _processedFeaturesController.sink.add(point);
      }
    } else {
      iso.dispose();
      finished.complete();
    }
  }, onError: (dynamic e) {
    throw GeofencingException("Can not geofence polygon $e");
  });
  final dataToProcess =
      _GeoFenceToProcess(points: points, polygon: polygon, verbose: verbose);
  unawaited(iso.run(<dynamic>[dataToProcess]));
  await finished.future;
  return foundPoints;
}