这里我发现之前放大和缩小搞反了,请自行更改资源文件和UI文件,重新生成对应的py文件。

  • zoom_in:是缩小
  • zoom_out:是放大

实现画布上方的放大、缩小、刷新功能,并绑定到对应按钮。在btn_func.py,添加更改绘图工具和刷新画布代码如下:

btn_func.py
def slot_set_gis_tool(canvas: QgsMapCanvas, tool):
canvas.setMapTool(tool)


def slot_refresh_canvas(canvas: QgsMapCanvas):
"""
刷新画布
:param canvas:
:return:
"""
for layer in canvas.layers():
canvas.setExtent(layer.extent())
canvas.setDestinationCrs(layer.crs())
break
canvas.refreshAllLayers()

preview.pybind_func方法中添加如下代码:

preview.oy
# 绑定工具方法
_ui.button_move.clicked.connect(lambda self: slot_set_gis_tool(main.preview_canvas, main.preview_tool_pan))
_ui.button_zoom_in.clicked.connect(lambda self: slot_set_gis_tool(main.preview_canvas, main.preview_tool_zoom_in))
_ui.button_zoom_out.clicked.connect(lambda self: slot_set_gis_tool(main.preview_canvas, main.preview_tool_zoom_out))
_ui.button_refresh.clicked.connect(lambda self: slot_refresh_canvas(main.preview_canvas))