Skip to content

Commit

Permalink
Added GUI for change basemaps #294
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Feb 6, 2021
1 parent 4f4a162 commit dc13a98
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,14 @@ def ok_cancel_clicked(change):
"name": "geetoolbox",
"tooltip": "GEE Toolbox for cloud computing",
},
"map": {
"name": "basemap",
"tooltip": "Change basemap",
},
"question": {
"name": "help",
"tooltip": "Get help",
},
}

if kwargs["use_voila"]:
Expand Down Expand Up @@ -752,7 +760,15 @@ def tool_callback(change):
)
self.whitebox = wbt_control
self.add_control(wbt_control)
elif tool_name == "basemap":
from .toolbar import change_basemap

change_basemap(self)
elif tool_name == "help":
import webbrowser

webbrowser.open_new_tab("https://geemap.org")
current_tool.value = False
else:
tool = change["owner"]
tool_name = tools[tool.icon]["name"]
Expand Down
45 changes: 45 additions & 0 deletions geemap/toolbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,48 @@ def ok_cancel_clicked(change):

m.add_control(tool_output_ctrl)
m.tool_output_ctrl = tool_output_ctrl


def change_basemap(m):
"""Widget for change basemaps.
Args:
m (object): geemap.Map()
"""
from .basemaps import ee_basemaps

dropdown = widgets.Dropdown(
options=list(ee_basemaps.keys()),
value="ROADMAP",
layout=widgets.Layout(width="200px")
# description="Basemaps",
)

close_btn = widgets.Button(
icon="times",
tooltip="Close the basemap widget",
button_style="primary",
layout=widgets.Layout(width="32px"),
)

basemap_widget = widgets.HBox([dropdown, close_btn])

def on_click(change):
basemap_name = change["new"]

if len(m.layers) == 1:
old_basemap = m.layers[0]
else:
old_basemap = old_basemap = m.layers[1]
m.substitute_layer(old_basemap, ee_basemaps[basemap_name])

dropdown.observe(on_click, "value")

def close_click(change):
m.toolbar_reset()
basemap_widget.close()

close_btn.on_click(close_click)

basemap_control = WidgetControl(widget=basemap_widget, position="topright")
m.add_control(basemap_control)

0 comments on commit dc13a98

Please sign in to comment.