1

When I try to read the expression variable @map_id using a Python expression function (see code below) inside a label text, it always returns "canvas" as result. When I use @map_id directly, it returns the correct name of a layout map item. What can I do to automatically retrieve the correct map id with Python?

@qgsfunction(args='auto', group='Custom')
def getMapId(feature, parent):
    return QgsExpressionContextUtils.mapSettingsScope(QgsMapSettings()).variable("map_id")

BTW: using QgsExpression("@map_id") doesn't work either.

My ultimate goal is to create a function that will return the extents of a map item so that I can speed up my virtual layers by restricting the query to that area.

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.