2

Is there a way to set the size of the QGIS Text Annotations to map units so that they get resized when I choose different scales?

I wrote a litte script as a workaround which scales the annotations in the QGIS canvas so that they get smaller when I zoom out.

Screenshot: annotations at target scale: enter image description here

Screenshot: smaller annotations when zoomed out:

enter image description here

That's the script I use in the QGIS console:

from qgis.gui import QgsTextAnnotationItem

def scale_annotations():
    target_extent=10000
    current_scale=iface.mapCanvas().scale()
    scale_factor=target_extent/current_scale
    all_annotations=[]
    for item in iface.mapCanvas().items():
        if isinstance( item, QgsTextAnnotationItem ):
            all_annotations.append(item)
    #print all_annotations
    for i in all_annotations:
            curr_scale=i.scale()
            i.setScale(scale_factor)
    iface.mapCanvas().refresh()

try:
    iface.mapCanvas().extentsChanged.disconnect()
except:
    print "kein disconnect"

iface.mapCanvas().extentsChanged.connect(scale_annotations)

But this of course won't scale the annotations in the MapComposer if I want to print multiple layouts with different scales.

Screenshot: annotations too large in PrintComposer: Annotations too large in PrintComposer

So is there a way to get the annotations scale in Canvas and MapComposer depending on the chosen scale?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.