Skip to content
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

map canvas rotation #24

Open
XavierCalatrava opened this issue Nov 22, 2018 · 1 comment
Open

map canvas rotation #24

XavierCalatrava opened this issue Nov 22, 2018 · 1 comment

Comments

@XavierCalatrava
Copy link

Is it possible to respect the map rotation in canvas view when you print?

@tveinot
Copy link

tveinot commented Jan 16, 2020

I have been working on this, as well as asked about this very feature.
So far I discovered that you can make a custom function for the Expression String Builder that will capture the Map Rotation and apply it to the Map Canvas of your Layout.
In the Function Tab of the Expression String Builder enter the below Python code

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(args='auto', group='Custom')
def CanvasRotation(feature, parent):
return (iface.mapCanvas().rotation())

As you can see I named my function "CanvasRotation" it should probably be "MapRotation" you can change the name where it says "def CanvasRotation(feature, parent):" with that saved you can then go to the Expression tab and use CanvasRotation() to return the value from your map rotation.

Back to your Layout if you look to the left of the Map Rotation value box in the Map Properties you will see a button for Data Defined Override. Click that, got to edit and enter CanvasRotation() and save it. Now, your Layout will be rotated by the same rotation as your Canvas.

NOTES:
There are some issues...
Since the original tool was built to use QRectF the rectangle will not rotate with map properly; this is because of how QRectF works. I tried to use QgsGeometry, QgsTransform, and PyMath to alter the rubberband to appear much like the view port of the rotated layout but so far have been unsuccessful.

The other issue is once rotated when you try to move the box will move in relation to the rotation; meaning if you rotate the map 90 degrees and grab the map view box and drag the mouse left the box will move up, at 180 degrees all the movements are reversed i.e. the box moves "Map Rotation" off from your mouse movements. It can make things interesting when aligning your map view but can be done with some patience.

I think QgsTransform needs to be applied to the tools def __createRubberBand(self):, and the def canvasMoveEvent(self, e): to fix this. As I mentioned I have made some attempts but this is as far as I have gotten to get it all to work.
FYI I am not the original developer of this tool, I was just looking for a way to do the same thing you are.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants