setZoomLevel method

int setZoomLevel(
  1. int zoomLevel, {
  2. int duration = 0,
  3. Point<int>? screenPosition,
})

Sets the map zoom level centered on a specified screen position.

Changes the zoom level while keeping the specified screen position fixed, meaning the geographic location at that screen point remains at the same screen coordinates after zooming. The zoom level must be between minZoomLevel and maxZoomLevel.

If no screen position is provided, the zoom centers on the current cursor position (which defaults to viewport center). The operation can be animated by specifying a duration.

Parameters

  • zoomLevel: Target zoom level, must be between minZoomLevel and maxZoomLevel
  • duration: Animation duration in milliseconds. Use 0 for instant zoom. Defaults to 0
  • screenPosition: Screen coordinates in physical pixels that should remain fixed during zoom, relative to the map view's top-left corner. If null, uses the current cursor position. Defaults to null

Returns

  • On success: the previous zoom level. On error: error code (< 0)

See also:

  • zoomLevel - Get the current zoom level
  • canZoom - Check if zoom to level is possible
  • setSlippyZoomLevel - Set zoom using slippy tile level

Implementation

int setZoomLevel(
  final int zoomLevel, {
  final int duration = 0,
  final Point<int>? screenPosition,
}) {
  final OperationResult resultString = objectMethod(
    _pointerId,
    'MapView',
    'setZoomLevel',
    args: <String, Object>{
      'zoomLevel': zoomLevel,
      'duration': duration,
      if (screenPosition != null) 'xy': XyType<int>.fromPoint(screenPosition),
    },
  );

  return resultString['result'];
}