refresh method

Future<void> refresh()

Loads the FloorManager for the GeoModel associated with the currently assigned GeoViewController to populate the floor information.

Call refresh() after assigning or replacing the GeoModel, or when the underlying FloorManager changes. Calling refresh() will clear any existing selection. If another refresh() call is made while one is already in progress, the latest refresh result is applied. The returned Future completes when loading finishes and, if unsuccessful, will re-throw any loading errors.

Implementation

Future<void> refresh() async {
  // If there is a current refresh run in progress, cancel it.
  _cancelableRefresh?.cancel().ignore();

  // Refresh
  final refreshOperation = CancelableOperation.fromFuture(_refresh());
  _cancelableRefresh = refreshOperation;

  FloorManager? floorManager;
  try {
    floorManager = await refreshOperation.valueOrCancellation();
  } catch (e) {
    _floorManagerNotifier.value = null;
    rethrow;
  }

  // Update floorManager related items if this operation has not been superseded.
  if (identical(_cancelableRefresh, refreshOperation)) {
    // Set min scale for facility and site layers autoselect.
    if (floorManager == null) {
      _facilitiesLayerMinScale = _defaultFacilitiesMinScale;
      _sitesLayerMinScale = _defaultSitesMinScale;
    } else {
      final facilityLayer = floorManager.facilityLayer;
      _facilitiesLayerMinScale =
          (facilityLayer == null || facilityLayer.minScale == 0.0)
          ? _defaultFacilitiesMinScale
          : facilityLayer.minScale;

      final siteLayer = floorManager.siteLayer;
      _sitesLayerMinScale = (siteLayer == null || siteLayer.minScale == 0.0)
          ? _defaultSitesMinScale
          : siteLayer.minScale;
    }

    // Notify listeners of the updated floor manager unless operation was canceled.
    _floorManagerNotifier.value = floorManager;
  }
}