getOptimalHighlightCenterViewport method
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. Ifnullor empty, uses the entire viewport. Defaults tonull. 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:
- activateHighlight - Activate highlighting for landmarks
- centerOnAreaRect - Center area within viewport rectangle
- getOptimalRoutesCenterViewport - Calculate optimal viewport for routes
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;
}