getOptimalHighlightCenterViewport method

Rectangle<int> getOptimalHighlightCenterViewport({
  1. Rectangle<int>? screenRect,
})

Calculates the optimal viewport for displaying all highlighted elements.

Returns an adjusted viewport rectangle that ensures all currently highlighted elements will be visible when used with centerOnAreaRect. The calculation accounts for all active highlights and automatically determines the best viewport dimensions to fit all highlighted content.

This is useful for centering on highlighted landmarks with custom padding or UI constraints.

Parameters

  • screenRect: Target screen rectangle in physical pixels where highlights should fit, relative to the map view's top-left corner. If null or empty, uses the entire viewport. Defaults to null. Useful for fitting within UI elements or adding margins

Returns

  • Optimal viewport Rectangle<int> in physical pixels that will fit all highlighted elements, relative to the map view's top-left corner

See also:

Implementation

Rectangle<int> getOptimalHighlightCenterViewport({
  Rectangle<int>? screenRect,
}) {
  screenRect ??= const Rectangle<int>(0, 0, 0, 0);

  final OperationResult resultString = objectMethod(
    _pointerId,
    'MapView',
    'getOptimalHighlightCenterViewport',
    args: RectType<int>.fromRectangle(screenRect),
  );

  final Rectangle<int> rect = Rectangle<int>(
    resultString['result']['x'] ?? 0,
    resultString['result']['y'] ?? 0,
    resultString['result']['width'] ?? 0,
    resultString['result']['height'] ?? 0,
  );

  return rect;
}