Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert toolbar and tool items to anywidget #2174

Open
wants to merge 68 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f2b7037
Implement LayerManager using LitElement + anywidget
naschmitz Oct 10, 2024
8e3ee04
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
acde734
Merge branch 'master' into anywidget
giswqs Oct 10, 2024
919e39a
Update static files
naschmitz Oct 11, 2024
f5af00d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2024
b87f39d
Use non-minified JS files to work around property renaming issue
naschmitz Oct 14, 2024
6381d46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2024
c31d5a9
Set up tests for layer_manager_row
sufyanAbbasi Oct 15, 2024
51a8556
Set up layer_manager_row test
sufyanAbbasi Oct 15, 2024
cdd5040
Implement LayerManager using LitElement + anywidget
naschmitz Oct 10, 2024
bbfa97d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 10, 2024
5fa9733
Update static files
naschmitz Oct 11, 2024
98ef790
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 11, 2024
0729c3d
Use non-minified JS files to work around property renaming issue
naschmitz Oct 14, 2024
b9e0d69
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2024
7195ac8
Clean up setuptools references in pyproject.toml
naschmitz Oct 14, 2024
ce4c34d
Clean up setuptools references in pyproject.toml
naschmitz Oct 15, 2024
28092e7
Fix dark mode and drop shadow issues in Colab
naschmitz Oct 15, 2024
78e0021
Remove common.css, load fonts using JS instead.
sufyanAbbasi Oct 16, 2024
9d359bc
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 16, 2024
8325c5a
Merge branch 'anywidget' into anywidget-test
sufyanAbbasi Oct 16, 2024
301d254
Rebuild
sufyanAbbasi Oct 16, 2024
0d20641
Remove extraneous files
sufyanAbbasi Oct 16, 2024
84f2661
Address comments from initial review
naschmitz Oct 16, 2024
4a462c0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 16, 2024
befdaa7
Ignore static files
naschmitz Oct 16, 2024
fc9952b
Fix TS errors
sufyanAbbasi Oct 16, 2024
7c1d6fc
Merge branch 'anywidget' into anywidget-test
sufyanAbbasi Oct 16, 2024
243c178
Merge branch 'master' into anywidget
giswqs Oct 17, 2024
25817a7
Convert tsconfig.json to spaces and export model interfaces
naschmitz Oct 18, 2024
cd6c259
Add TS tests for anywidgets
sufyanAbbasi Oct 18, 2024
9dbe4f6
Merge branch 'anywidget' into anywidget-test
sufyanAbbasi Oct 18, 2024
2700b4e
Add a tab panel component
sufyanAbbasi Oct 25, 2024
f116e98
Merge remote-tracking branch 'origin/master' into anywidget-test
sufyanAbbasi Nov 11, 2024
b79ea78
clean up styles
sufyanAbbasi Nov 11, 2024
7ae4e23
Add css classes for better testability
sufyanAbbasi Nov 11, 2024
bc8183e
Add better css classes (p2), build before test
sufyanAbbasi Nov 11, 2024
3136832
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 11, 2024
41afc67
Add a rough basemap-selector widget
sufyanAbbasi Nov 12, 2024
1991e13
Add a tab panel and rough toolbar
sufyanAbbasi Nov 13, 2024
d26c584
Add tests for basemap selector widget
sufyanAbbasi Nov 13, 2024
8058de7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 14, 2024
98c61bb
Increase margin to 4px
sufyanAbbasi Nov 14, 2024
db21945
Merge remote-tracking branch 'refs/remotes/origin/anywidget-basemap-s…
sufyanAbbasi Nov 14, 2024
9541eec
Merge branch 'anywidget-basemap-selector' into anywidget-containers
sufyanAbbasi Nov 14, 2024
6bf6fce
Merge branch 'master' into anywidget-basemap-selector
sufyanAbbasi Nov 14, 2024
3bb707f
Merge branch 'anywidget-basemap-selector' into anywidget-containers
sufyanAbbasi Nov 14, 2024
010d2be
Add working, rough toolbar (broken layer_manager)
sufyanAbbasi Nov 14, 2024
79202bb
Add None check to plot tool
sufyanAbbasi Nov 14, 2024
2b417ee
Return empty list for extra tools in core
sufyanAbbasi Nov 14, 2024
f98f91a
Unbreak layer_manager
sufyanAbbasi Nov 14, 2024
78b2066
Make sure rerendering preserves tab index
sufyanAbbasi Nov 15, 2024
8c7d332
Use primary styling to match old style
sufyanAbbasi Nov 15, 2024
6f78471
Merge branch 'anywidget-basemap-selector' into anywidget-containers
sufyanAbbasi Nov 15, 2024
a3d81c6
Support dark mode better
sufyanAbbasi Nov 15, 2024
2d55f10
Fix toolbar unit tests
sufyanAbbasi Nov 15, 2024
49e363b
Address review comments.
sufyanAbbasi Nov 15, 2024
c3ae62f
Add type annotation
sufyanAbbasi Nov 15, 2024
5e33717
Merge branch 'anywidget-basemap-selector' into anywidget-containers
sufyanAbbasi Nov 15, 2024
f589730
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 15, 2024
c2cb923
Merge branch 'master' into anywidget-containers
sufyanAbbasi Nov 19, 2024
8141698
Merge remote-tracking branch 'refs/remotes/origin/anywidget-container…
sufyanAbbasi Nov 19, 2024
a1063b4
Address reviewer comments
sufyanAbbasi Nov 19, 2024
45b2797
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
bdc574e
Extend LitWidget for ToolbarItem too
sufyanAbbasi Nov 19, 2024
39dd8b5
Remove scratch file
sufyanAbbasi Nov 19, 2024
d50a98b
Fix core tests
sufyanAbbasi Nov 19, 2024
cef79a6
Adjust margins
sufyanAbbasi Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 33 additions & 43 deletions geemap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,14 @@ def _layer_manager(self) -> Optional[map_widgets.LayerManager]:
Optional[map_widgets.LayerManager]: The layer manager widget if found, else None.
"""
if toolbar_widget := self._toolbar:
if isinstance(toolbar_widget.accessory_widget, map_widgets.LayerManager):
return toolbar_widget.accessory_widget
return next(
(
widget
for widget in toolbar_widget.accessory_widgets
if isinstance(widget, map_widgets.LayerManager)
),
None,
)
return self._find_widget_of_type(map_widgets.LayerManager)

@property
Expand Down Expand Up @@ -917,35 +923,13 @@ def add(self, obj: Any, position: str = "", **kwargs: Any) -> None:
else:
super().add(obj)

def _on_toggle_toolbar_layers(self, is_open: bool) -> None:
"""Handles the toggle event for the toolbar layers.

