Skip to content

Commit

Permalink
Type annotate and clean up MapInterface
Browse files Browse the repository at this point in the history
These new methods and class variables are already being used in various `map_widgets` classes.
  • Loading branch information
naschmitz committed Oct 8, 2024
1 parent 6af1f83 commit 61868b3
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions geemap/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import enum
import logging
import math
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Type
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, TypedDict, Type

import ee
import ipyleaflet
Expand Down Expand Up @@ -403,8 +403,18 @@ def _clear_draw_control(self) -> None:
class MapInterface:
"""Interface for all maps."""

# The layers on the map.
ee_layers: Dict[str, Dict[str, Any]]
class EELayerMetadata(TypedDict):
"""Metadata for layers backed by Earth Engine objects."""

ee_object: ee.ComputedObject
ee_layer: Any
vis_params: Dict[str, Any]

# All layers (including basemaps, GeoJSON layers, etc.).
layers: List[Any]

# Layers backed by Earth Engine objects and keyed by layer name.
ee_layers: Dict[str, EELayerMetadata]

# The GeoJSON layers on the map.
geojson_layers: List[Any]
Expand Down Expand Up @@ -551,6 +561,14 @@ def add_layer(
del ee_object, vis_params, name, shown, opacity # Unused.
raise NotImplementedError()

def remove_layer(self, layer: Any) -> None:
"""Removes a layer from the map.
Args:
layer (str): The layer to remove.
"""
del layer # Unused.
raise NotImplementedError()


class Map(ipyleaflet.Map, MapInterface):
"""The Map class inherits the ipyleaflet Map class.
Expand Down

0 comments on commit 61868b3

Please sign in to comment.