centerOnCoordinates method

void centerOnCoordinates(
  1. Coordinates coords, {
  2. int zoomLevel = -1,
  3. Point<int>? screenPosition,
  4. GemAnimation? animation,
  5. double? mapAngle,
  6. double? viewAngle,
  7. double slippyZoomLevel = -1.0,
})

Centers the map view on specified WGS84 geographic coordinates.

Positions the map so the specified coords appear at the target screen location with optional zoom level, rotation, and viewing angle adjustments. If no screen position is specified, the coordinates center at the current cursor position (defaulting to viewport center).

The operation can be animated using the animation parameter for smooth transitions. Use skipAnimation to immediately complete any ongoing animation.

Parameters

  • coords: The WGS84 coordinates (latitude, longitude, optional altitude) to center on
  • zoomLevel: Zoom level (higher values = more zoomed in). Use -1 for automatic selection based on context. Defaults to -1
  • screenPosition: Target screen position in physical pixels where the coordinates should project, relative to the map view's top-left corner. If null, uses the current cursor position. Defaults to null
  • animation: Animation settings for the centering operation. If null, centering occurs instantly. Defaults to null
  • mapAngle: Map rotation angle in degrees (0-360), where 0 represents north-up alignment. If null, rotation remains unchanged. Defaults to null
  • viewAngle: Camera pitch angle in degrees (0-90), where 0 is top-down view and 90 is horizon view. If null, pitch remains unchanged. Defaults to null
  • slippyZoomLevel: Tile-based zoom level for specific tile system compatibility. Use -1.0 for automatic selection. Defaults to -1.0

See also:

Implementation

void centerOnCoordinates(
  final Coordinates coords, {
  final int zoomLevel = -1,
  final Point<int>? screenPosition,
  final GemAnimation? animation,
  double? mapAngle,
  double? viewAngle,
  final double slippyZoomLevel = -1.0,
}) {
  if (viewAngle != null && (viewAngle - viewAngle.toInt() == 0)) {
    viewAngle -= 0.0000000001;
  }
  if (mapAngle != null && (mapAngle - mapAngle.toInt() == 0)) {
    mapAngle -= 0.0000000001;
  }
  objectMethod(
    _pointerId,
    'MapView',
    'centerOnCoordinates',
    args: <String, Object>{
      'coords': coords,
      'zoomLevel': zoomLevel,
      'slippyZoomLevel': slippyZoomLevel,
      if (screenPosition != null) 'xy': XyType<int>.fromPoint(screenPosition),
      if (animation != null) 'animation': animation,
      if (mapAngle != null) 'mapAngle': mapAngle,
      if (viewAngle != null) 'viewAngle': viewAngle,
    },
  );
}