2

Do you know if it is possible to set QGIS to zoom to the predefined scales (in project options) when using the mouse wheel ?

2 Answers 2

3

An answer using PyQGIS, mainly adapted from Set predefined scales in PyQGIS for standalone application. I'm not aware of a GUI approach to do so (?!)

It influences both classic zoom and mouse wheel behaviour

# Get the predefined scales from your project
myscales = QgsProject.instance().viewSettings().mapScales()

def forcedScale(scales=None):
    if scales is None:
        predefinedScales = [
            591657528,
            295828764,
            147914382,
            73957191,
            36978595,
            18489298,
            9244649,
            4622324,
            2311162,
            1155581,
            577791,
            288895,
            144448,
            72224,
            36112,
            18056,
            9028,
            4514,
            2257,
            1128,
            564,
            282,
            141,
            71
        ]
    def zoomToScale(scale):
        mapcanvas.scaleChanged.disconnect(zoomToScale)
        targetScale = min(scales, key=lambda x:abs(x-scale))
        mapcanvas.zoomScale(targetScale )
        mapcanvas.scaleChanged.connect(zoomToScale)
    mapcanvas.scaleChanged.connect(zoomToScale)

# Execute once
forcedScale(myscales)
1
  • Thank you. However I don't know how to implement this code in my QGIS project so I can apply it. Any advice ?
    – Jérémie
    Commented Jul 9, 2021 at 13:32
1

It doesn't involve the mouse wheel, but you could create a Spatial Bookmark, possibly?

enter image description here

1
  • Thanks @Pfalbaum, however I don't need Spatial bookmarks. What I want is that scrolling with the mouse wheel stops at predefined scales.
    – Jérémie
    Commented Jul 9, 2021 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.