Store bounding box parameters when moveToBoundingBox is called before viewport size is known
Task: Set Bounds before size changed
Issue: Calling moveToBoundingBox before viewport size is known discards the call because a size is required for calculations.
Goal: Store the bounding box parameters and apply them when viewport size is known.
Implementation Complete ✅
Changed approach based on feedback to modify the public API instead:
- [x] Explore repository and understand the issue
- [x] Build and test the codebase (all tests pass)
- [x] Modify public API
moveToBoundingBoxto store parameters when viewport size is unknown - [x] Apply stored parameters when viewport size becomes known in
viewportSizeChanged - [x] Implement for both MapCamera2d and MapCamera3d
- [x] Verify all existing tests still pass (1282 assertions in 46 test cases)
Changes Made
MapCamera2d.h / MapCamera3d.h:
- Added
PendingBoundingBoxstruct to store parameters formoveToBoundingBoxcall when viewport size is not yet known - Added
std::optional<PendingBoundingBox> pendingBoundingBoxmember variable
MapCamera2d.cpp:
- Modified
moveToBoundingBox()to:- Check if viewport size is known (viewportSize.x > 0 && viewportSize.y > 0)
- Store bounding box parameters in
pendingBoundingBoxif size is unknown - Clear
pendingBoundingBoxand apply immediately if size is known
- Modified
viewportSizeChanged()to apply pending bounding box when viewport size becomes known
MapCamera3d.cpp:
- Modified
moveToBoundingBox()with same logic as MapCamera2d - Modified
viewportSizeChanged()to apply pending bounding box when viewport size becomes known
Testing
✅ All existing tests pass without modification (1282 assertions in 46 test cases), confirming backward compatibility and no regressions.
Code Quality
-
Minimal changes - only modified the public API method as requested
-
Consistent with existing code patterns in both camera implementations
-
No breaking changes to the public API behavior
-
Fixes openmobilemaps/maps-core#890
Original prompt
This section details on the original issue you should resolve
<issue_title>Set Bounds before size changed</issue_title> <issue_description>Current: setting camera bounds before size is known will discard the call, because a size is required.
Goal: store the desired bounds, set when size is known.</issue_description>
Comments on the Issue (you are @copilot in this section)
- Fixes openmobilemaps/maps-core#890
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.