layout method
Given the child
image to display, return the layout (ie. position &
transformation) of the child
Use MapCamera.of to retrieve the ambient MapCamera useful for layout.
If more control over the Image itself is required, prefer subclassing one of the existing subclasses and overriding build.
Implementation
@override
Widget layout(
BuildContext context, {
required Image child,
}) {
final camera = MapCamera.of(context);
// northWest is not necessarily upperLeft depending on projection
final bounds = Rect.fromPoints(
camera.projectAtZoom(this.bounds.northWest) - camera.pixelOrigin,
camera.projectAtZoom(this.bounds.southEast) - camera.pixelOrigin,
);
return Positioned(
left: bounds.topLeft.dx,
top: bounds.topLeft.dy,
width: bounds.size.width,
height: bounds.size.height,
child: child,
);
}