74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
|
import tkinter
|
||
|
import tkintermapview
|
||
|
import requests
|
||
|
import skydome
|
||
|
from PIL import Image, ImageTk
|
||
|
|
||
|
|
||
|
#api altitude endpoint
|
||
|
URL="https://api.open-elevation.com/api/v1/lookup"
|
||
|
|
||
|
def get_api_params(coords):
|
||
|
return {"locations":"{},{}".format(coords[0],coords[1])}
|
||
|
|
||
|
# create tkinter window
|
||
|
root_tk = tkinter.Tk()
|
||
|
root_tk.geometry(f"{1000}x{700}")
|
||
|
root_tk.title("map_view_simple_example.py")
|
||
|
|
||
|
# create map widget
|
||
|
map_widget = tkintermapview.TkinterMapView(root_tk, width=1000, height=700, corner_radius=0)
|
||
|
map_widget.pack(fill="both", expand=True)
|
||
|
|
||
|
# set other tile server (standard is OpenStreetMap)
|
||
|
# map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22) # google normal
|
||
|
# map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=22) # google satellite
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
def show_image(coords):
|
||
|
image_window = tkinter.Toplevel()
|
||
|
image_window.title("Simulated Sunset")
|
||
|
image_window.config(width=256,height=256)
|
||
|
#image = skydome.renderFromCamera(coords)
|
||
|
#canvas = tkinter.Canvas(image_window,width=256,height=256)
|
||
|
#canvas.pack()
|
||
|
#img = ImageTk.PhotoImage(width=256,height=256,image=Image.fromarray(image,mode="RGB"))
|
||
|
img = ImageTk.PhotoImage(Image.open("highpress_camera.png"))
|
||
|
|
||
|
panel = tkinter.Label(image_window,image=img)
|
||
|
panel.pack(side="bottom", fill = "both", expand = "yes")
|
||
|
image_window.mainloop()
|
||
|
#canvas.create_image(20,20, anchor="nw", image=img)
|
||
|
|
||
|
def marker_click(marker):
|
||
|
print(f"marker clicked - text: {marker.text} position: {marker.position}")
|
||
|
|
||
|
|
||
|
def add_marker_event(coords):
|
||
|
print("marker added to {}".format(coords))
|
||
|
map_widget.delete_all_marker()
|
||
|
new_marker = map_widget.set_marker(coords[0], coords[1], text="sunset observer")
|
||
|
|
||
|
|
||
|
def get_altitude(coords):
|
||
|
print("getting altitude for {}\n".format(coords))
|
||
|
params = get_api_params(coords)
|
||
|
r = requests.get(URL,params)
|
||
|
data = r.json()
|
||
|
print(data['results'][0]['elevation'])
|
||
|
|
||
|
map_widget.add_right_click_menu_command(label="Set as observer location",
|
||
|
command=add_marker_event,
|
||
|
pass_coords=True)
|
||
|
|
||
|
map_widget.add_right_click_menu_command(label="get altitude",
|
||
|
command=get_altitude,
|
||
|
pass_coords=True)
|
||
|
|
||
|
map_widget.add_right_click_menu_command(label="open_window",
|
||
|
command=show_image,
|
||
|
pass_coords=True)
|
||
|
root_tk.mainloop()
|