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

Remove drawn features layer when geometries are cleared #2038

Merged
merged 5 commits into from
Jun 14, 2024
Merged
Changes from 2 commits
Commits
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
13 changes: 10 additions & 3 deletions geemap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from . import map_widgets
from . import toolbar

DRAWN_FEATURES_LAYER = "Drawn Features"
sufyanAbbasi marked this conversation as resolved.
Show resolved Hide resolved


class DrawActions(enum.Enum):
"""Action types for the draw control.
Expand Down Expand Up @@ -46,7 +48,8 @@ def __init__(self, host_map):
"""Initialize the draw control.

Args:
host_map (geemap.Map): The geemap.Map instance to be linked with the draw control.
host_map (geemap.Map): The geemap.Map instance to be linked with
the draw control.
"""

self.host_map = host_map
Expand Down Expand Up @@ -194,9 +197,9 @@ def _sync_geometries(self):
def _redraw_layer(self):
if self.host_map:
self.host_map.add_layer(
self.collection, {"color": "blue"}, "Drawn Features", False, 0.5
self.collection, {"color": "blue"}, DRAWN_FEATURES_LAYER, False, 0.5
)
self.layer = self.host_map.ee_layers.get("Drawn Features", {}).get(
self.layer = self.host_map.ee_layers.get(DRAWN_FEATURES_LAYER, {}).get(
"ee_layer", None
)

Expand Down Expand Up @@ -263,6 +266,10 @@ def handle_draw(_, action, geo_json):
self._handle_geometry_edited(geo_json)
elif action == "deleted":
self._handle_geometry_deleted(geo_json)
# Remove drawn features layer if there are no geometries.
if not self.count:
if DRAWN_FEATURES_LAYER in self.host_map.ee_layers:
self.host_map.remove_layer(DRAWN_FEATURES_LAYER)
except Exception as e:
self.reset(clear_draw_control=False)
print("There was an error creating Earth Engine Feature.")
Expand Down
Loading