painter property

CanvasPainter painter
getter/setter pair

A painter function that draws on a Canvas.

This is a regular painter that uses the Canvas API to draw markers. Generally it is performant enough for most use cases. But it can suffer from overdraw issues when rendering many markers. Keep values computed outside the painter function for better performance.

The painter must return a Rect that represents the area covered by the drawn marker.

  • The returned Rect is also used for culling and hit testing, so it must be precise.

The painter function provides several parameters:

  • canvas: The Canvas instance used to draw the marker.
  • center: The central pixel position of the marker. This is typically the anchor point for rendering shapes (e.g., the center of a circle).
  • metersToPixels: A function that converts a size in meters to pixels, based on the current zoom level and latitude of the position.
  • latLngToPixelOffset: A function that converts geographic coordinates (LatLng) to pixel offsets. Useful for drawing lines or shapes between coordinates.
  • zoomLevel: The current zoom level, which can be used to scale graphics based on the zoom level.

Implementation

CanvasPainter painter;