-
Notifications
You must be signed in to change notification settings - Fork 0
/
folium_window.py
603 lines (472 loc) · 28.2 KB
/
folium_window.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
import branca
import folium
import geopandas as gpd
import json
import math
import pandas as pd
import pydeck as pdk
import tkinter as tk
import webbrowser
from branca.element import MacroElement
from color_utils import get_styled_geojson
from folium import LayerControl
from folium_utils import calculate_bounding_box
from haversine import haversine
from jinja2 import Template
from tkinter import filedialog
from typing import Any, List, Tuple
class FoliumWindowLogic:
def __init__(self, gui=None, working_object_a=None, working_object_b=None):
self.gui = gui
self.working_object_a = working_object_a
self.working_object_b = working_object_b
def get_all_styled_geojson(self):
# Initialize a list to hold the styled GeoJSON data for each layer
styled_geojson_list = []
# Iterate over the GeoJSON data in the geojson_data_list variable
for i, geojson_data in enumerate(self.gui.geojson_data_list):
# Style the GeoJSON data using the style information appended to the layer
for feature in geojson_data['features']:
feature['properties']['style'] = feature['properties'].get('style', {})
# Add the styled GeoJSON data to the list
styled_geojson_list.append(geojson_data)
# Return the list of styled GeoJSON data
return styled_geojson_list
def get_property_names(self):
# Get the first feature from the working_object_a GeoDataFrame
feature = self.working_object_a.iloc[0]
# Get the names of the properties from the feature
property_names = list(feature.keys())
return property_names
def select_properties_for_popups(self):
# Get the selected layer index from the Listbox widget
selected_layer_indices = self.gui.folium_listbox.curselection()
if not selected_layer_indices:
message = "Please select a layer"
print(message)
return
selected_layer_index = selected_layer_indices[0]
# Open a new window to select properties for the popups of the selected layer
LayerPropertiesWindow(self.gui, self.gui.master, self.layers[selected_layer_index])
class FoliumWindowGUI(tk.Toplevel):
def __init__(self, master=None, logic=None):
super().__init__(master)
self.logic = logic
self.logic.gui = self
self.layer_count = 0
self.map_title = tk.StringVar()
self.layer_control_var = tk.BooleanVar(value=True)
self.create_widgets()
self.geojson_data_list = []
self.geojson_layers = [] # Create a new attribute to store references to the GeoJson layers
self.feature_groups = []
self.m = folium.Map()
self.selected_property = None
def create_widgets(self):
# Create a top frame to hold the Listbox and Scrollbars
self.listbox_frame = tk.Frame(self)
self.listbox_frame.grid(row=1, column=0, columnspan=2, padx=5, pady=5)
# Create a title for the listbox widget:
self.layer_listbox_label = tk.Label(self.listbox_frame, text="Available Layers")
self.layer_listbox_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
# Create the vertical scrollbar
self.yscroll = tk.Scrollbar(self.listbox_frame, orient=tk.VERTICAL)
self.yscroll.grid(row=1, column=1)
# Create the horizontal scrollbar
self.xscroll = tk.Scrollbar(self.listbox_frame, orient=tk.HORIZONTAL)
self.xscroll.grid(row=2, column=0)
# Create a Listbox widget to display the passed data
self.folium_listbox = tk.Listbox(self.listbox_frame, selectmode=tk.SINGLE, exportselection=False, xscrollcommand=self.xscroll.set, yscrollcommand=self.yscroll.set)
self.folium_listbox.grid(row=1, column=0)
# Attach the scrollbars to the Listbox
self.yscroll.config(command=self.folium_listbox.yview)
self.xscroll.config(command=self.folium_listbox.xview)
# Configure the top frame grid to resize properly
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
# Create a middle frame to hold the widgets
self.middle_frame = tk.Frame(self)
self.middle_frame.grid(row=5, column=0, columnspan=2, padx=5, pady=5)
# Create a label for the layer title entry
self.layer_title_label = tk.Label(self.middle_frame, text="Layer Title:")
self.layer_title_label.grid(row=0, column=0, padx=5, pady=5)
# Create an Entry widget for the layer title
self.layer_title_entry = tk.Entry(self.middle_frame)
self.layer_title_entry.grid(row=0, column=1, padx=5, pady=5)
# Create a button for updating the name for the selected layer
self.update_layer_name_button = tk.Button(self.middle_frame,text="Apply Name to Selected Layer",command=self.update_layer_name)
self.update_layer_name_button.grid(row=1,column=1, padx=5,pady=5)
# Create a label for the popup properties Listbox
self.popup_properties_label = tk.Label(self.middle_frame, text="Select One or More Popup Properties:")
self.popup_properties_label.grid(row=3, column=0, padx=5, pady=5)
# Create a Listbox for selecting the popup properties
self.popup_properties_listbox = tk.Listbox(self.middle_frame, selectmode=tk.MULTIPLE)
self.popup_properties_listbox.grid(row=3, column=1, padx=5, pady=5)
# Create a button for updating the popup properties for the selected layer
self.update_popup_properties_button = tk.Button(self.middle_frame,text="Apply Selected Popup Properties for Selected Layer",command=self.update_popup_properties)
self.update_popup_properties_button.grid(row=4,columnspan=2,padx=5,pady=5)
# Configure the middle frame grid to resize properly
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
# Create a bottom frame to hold the widgets
self.bottom_frame = tk.Frame(self)
self.bottom_frame.grid(row=10, column=0, columnspan=2, padx=5, pady=5)
# Create a label for the map title entry
self.map_title_label = tk.Label(self.bottom_frame, text="Map Title:")
self.map_title_label.grid(row=0, column=0, padx=5, pady=5)
# Create an Entry widget for the map title
self.map_title_entry = tk.Entry(self.bottom_frame, textvariable=self.map_title)
self.map_title_entry.grid(row=0, column=1, padx=5, pady=5)
# Create a label and OptionMenu for the map title placement
self.title_placement_label = tk.Label(self.bottom_frame, text="Title Placement:")
self.title_placement_label.grid(row=1, column=0, padx=5, pady=5)
self.title_placement_var = tk.StringVar(value="top-center")
self.title_placement_options = ["top-left", "top-right", "bottom-left", "bottom-right", "top-center", "bottom-center"]
self.title_placement_menu = tk.OptionMenu(self.bottom_frame, self.title_placement_var, *self.title_placement_options)
self.title_placement_menu.grid(row=1, column=1, padx=5, pady=5)
# Create a label and OptionMenu for the map title border color
self.title_border_color_label = tk.Label(self.bottom_frame, text="Title Border Color:")
self.title_border_color_label.grid(row=2, column=0, padx=5, pady=5)
self.title_border_color_var = tk.StringVar(value="grey")
self.title_border_color_options = ["black", "grey", "white", "red", "green", "blue"]
self.title_border_color_menu = tk.OptionMenu(self.bottom_frame, self.title_border_color_var, *self.title_border_color_options)
self.title_border_color_menu.grid(row=2, column=1, padx=5, pady=5)
# Create a label and OptionMenu for the map title border size
self.title_border_size_label = tk.Label(self.bottom_frame, text="Title Border Weight (in Pixels):")
self.title_border_size_label.grid(row=3, column=0, padx=5, pady=5)
# Create a variable to hold the border size value
self.title_border_size_var = tk.IntVar(value=1)
# Create a Scale widget for the map title border size
self.title_border_size_scale = tk.Scale(self.bottom_frame, from_=1, to=5, orient=tk.HORIZONTAL, variable=self.title_border_size_var)
self.title_border_size_scale.grid(row=3, column=1, columnspan=2, padx=5, pady=5)
# Create a label and Entry for the map title font size
self.title_font_size_label = tk.Label(self.bottom_frame, text="Title Font Size:")
self.title_font_size_label.grid(row=4, column=0, padx=5, pady=5)
# Create a variable to hold the font size value
self.title_font_size_var = tk.IntVar(value=20)
# Create a Scale widget for the map title font size
self.title_font_size_scale = tk.Scale(self.bottom_frame, from_=8, to=72, orient=tk.HORIZONTAL, variable=self.title_font_size_var)
self.title_font_size_scale.grid(row=4, column=1, columnspan=2, padx=5, pady=5)
# Create a label and OptionMenu for the map title font color
self.title_font_color_label = tk.Label(self.bottom_frame, text="Title Font Color:")
self.title_font_color_label.grid(row=5, column=0, padx=5, pady=5)
self.title_font_color_var = tk.StringVar(value="black")
self.title_font_color_options = ["black", "grey", "white", "red", "green", "blue"]
self.title_font_color_menu = tk.OptionMenu(self.bottom_frame,self.title_font_color_var,*self.title_font_color_options)
self.title_font_color_menu.grid(row=5,column=1,padx=5,pady=5)
# Create a label and OptionMenu for the map title background color
self.title_bg_color_label = tk.Label(self.bottom_frame, text="Title Background Color:")
self.title_bg_color_label.grid(row=6, column=0, padx=5, pady=5)
self.title_bg_color_var = tk.StringVar(value="white")
self.title_bg_color_options = ["black", "grey", "white", "red", "green", "blue"]
self.title_bg_color_menu = tk.OptionMenu(self.bottom_frame, self.title_bg_color_var, *self.title_bg_color_options)
self.title_bg_color_menu.grid(row=6, column=1, padx=5, pady=5)
# Create a label and OptionMenu widget for selecting the folium basemap layer
self.title_bg_color_label = tk.Label(self.bottom_frame, text="Select Basemap Layer:")
self.title_bg_color_label.grid(row=7, column=0, padx=5, pady=5)
self.basemap_options = ['stamen toner', 'stamen terrain', 'stamen watercolor', 'cartodb positron', 'cartodb dark matter', 'openstreetmap', 'none']
self.basemap_var = tk.StringVar(self)
self.basemap_var.set(self.basemap_options[0])
self.basemap_option_menu = tk.OptionMenu(self.bottom_frame, self.basemap_var, *self.basemap_options)
self.basemap_option_menu.grid(row=7, column=1, padx=5, pady=5)
# Create a button to create the folium map from active layers
self.create_map_button = tk.Button(self.bottom_frame, text="Create Folium Map from Active Layers", command=self.create_map)
self.create_map_button.grid(row=8,columnspan=2, padx=5, pady=5)
# Configure the bottom frame grid to resize properly
self.columnconfigure(0, weight=1)
self.rowconfigure(5, weight=1)
# Create a PyDeck frame to hold the widgets
self.pydeck_frame = tk.Frame(self)
self.pydeck_frame.grid(row=1, column=5, columnspan=2, padx=5, pady=5)
# Create a label for the popup properties Listbox
self.z_properties_label = tk.Label(self.pydeck_frame, text="Select Property to use as 3D Height Variable:")
self.z_properties_label.grid(row=1, column=5, padx=5, pady=5)
# Create a Listbox for selecting the popup properties
self.z_properties_listbox = tk.Listbox(self.pydeck_frame, selectmode=tk.SINGLE)
self.z_properties_listbox.grid(row=2, column=5, padx=5, pady=5)
# Create a button for updating the popup properties for the selected layer
self.z_set_button = tk.Button(self.pydeck_frame,text="Set This Property as 3D Height Variable",command=self.update_elevation_property)
self.z_set_button.grid(row=4,column=5, columnspan=2,padx=5,pady=5)
# Create a button to create the PyDeck map from active layers
self.create_z_map_button = tk.Button(self.pydeck_frame, text="Create 3D Map", command=self.create_z_map)
self.create_z_map_button.grid(row=6,column=5, columnspan=2, padx=5, pady=5)
# Configure the PyDeck frame grid to resize properly
self.columnconfigure(0, weight=1)
self.rowconfigure(1, weight=1)
def add_layer(self, geojson_str):
self.layer_count += 1
layer_title = self.layer_title_entry.get()
if not layer_title:
layer_title = f"Layer {self.layer_count}"
self.folium_listbox.insert(tk.END, layer_title)
geojson_data = json.loads(geojson_str)
self.geojson_data_list.append(geojson_data)
feature_group = folium.FeatureGroup(name=layer_title)
feature_group.add_child(folium.GeoJson(geojson_str))
feature_group.add_to(self.m)
self.feature_groups.append(feature_group)
def update_layer_name(self):
selected_index = self.folium_listbox.curselection()
if not selected_index:
return # No layer is selected
selected_index = selected_index[0]
new_layer_name = self.layer_title_entry.get()
if not new_layer_name:
return # No new layer name is entered
self.folium_listbox.delete(selected_index)
self.folium_listbox.insert(selected_index, new_layer_name)
# Update the LayerControl widget of the output Folium map with the new layer name
if self.feature_groups:
feature_group = self.feature_groups[selected_index]
feature_group.layer_name = new_layer_name
def update_popup_properties(self):
# Get the index of the currently selected layer
selected_layer_index = self.folium_listbox.curselection()[0]
# Get the list of selected properties from the Listbox
selected_properties = [self.popup_properties_listbox.get(i) for i in self.popup_properties_listbox.curselection()]
# Update the popup properties for each feature in the selected layer
geojson_data = self.geojson_data_list[selected_layer_index]
for feature in geojson_data["features"]:
if "properties" not in feature:
feature["properties"] = {}
feature["properties"]["popupProperties"] = selected_properties
# Get the list of available properties for the selected layer
available_properties = set()
for feature in geojson_data["features"]:
available_properties.update(feature["properties"].keys())
# Update the Listbox with the available properties
self.popup_properties_listbox.delete(0, tk.END)
for prop in sorted(available_properties):
self.popup_properties_listbox.insert(tk.END, prop)
def add_z_layer(self, geojson_str):
# Load the GeoJSON data
geojson_data = json.loads(geojson_str)
# Get the list of available properties from the GeoJSON data
available_properties = set()
for feature in geojson_data["features"]:
available_properties.update(feature["properties"].keys())
# Update the z_properties_listbox with the available properties
self.z_properties_listbox.delete(0, tk.END)
for prop in sorted(available_properties):
self.z_properties_listbox.insert(tk.END, prop)
def update_z_properties_listbox(self):
# Clear the current contents of the z_properties_listbox
self.z_properties_listbox.delete(0, tk.END)
# Get the list of available properties from the GeoJSON data
available_z_properties = set()
for geojson_data in self.geojson_data_list:
for feature in geojson_data["features"]:
available_properties.update(feature["properties"].keys())
# Add the available properties to the z_properties_listbox
for prop in sorted(available_properties):
self.z_properties_listbox.insert(tk.END, prop)
def update_elevation_property(self):
# Check if an item is selected in the z_properties_listbox
if not self.z_properties_listbox.curselection():
# No item is selected, so display an error message and return
tk.messagebox.showerror("Error", "Please select a property from the list")
return
# Get the index of the currently selected layer
selected_layer_index = self.folium_listbox.curselection()[0]
# Get the selected property from the z_properties_listbox
selected_property = self.z_properties_listbox.get(tk.ANCHOR)
# Update the elevation property for each feature in the selected layer
geojson_data = self.geojson_data_list[selected_layer_index]
for feature in geojson_data["features"]:
if "properties" not in feature:
feature["properties"] = {}
feature["properties"]["elevation"] = feature["properties"].get(selected_property, 0)
# Get the list of available properties for the selected layer
available_z_properties = set()
for feature in geojson_data["features"]:
available_z_properties.update(feature["properties"].keys())
# Update the Listbox with the available properties
self.z_properties_listbox.delete(0, tk.END)
for prop in sorted(available_z_properties):
self.z_properties_listbox.insert(tk.END, prop)
self.selected_property = selected_property
def create_map(self):
styled_geojson_list = self.geojson_data_list
# Get the selected layer from the folium_listbox
selected_layer = self.folium_listbox.get(tk.ANCHOR)
active_layers = list(self.folium_listbox.get(0, tk.END))
for i, layer_name in enumerate(active_layers):
feature_group = self.feature_groups[i]
if layer_name == selected_layer:
feature_group.show = True
else:
feature_group.show = False
basemap_layer = self.basemap_var.get()
if basemap_layer == 'none':
m = folium.Map()
elif basemap_layer in self.basemap_options:
m = folium.Map(tiles=basemap_layer)
else:
raise ValueError(f"Invalid basemap layer: {basemap_layer}")
min_lng, min_lat, max_lng, max_lat = float('inf'), float('inf'), float('-inf'), float('-inf')
def style_function(feature):
style = feature['properties'].get('style', {})
return style
for i, geojson_data in enumerate(styled_geojson_list):
layer_min_lng, layer_min_lat, layer_max_lng, layer_max_lat = calculate_bounding_box(geojson_data)
min_lng = min(min_lng, layer_min_lng)
min_lat = min(min_lat, layer_min_lat)
max_lng = max(max_lng, layer_max_lng)
max_lat = max(max_lat, layer_max_lat)
# Create a GeoJson layer for this data
geojson_layer = folium.GeoJson(geojson_data, style_function=style_function, overlay=True)
# Create a new FeatureGroup for this layer using the updated layer name from the Listbox
feature_group = folium.FeatureGroup(name=active_layers[i])
# Add the GeoJson layer to the FeatureGroup
feature_group.add_child(geojson_layer)
# Append a reference to the GeoJson layer to the geojson_layers list
self.geojson_layers.append(geojson_layer)
def popup_style_function(feature):
return {'fillOpacity': 0, 'weight': 0}
# Add popups to this layer
for feature in geojson_data["features"]:
if "popupProperties" in feature["properties"]:
popup_properties = feature["properties"]["popupProperties"]
popup_html = "<table>"
for prop in popup_properties:
if prop != "popupProperties":
value = feature["properties"].get(prop, "")
popup_html += f"<tr><td><b>{prop}:</b></td><td>{value}</td></tr>"
popup_html += "</table>"
# Create a new GeoJson object for this feature
feature_layer = folium.GeoJson(feature, style_function=popup_style_function)
# Add the popup to this feature
feature_layer.add_child(folium.Popup(popup_html))
# Add this feature to the layer
geojson_layer.add_child(feature_layer)
# Add this FeatureGroup to the map
feature_group.add_to(m)
centroid_lng=(min_lng+max_lng)/2
centroid_lat=(min_lat+max_lat)/2
m.location=[centroid_lat,centroid_lng]
m.fit_bounds([[min_lat,min_lng],[max_lat,max_lng]])
title = self.map_title.get()
if title:
placement = self.title_placement_var.get()
border_size = self.title_border_size_var.get()
border_color = self.title_border_color_var.get()
font_size = self.title_font_size_var.get()
font_color = self.title_font_color_var.get()
bg_color = self.title_bg_color_var.get()
if placement == "top-left":
position = f"top: 25px; left: 25px;"
elif placement == "top-right":
position = f"top: 25px; right: 25px;"
elif placement == "bottom-left":
position = f"bottom: 25px; left: 25px;"
elif placement == "bottom-right":
position = f"bottom: 25px; right: 25px;"
elif placement == "top-center":
position = f"top: 25px; left: 50%; transform: translateX(-50%);"
elif placement == "bottom-center":
position = f"bottom: 25px; left: 50%; transform: translateX(-50%);"
title_html = f"""
<div id="map-title" style="position: fixed; {position} border:{border_size}px solid {border_color}; z-index:9999; font-size:{font_size}px; color:{font_color}; background-color: {bg_color};"> {title}
</div>
<script>
// Get the map title element
var mapTitle = document.getElementById('map-title');
// Measure the width and height of the title text
var canvas = document.createElement('canvas');
var context = canvas.getContext('2d');
context.font = '{font_size}px sans-serif';
var metrics = context.measureText(mapTitle.textContent);
// Set the width and height of the map title element
mapTitle.style.width = (metrics.width + 20) + 'px';
mapTitle.style.height = (metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent + 20) + 'px';
</script>
"""
m.get_root().html.add_child(folium.Element(title_html))
if self.layer_control_var.get():
LayerControl().add_to(m)
file_name = filedialog.asksaveasfilename(defaultextension=".html", filetypes=[("HTML Files", "*.html")])
m.save(file_name)
webbrowser.open(file_name)
return m
def create_z_map(self):
# Access the styled geojson data
styled_geojson_list = self.geojson_data_list
# Load the GeoJSON data
geojson_data = json.loads(geojson_str)
# geojson_data is the GeoJSON data you want to display on the map
min_lng, min_lat, max_lng, max_lat = calculate_bounding_box(geojson_data)
# Calculate the center point of the bounding box
center_lng = (min_lng + max_lng) / 2
center_lat = (min_lat + max_lat) / 2
# Calculate the width and height of the bounding box in meters
width = haversine((center_lat, min_lng), (center_lat, max_lng)) * 1000
height = haversine((min_lat, center_lng), (max_lat, center_lng)) * 1000
# Determine an appropriate zoom level based on the size of the bounding box
zoom = max(0, round(math.log2(591657550.5 / max(width, height)) - 8))
# Create a new view state object using the center point and zoom level of the bounding box
view_state = pdk.ViewState(
latitude=center_lat,
longitude=center_lng,
zoom=zoom,
pitch=45,
bearing=0,
)
# Define the coordinates of the land cover using the calculated bounding box values
LANDCOVER = [[[min_lng, min_lat], [min_lng, max_lat], [max_lng, max_lat], [max_lng, min_lat]]]
# Create a new GeoJsonLayer using the styled GeoJSON data
geojson_layer = pdk.Layer(
"GeoJsonLayer",
data=geojson_str,
get_fill_color="properties.style.fillColor",
get_line_color="properties.style.color",
line_width_min_pixels=1,
)
# Create an empty list to store the parsed data
data = []
# Iterate over the features in the GeoJSON data
for feature in geojson_data['features']:
# Extract the relevant information from the feature
coordinates = feature['geometry']['coordinates']
fill_color = feature['properties']['style']['fillColor']
line_color = feature['properties']['style']['color']
# Append the extracted information to the data list
data.append({
'coordinates': coordinates,
'fill_color': fill_color,
'line_color': line_color,
})
# Create a Pandas DataFrame from the parsed data
df = pd.DataFrame(data)
polygon_layer = pdk.Layer(
"PolygonLayer",
df,
get_polygon="coordinates",
get_fill_color="fill_color",
get_line_color="line_color",
line_width_min_pixels=1,
)
# Set this variable to the name of the property you want to use for extrusion height
selected_property = self.selected_property
# Add an additional column to your DataFrame containing the values of the selected property
df['extrusion_height'] = [feature['properties'][selected_property] for feature in geojson_data['features']]
polygon_layer = pdk.Layer(
"PolygonLayer",
df,
get_polygon="coordinates",
get_fill_color="fill_color",
get_line_color="line_color",
get_elevation="extrusion_height",
elevation_scale=100,
extruded=True,
line_width_min_pixels=1,
)
r = pdk.Deck(layers=[polygon_layer, geojson_layer], initial_view_state=view_state)
# Use a file dialog to specify the location to save the resulting HTML map
pydeck_file_name = filedialog.asksaveasfilename(
title="Save HTML map",
defaultextension=".html",
filetypes=[("HTML files", "*.html")]
)
r.to_html(pydeck_file_name)
webbrowser.open(pydeck_file_name)
return r