TomSchimansky / TkinterMapView

A python Tkinter widget to display tile based maps like OpenStreetMap or Google Satellite Images.
Creative Commons Zero v1.0 Universal
621 stars 85 forks source link

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

Open motormouthvis opened 1 year ago

motormouthvis commented 1 year ago

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)
twintersx commented 1 year ago

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

@motormouthvis Were you able to find a solution?

twintersx commented 1 year ago

@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))