TkinterMapView icon indicating copy to clipboard operation
TkinterMapView copied to clipboard

If I use the mouse to move or zoom the map, the next map.set_position centers intermittently in random places

Open motormouthvis opened this issue 3 years ago • 3 comments

Hi, I'm having a problem with a moving map for aircraft. If I just let it run it works great, but if I move the map display with the mouse or change the zoom with the mouse, the next time this code is run, it intermittently centers in Brazil. Once that happens, it never centers in the correct place again. Can you help?

This code runs on a timer:

            self.map_widget.set_position(self.address_lat, self.address_lon)
            if self.auto_zoom_flag.get() == True:
                # Set zoom level based on aircraft speed 1 is zoomed all the way out, 
                # 19 all the way in
                zoom_level = 19-int(flight_position_data[0].get("speed")/600*19)
                if zoom_level <= 3:
                    zoom_level = 3
                elif zoom_level >= 14: zoom_level = 14
                self.map_widget.set_zoom(zoom_level)
            self.airplaneMarker.set_position(self.aircraft_lat, self.aircraft_lon)

motormouthvis avatar Nov 11 '22 03:11 motormouthvis

@TomSchimansky Having the same issue with map.set_position(lat, long).

@motormouthvis Were you able to find a solution?

twintersx avatar Feb 01 '23 18:02 twintersx

@TomSchimansky, @motormouthvis Found the issue... when you scroll using mouse, the zoom is stored as float.

In the utility_functions.py: def decimal_to_osm(lat_deg: float, lon_deg: float, zoom: int) <-- int is rounding the float value and thus changing the calculations in the following lines...

I believe zoom:int should be changed to zoom:float alternative solution could be forcing mouse scroll to int?

simple solution: map_widget.set_zoom(int(map_widget.zoom))

twintersx avatar Feb 01 '23 22:02 twintersx