Args:
is_open (bool): Whether the toolbar layers are open.
"""
if is_open:
if self._layer_manager:
return

layer_manager = map_widgets.LayerManager(self)
layer_manager.header_hidden = True
layer_manager.close_button_hidden = True
layer_manager.refresh_layers()
self._toolbar.accessory_widget = layer_manager
else:
self._toolbar.accessory_widget = None
self.remove("layer_manager")

def _add_layer_manager(self, position: str, **kwargs: Any) -> None:
"""Adds a layer manager to the map.

Args:
position (str): The position to place the layer manager.
**kwargs (Any): Additional keyword arguments.
"""
if self._layer_manager:
return

layer_manager = map_widgets.LayerManager(self, **kwargs)
layer_manager.on_close = lambda: self.remove("layer_manager")
layer_manager.refresh_layers()
Expand All @@ -964,16 +948,21 @@ def _add_toolbar(self, position: str, **kwargs: Any) -> None:
if self._toolbar:
return

layer_manager = map_widgets.LayerManager(self)
layer_manager.header_hidden = True
layer_manager.close_button_hidden = True
layer_manager.refresh_layers()

toolbar_val = toolbar.Toolbar(
self, self._toolbar_main_tools(), self._toolbar_extra_tools(), **kwargs
self,
self._toolbar_main_tools(),
self._toolbar_extra_tools(),
[layer_manager],
)
toolbar_val.on_layers_toggled = self._on_toggle_toolbar_layers
toolbar_control = ipyleaflet.WidgetControl(
widget=toolbar_val, position=position
)
super().add(toolbar_control)
# Enable the layer manager by default.
toolbar_val.toggle_layers(True)

def _add_inspector(self, position: str, **kwargs: Any) -> None:
"""Adds an inspector to the map.
Expand Down Expand Up @@ -1255,65 +1244,66 @@ def _add_colorbar(
return control

def _open_help_page(
self, host_map: "MapInterface", selected: bool, item: toolbar.Toolbar.Item
self, host_map: "MapInterface", selected: bool, item: toolbar.ToolbarItem
) -> None:
"""Opens the help page.

Args:
host_map (MapInterface): The host map.
selected (bool): Whether the item is selected.
item (toolbar.Toolbar.Item): The toolbar item.
item (toolbar.ToolbarItem): The toolbar item.
"""
del host_map, item # Unused.
if selected:
coreutils.open_url("https://geemap.org")

def _toolbar_main_tools(self) -> List[toolbar.Toolbar.Item]:
def _toolbar_main_tools(self) -> List[toolbar.ToolbarItem]:
"""Gets the main tools for the toolbar.

Returns:
List[toolbar.Toolbar.Item]: The main tools for the toolbar.
List[toolbar.ToolbarItem]: The main tools for the toolbar.
"""

@toolbar._cleanup_toolbar_item
def inspector_tool_callback(
map: Map, selected: bool, item: toolbar.Toolbar.Item
map: Map, selected: bool, item: toolbar.ToolbarItem
):
del selected, item # Unused.
map.add("inspector")
return map._inspector

@toolbar._cleanup_toolbar_item
def basemap_tool_callback(map: Map, selected: bool, item: toolbar.Toolbar.Item):
def basemap_tool_callback(map: Map, selected: bool, item: toolbar.ToolbarItem):
del selected, item # Unused.
map.add("basemap_selector")
return map._basemap_selector

return [
toolbar.Toolbar.Item(
toolbar.ToolbarItem(
icon="map",
tooltip="Basemap selector",
callback=basemap_tool_callback,
reset=False,
),
toolbar.Toolbar.Item(
toolbar.ToolbarItem(
icon="info",
tooltip="Inspector",
callback=inspector_tool_callback,
reset=False,
),
toolbar.Toolbar.Item(
icon="question", tooltip="Get help", callback=self._open_help_page
toolbar.ToolbarItem(
icon="question_mark",
tooltip="Get help",
callback=self._open_help_page,
reset=True,
),
]

def _toolbar_extra_tools(self) -> Optional[List[toolbar.Toolbar.Item]]:
def _toolbar_extra_tools(self) -> List[toolbar.ToolbarItem]:
"""Gets the extra tools for the toolbar.

Returns:
Optional[List[toolbar.Toolbar.Item]]: The extra tools for the toolbar.
List[toolbar.ToolbarItem]: The extra tools for the toolbar.
"""
return None
return []

def _control_config(self) -> Dict[str, List[str]]:
"""Gets the control configuration.
Expand Down
Loading