Feel like I've been banging my head against the wall here.
I'm writing a plugin. As part of the functionality, I have need to programmatically add a list of annotations to the map.
What I have: list of coordinates (selected using
QgsMapToolEmitPoint), list of corresponding plaintext notes.
Now, I've been trying to use either
QgsAnnotationManager to create these annotations.
<<in constructor>> self.notelayer = QgsAnnotationLayer(name ="Annotations", options = QgsAnnotationLayer.LayerOptions) <<inside a method>> self.notelayer.clear() for i in range(len(self.xydata)): annotation = QgsAnnotationPointTextItem.create() annotation.setText(self.xynotes[i]) annotation.setPoint(QgsPointXY(self.xydata[i],self.xydata[i])) QgsProject.instance().annotationManager().addAnnotation(annotation) self.notelayer.addItem(annotation)
xydata has the coordinates in float, and
xynotes has the plaintext.
I was getting an insufficient arguments error with this, so I tried using annotation manager instead. That itself had issues.
What I need is a simple example of how to actually use them to make and manage annotations. I couldn't find any examples on the web.