What is the best way to call a folium map on app page load, let the user place a marker on the map, and then call a function to generate data and then add this to the existing map - my current code is as such, which calls a base map first, which lets a user place a marker on the map. Then it stores this data. Then when the user checks the box it calls a function which generates the data based on the selected coordinates. It doesn’t load back on the original map though. How do I refresh the map?
"""// Generate base map with marker placement function."""
m = geemap.Map(center=[54, 1],
zoom=6,
draw_export=True)
"""// set map data to variable and display map."""
mapdata = st_folium(m, width=1500, height=700)
"""// extract coordinates from mapdata."""
if mapdata['all_drawings']:
for i in range(0,len(mapdata['all_drawings'])):
longitudes.append(mapdata['all_drawings'][i]['geometry']['coordinates'][0])
latitudes.append(mapdata['all_drawings'][i]['geometry']['coordinates'][1])
"""// implement check box for function run request."""
if st.checkbox("Submit Model Coordinates"):
try:
data_generated = data_generation(latitudes[0],longitudes[0])
geo_j = folium.GeoJson(data=data_generated, name="GeneratedData", style_function=lambda x: {'color': 'red', 'weight': 1, 'opacity':0.5})
"""// Add data to current map."""
geo_j.add_to(m)
except AttributeError:
st.write("No data found in the area. Please select another location.")