O'Reilly logo

Building Mapping Applications with QGIS by Erik Westra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating custom map canvas items

A map canvas item is an item that is placed on top of the map canvas. Standard map canvas items include text annotations, vertex markers, and the visual highlighting of a feature. It is also possible to create your own custom map canvas items by subclassing QgsMapCanvasItem. To see how this works, let's create a map canvas item that draws a compass rose onto the map:

Creating custom map canvas items

We'll start by creating the basic QgsMapCanvasItem subclass:

class CompassRoseItem(QgsMapCanvasItem): def __init__(self, canvas): QgsMapCanvasItem.__init__(self, canvas) self.center = QgsPoint(0, 0) self.size = 100 def setCenter(self, center): self.center ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required