Skip to content

Commit

Permalink
Improve the timelapse gui (#2083)
Browse files Browse the repository at this point in the history
* Improve the timelapse gui

* Make basemap optional
  • Loading branch information
giswqs authored Jul 18, 2024
1 parent de75154 commit 6f5666c
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions geemap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,17 +2209,18 @@ def close_btn_clicked(b):
return full_widget


def timelapse_gui(m=None):
def timelapse_gui(m=None, basemap="HYBRID"):
"""Creates timelapse animations.
Args:
m (geemap.Map, optional): A geemap Map instance. Defaults to None.
basemap (str, optional): The basemap to use. Defaults to "HYBRID".
Returns:
ipywidgets: The interactive GUI.
"""
if m is not None:
m.add_basemap("HYBRID")
if m is not None and (basemap is not None):
m.add_basemap(basemap)

widget_width = "350px"
padding = "0px 0px 0px 5px" # upper, right, bottom, left
Expand All @@ -2245,8 +2246,6 @@ def timelapse_gui(m=None):
collection = widgets.Dropdown(
options=[
"Landsat TM-ETM-OLI Surface Reflectance",
"Sentinel-2AB Surface Reflectance",
"MODIS",
],
value="Landsat TM-ETM-OLI Surface Reflectance",
description="Collection:",
Expand Down Expand Up @@ -2275,7 +2274,7 @@ def timelapse_gui(m=None):
"SWIR2/NIR/Green",
"SWIR1/NIR/Red",
],
value="NIR/Red/Green",
value="SWIR1/NIR/Red",
style=style,
layout=widgets.Layout(width="165px", padding=padding),
)
Expand Down Expand Up @@ -2453,8 +2452,8 @@ def nd_index_change(change):
first_band.value = "NIR"
second_band.value = "Red"
elif nd_indices.value == "Water Index (NDWI)":
first_band.value = "NIR"
second_band.value = "SWIR1"
first_band.value = "Green"
second_band.value = "NIR"
elif nd_indices.value == "Modified Water Index (MNDWI)":
first_band.value = "Green"
second_band.value = "SWIR1"
Expand Down Expand Up @@ -2498,7 +2497,12 @@ def submit_clicked(b):
end_date = str(end_month.value).zfill(2) + "-30"

with output:
print("Computing... Please wait...")
output.clear_output()
message = "Computing... Please wait..."
if os.environ.get("EE_SOLARA", None) is None:
output.append_stdout(message)
else:
print(message)

nd_bands = None
if (first_band.value is not None) and (second_band.value is not None):
Expand All @@ -2507,11 +2511,18 @@ def submit_clicked(b):
temp_output = widgets.Output()

if m is not None:
m.default_style = {"cursor": "wait"}
out_dir = get_temp_dir()
out_gif = os.path.join(out_dir, "timelapse_" + random_string(3) + ".gif")

with temp_output:
temp_output.outputs = ()

if m.find_layer("Timelapse") is not None:
m.remove(m.find_layer("Timelapse"))
if m.find_layer("Timelapse ND") is not None:
m.remove(m.find_layer("Timelapse ND"))

m.add_landsat_ts_gif(
roi=m.user_roi,
label=title.value,
Expand All @@ -2535,7 +2546,7 @@ def submit_clicked(b):
m.centerObject(m.user_roi)

with output:
print("The timelapse has been added to the map.")
output.clear_output()
link = create_download_link(
out_gif,
title="Click here to download: ",
Expand All @@ -2548,6 +2559,8 @@ def submit_clicked(b):
)
display(link_nd)

m.default_style = {"cursor": "default"}

create_gif.on_click(submit_clicked)

reset_btn = widgets.Button(
Expand Down

0 comments on commit 6f5666c

Please sign in to comment.