Bug report #12601

QgsMapCanvasItem not position properly if map is rotated

Added by Uros Bernik over 7 years ago. Updated over 7 years ago.

Affected QGIS version:2.8.1 Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:duplicate
Crashes QGIS or corrupts data:No Copied to github as #:20723


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))
point = self.toCanvasCoordinates(QgsPoint(self.x, self.y))
painter.translate(point.x(), point.y())

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.marker.update_position(x, y, r)

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 issues

Duplicates QGIS Application - Bug report #11910: in case of rotation zoom by rectangle shows artifacts Closed 2014-12-23


#1 Updated by Uros Bernik over 7 years ago

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

#2 Updated by Jürgen Fischer over 7 years ago

  • Resolution set to duplicate
  • Status changed from Open to Closed

Also available in: Atom PDF