removeDatastore method

Future<void> removeDatastore(
  1. double minLatitude,
  2. double minLongitude,
  3. double maxLatitude,
  4. double maxLongitude,
)

Implementation

Future<void> removeDatastore(double minLatitude, double minLongitude, double maxLatitude, double maxLongitude) async {
  BoundingBox toRemove = BoundingBox(minLatitude, minLongitude, maxLatitude, maxLongitude);
  _boundingBox = null;
  final List<Datastore> datastoresList = datastores.toList();

  // Fetch all boundaries in parallel, using the cache when available.
  final List<Future<BoundingBox>> futures = [];
  for (Datastore datastore in datastoresList) {
    BoundingBox? datastoreBoundary = _datastoreBoundaries[datastore];
    futures.add(datastoreBoundary != null ? Future.value(datastoreBoundary) : datastore.getBoundingBox());
  }
  final List<BoundingBox> boundaries = await Future.wait(futures);

  for (int i = 0; i < datastoresList.length; ++i) {
    Datastore datastore = datastoresList[i];
    BoundingBox datastoreBoundary = boundaries[i];
    _datastoreBoundaries[datastore] = datastoreBoundary;
    if (toRemove.intersects(datastoreBoundary)) {
      datastores.remove(datastore);
      _datastoreBoundaries.remove(datastore);
    } else {
      if (null == _boundingBox) {
        _boundingBox = datastoreBoundary;
      } else {
        _boundingBox = _boundingBox!.extendBoundingBox(datastoreBoundary);
      }
    }
  }
}