Extended: Camera Zoom Coordinate Confusion

I have a 2D tilemap and 2D sprite.

Currently, the sprite moves around when I press the WASD keys and the camera follows it. If the camera hits the edge of the map, it stops following the sprite and follows the sprite when it moves away from the edge. (Zoom = 1)

This works fine… until I start changing the zoom.

When I zoom out, the camera goes beyond the map bounds. If I zoom in (beyond a zoom of 1), I cant reach the edge of the map.

Since I cant set the camera’s bounding rectangle directly, I cant figure out what tranformation to apply to correct the issue.

Any help would be appreciated.