Tkinter canvas zoom + move/pan

后端 未结 3 1408
无人及你
无人及你 2020-11-27 17:44

Tkinter\'s canvas widget has built-in features to:

  • move/pan the canvas (for example with Click + Drag) with canvas.scan_mark and canvas.s

3条回答
  •  甜味超标
    2020-11-27 18:29

    You might consider using map tiles for this case. The tiles can be specific to the zoom level. After selecting the tiles based on the pan and zoom level you can position them on the canvas with Canvas.create_image.

    Assuming you have some tile class with its coordinates and image, you could select for visible tiles based on the pan, zoom and frame size.

    for tile in visible_tiles(pan_center, frame_dimensions, zoom_level):
        canvas.create_image(tile.x, tile.y, anchor=Tkinter.NW, image=tile.image)
    

    There is a full sample of this in Tile-Based Geospatial Information Systems by John Sample and Elias Ioup in the chapter on Tiled Mapping Clients.

提交回复
热议问题