From 4b32d72f8f007a64cd2f2249948c0fafbddd097f Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Fri, 15 Dec 2023 15:16:40 -0500 Subject: [PATCH] Add initial test for rendering buildings --- map_view_simple_example.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/map_view_simple_example.py b/map_view_simple_example.py index fabc09f..b3a098a 100644 --- a/map_view_simple_example.py +++ b/map_view_simple_example.py @@ -1,5 +1,21 @@ import tkinter import tkintermapview +import json +import copy + +with open('./data/collinear_clean.geojson', 'r') as city_file: + city = json.load(city_file) + buildings = city['features'] + +building_polygons = [] + +for building in buildings: + building_polygon = [] + if building['geometry']['type'] == 'Polygon': + for coordinate in building['geometry']['coordinates'][0]: + building_polygon.append((coordinate[1], coordinate[0])) + building_polygons.append({'id': building['id'], + 'polygon': copy.deepcopy(building_polygon)}) # create tkinter window root_tk = tkinter.Tk() @@ -15,13 +31,24 @@ map_widget.set_tile_server("https://mt0.google.com/vt/lyrs=m&hl=en&x={x}&y={y}&z # 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 -map_widget.set_position(45.497059, -73.578451, marker=False) # Berlin, Germany +map_widget.set_position(45.497059, -73.578451, marker=False) # Montreal, Quebec map_widget.set_zoom(11) # set current position with address # map_widget.set_address("Berlin Germany", marker=False) def marker_click(marker): - print(f"marker clicked - text: {marker.text} position: {marker.position}") + print(f"marker clicked - text: {marker.text} position: {marker.position}") -root_tk.mainloop() +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() \ No newline at end of file