Add side bar with button and textbox

This commit is contained in:
Koa Wells 2023-12-18 16:21:57 -05:00
parent 4b32d72f8f
commit d824a8638f

View File

@ -1,54 +1,52 @@
import tkinter import tkinter
import tkintermapview import tkintermapview
import json
import copy
with open('./data/collinear_clean.geojson', 'r') as city_file: select_buildings = False
city = json.load(city_file) selected_coordinates = []
buildings = city['features']
building_polygons = [] def marker_click(marker):
print(f"marker clicked - text: {marker.text} position: {marker.position}")
for building in buildings: def on_click(coordinates_tuple):
building_polygon = [] if select_buildings:
if building['geometry']['type'] == 'Polygon': print(coordinates_tuple)
for coordinate in building['geometry']['coordinates'][0]: selected_coordinates.append(coordinates_tuple)
building_polygon.append((coordinate[1], coordinate[0]))
building_polygons.append({'id': building['id'], def activate_selection_box():
'polygon': copy.deepcopy(building_polygon)}) select_buildings = True
# create tkinter window # create tkinter window
root_tk = tkinter.Tk() root_tk = tkinter.Tk()
root_tk.geometry(f"{1000}x{700}") root_tk.geometry(f"{1000}x{700}")
root_tk.title("Building Selection Tool") root_tk.title("Building Selection Tool")
# create left frame
leftframe = tkinter.Frame(root_tk)
leftframe.pack(side=tkinter.LEFT)
# create right frame
rightframe = tkinter.Frame(root_tk,width=80)
rightframe.pack(side=tkinter.RIGHT)
# create button for activating building selection
selection_box_button = tkinter.Button(leftframe, text="Create Selection Box", command=activate_selection_box)
selection_box_button.pack(side=tkinter.TOP)
# create text box for viewing selecting coordinates
text_width = tkinter.Text(leftframe,height=50,width=30)
text_width.pack(side=tkinter.BOTTOM,padx=50)
# create map widget # create map widget
map_widget = tkintermapview.TkinterMapView(root_tk, width=1000, height=700, corner_radius=0) map_widget = tkintermapview.TkinterMapView(rightframe, width=1000, height=700, corner_radius=0)
map_widget.pack(fill="both", expand=True) map_widget.pack(fill="both", expand=True)
# set other tile server (standard is OpenStreetMap) # 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=m&hl=en&x={x}&y={y}&z={z}&s=Ga", max_zoom=14) # 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
# set current position and zoom # set current position and zoom
map_widget.set_position(45.497059, -73.578451, marker=False) # Montreal, Quebec map_widget.set_position(45.497059, -73.578451, marker=False) # Montreal, Quebec
map_widget.set_zoom(11) map_widget.set_zoom(11)
# set current position with address map_widget.add_left_click_map_command(on_click)
# map_widget.set_address("Berlin Germany", marker=False)
def marker_click(marker):
print(f"marker clicked - text: {marker.text} position: {marker.position}")
building_polygon_markers = []
count = 0
for building_polygon in building_polygons:
if count > 1000:
break
building_polygon_markers.append(map_widget.set_polygon(building_polygon['polygon'],
fill_color='black',
outline_color='black',
name=building_polygon['id']))
count+=1
root_tk.mainloop() root_tk.mainloop()