Bug report #12601

QgsMapCanvasItem not position properly if map is rotated

Added by Uros Bernik almost 5 years ago. Updated almost 5 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
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

Description

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 issues

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

History

#1 Updated by Uros Bernik almost 5 years ago

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

#2 Updated by Jürgen Fischer almost 5 years ago

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

Also available in: Atom PDF