Skip to content

Fix map center positioning with rotation and information drawer #6285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 25, 2025

Conversation

mohsenD98
Copy link
Collaborator

@mohsenD98 mohsenD98 commented May 21, 2025

Pull Request Description

When clicking the "next feature" button in geometry editing mode, the map center position was incorrect when:

  1. The map was rotated
  2. The information drawer was open

This happened because the margin adjustments for the information drawer weren't properly accounting for map rotation.

✨ Solution

The fix modifies the setCenter function in QgsQuickMapSettings to properly handle margin adjustments with rotation. Here's how it works:

1. Base Margin Calculation

const double baseXAdjustment = mRightMargin * devicePixelRatio() * mMapSettings.mapUnitsPerPixel() / 2;
const double baseYAdjustment = mBottomMargin * devicePixelRatio() * mMapSettings.mapUnitsPerPixel() / 2;
  • We calculate the base margin adjustments in map units
  • The division by 2 is crucial because the margin needs to be split between both sides of the center point
  • This ensures proper centering when rotation is 0

2. Rotation Adjustment

const double rotationRadians = mMapSettings.rotation() * M_PI / 180.0;
const double xAdjustment = baseXAdjustment * cos(rotationRadians) - baseYAdjustment * sin(rotationRadians);
const double yAdjustment = baseXAdjustment * sin(rotationRadians) + baseYAdjustment * cos(rotationRadians);
  • We convert the rotation angle to radians
  • ✨ We use rotation matrices to transform the margin adjustments:
    • xAdjustment = baseX * cos(θ) - baseY * sin(θ)
    • yAdjustment = baseX * sin(θ) + baseY * cos(θ)
  • This properly rotates the margin adjustments to account for the map's rotation

Issue

issue.before.webm

Fixed

Screencast.From.2025-05-21.20-11-00.webm

@mohsenD98 mohsenD98 self-assigned this May 21, 2025
@duke-nyuki
Copy link

Task linked: QF-5910 Vertex Editor Improvments

@qfield-fairy
Copy link
Collaborator

qfield-fairy commented May 21, 2025

@@ -142,8 +142,14 @@ void QgsQuickMapSettings::setCenter( const QgsPoint &center, bool handleMargins
QgsRectangle e = mMapSettings.extent();
if ( handleMargins )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( handleMargins )
if ( handleMargins && ( !qgsDoubleNear( mRightMargin, 0.0 ) || !qgsDoubleNear( mBottomMargin, 0.0 ) )

@nirvn nirvn merged commit 0847c59 into master May 25, 2025
27 checks passed
@nirvn nirvn deleted the QF-5910_Vertex-Editor-Improvments2 branch May 25, 2025 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants