Skip to content

Commit

Permalink
Better None checks on properties lookup.
Browse files Browse the repository at this point in the history
  • Loading branch information
sufyanAbbasi committed Aug 19, 2023
1 parent 85e2dd0 commit 7c0d85a
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions geemap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def _objects_info(self, latlon):
return self._root_node("Objects", nodes)


class DrawActions(enum.StrEnum):
class DrawActions(enum.Enum):
CREATED='created'
EDITED='edited'
DELETED='deleted'
Expand Down Expand Up @@ -423,7 +423,7 @@ def features(self):

@property
def collection(self):
return ee.FeatureCollection(self.features) if self.count else None
return ee.FeatureCollection(self.features if self.count else [])

@property
def last_feature(self):
Expand All @@ -434,7 +434,7 @@ def last_feature(self):
def count(self):
return len(self.geometries)

def reset(self, clear_draw_control=True):
def reset(self, clear_draw_control=False):
"""Resets the draw controls."""
if self.layer is not None:
self.host_map.remove_layer(self.layer)
Expand All @@ -446,7 +446,12 @@ def reset(self, clear_draw_control=True):
self._clear_draw_control()

def remove_geometry(self, geometry):
index = self.geometries.index(geometry)
if not geometry:
return
try:
index = self.geometries.index(geometry)
except ValueError:
return
if index >= 0:
del self.geometries[index]
del self.properties[index]
Expand All @@ -459,14 +464,24 @@ def remove_geometry(self, geometry):
self._redraw_layer()

def get_geometry_properties(self, geometry):
index = self.geometries.index(geometry)
if not geometry:
return None
try:
index = self.geometries.index(geometry)
except ValueError:
return None
if index >= 0:
return self.properties[index]
else:
return None

def set_geometry_properties(self, geometry, property):
index = self.geometries.index(geometry)
if not geometry:
return
try:
index = self.geometries.index(geometry)
except ValueError:
return
if index >= 0:
self.properties[index] = property

Expand Down

0 comments on commit 7c0d85a

Please sign in to comment.