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

QgsMapCanvasItem not position properly if map is rotated #20723

Closed
qgib opened this issue Apr 18, 2015 · 2 comments
Closed

QgsMapCanvasItem not position properly if map is rotated #20723

qgib opened this issue Apr 18, 2015 · 2 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@qgib
Copy link
Contributor

qgib commented Apr 18, 2015

Author Name: Uros Bernik (Uros Bernik)
Original Redmine Issue: 12601
Affected QGIS version: 2.8.1


Here is the code of my custom QgsMapCanvasItem:

class QgsPositionMarker(QgsMapCanvasItem):
Graphic = QPolygon([QPoint(-20, 0), QPoint(20, 15), QPoint(10, 0), QPoint(20, -15)])

def __init__(self, canvas):
    QgsMapCanvasItem.__init__(self, canvas)
    self.x, self.y, self.r = 0, 0, 0
    
def update_position(self, x, y, r):
    self.x, self.y, self.r = x, y, r

def paint(self, painter, option, widget):
    painter.setPen(QPen(QColor(0, 0, 0), 2))
    painter.setBrush(QColor(255, 0, 0))
    painter.setRenderHint(QPainter.Antialiasing)
    
    point = self.toCanvasCoordinates(QgsPoint(self.x, self.y))
    
    painter.translate(point.x(), point.y())
    painter.rotate(self.r)
    painter.drawPolygon(QgsPositionMarker.Graphic)

I tested, and the transformed points from toCanvasCoordinates method are calculated correctly (ie. i center the position marker in the middle of map canvas, and i get the same resulting point, regardless whether the map is rotated or not) When i update map canvas like this:

    self.map.setRotation(r)
    self.marker.update_position(x, y, r)
            
    self.map.setExtent(myextents)
    self.map.refresh()

Position of the marker is correct only if map rotation is zero, otherwise not, even though the point returned from toCanvasCoordinates is always correct.Error persists if i reverse the order of setRotation and marker.update_position calls.


Related issue(s): #20120 (duplicates)
Redmine related issue(s): 11910


@qgib
Copy link
Contributor Author

qgib commented Apr 19, 2015

Author Name: Uros Bernik (Uros Bernik)


After checking out #20120, i believe it could be the same issue!

@qgib
Copy link
Contributor Author

qgib commented Apr 19, 2015

Author Name: Jürgen Fischer (@jef-n)


  • resolution was changed from to duplicate
  • status_id was changed from Open to Closed

@qgib qgib added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label May 25, 2019
@qgib qgib closed this as completed May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

No branches or pull requests

1 participant