Skip to content

Commit

Permalink
Added decimals param for Inspector GUI (#1548)
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed May 31, 2023
1 parent 773e1b6 commit 2b81a3a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 13 additions & 4 deletions geemap/geemap.py
Expand Up @@ -6550,13 +6550,16 @@ def _point_info(self, latlon, decimals=3, return_node=False):
else:
return Tree(nodes=[root_node])

def _pixels_info(self, latlon, names=None, visible=True, return_node=False):
def _pixels_info(
self, latlon, names=None, visible=True, decimals=2, return_node=False
):
"""Create the ipytree widget for displaying the pixel values at the mouse clicking point.
Args:
latlon (list | tuple): The coordinates (lat, lon) of the point.
names (str | list, optional): The names of the layers to be included. Defaults to None.
visible (bool, optional): Whether to inspect visible layers only. Defaults to True.
decimals (int, optional): Number of decimals to round the pixel values. Defaults to 2.
return_node (bool, optional): If True, return the ipytree node.
Otherwise, return the ipytree tree widget. Defaults to False.
Expand Down Expand Up @@ -6607,7 +6610,10 @@ def _pixels_info(self, latlon, names=None, visible=True, return_node=False):

keys = sorted(item.keys())
for key in keys:
layer_node.add_node(Node(f"{key}: {item[key]}", icon="file"))
value = item[key]
if isinstance(value, float):
value = round(value, decimals)
layer_node.add_node(Node(f"{key}: {value}", icon="file"))

nodes.append(layer_node)
except:
Expand Down Expand Up @@ -6726,19 +6732,22 @@ def inspect(self, latlon):
tree.nodes = nodes
return tree

def add_inspector(self, names=None, visible=True, position="topright", opened=True):
def add_inspector(
self, names=None, visible=True, decimals=2, position="topright", opened=True
):
"""Add the Inspector GUI to the map.
Args:
names (str | list, optional): The names of the layers to be included. Defaults to None.
visible (bool, optional): Whether to inspect visible layers only. Defaults to True.
decimals (int, optional): The number of decimal places to round the coordinates. Defaults to 2.
position (str, optional): The position of the Inspector GUI. Defaults to "topright".
opened (bool, optional): Whether the control is opened. Defaults to True.
"""
from .toolbar import ee_inspector_gui

ee_inspector_gui(self, names, visible, position, opened)
ee_inspector_gui(self, names, visible, decimals, position, opened)

def add_layer_manager(self, position="topright", opened=True):
"""Add the Layer Manager to the map.
Expand Down
9 changes: 7 additions & 2 deletions geemap/toolbar.py
Expand Up @@ -4616,13 +4616,16 @@ def handle_search_event(event):
m.add(data_control)


def ee_inspector_gui(m, names=None, visible=True, position="topright", opened=True):
def ee_inspector_gui(
m, names=None, visible=True, decimals=2, position="topright", opened=True
):
"""Earth Engine Inspector GUI.
Args:
m (geemap.Map): The geemap.Map object.
names (str | list, optional): The names of the layers to be included. Defaults to None.
visible (bool, optional): Whether to inspect visible layers only. Defaults to True.
decimals (int, optional): The number of decimal places to round the values. Defaults to 2.
position (str, optional): The position of the control. Defaults to "topright".
opened (bool, optional): Whether the control is opened. Defaults to True.
Expand Down Expand Up @@ -4732,7 +4735,9 @@ def handle_interaction(**kwargs):
nodes = []
point_node = m._point_info(latlon, return_node=True)
nodes.append(point_node)
pixels_node = m._pixels_info(latlon, names, visible, return_node=True)
pixels_node = m._pixels_info(
latlon, names, visible, decimals, return_node=True
)
if pixels_node.nodes:
nodes.append(pixels_node)
objects_node = m._objects_info(latlon, names, visible, return_node=True)
Expand Down

0 comments on commit 2b81a3a

Please sign in to comment.