Skip to content

Commit

Permalink
Merge branch 'master' of github.com:naschmitz/geemap
Browse files Browse the repository at this point in the history
  • Loading branch information
naschmitz committed Aug 29, 2023
2 parents 68bd0dd + 4b13f99 commit 0ab0903
Show file tree
Hide file tree
Showing 9 changed files with 6,628 additions and 16 deletions.
3,147 changes: 3,147 additions & 0 deletions docs/workshops/G4G_2023.ipynb

Large diffs are not rendered by default.

3,148 changes: 3,148 additions & 0 deletions examples/workshops/G4G_2023.ipynb

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions geemap/basemaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@
"format": "image/png",
"transparent": True,
},
"NLCD 2021 CONUS Land Cover": {
"url": "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2021_Land_Cover_L48/wms?",
"layers": "NLCD_2021_Land_Cover_L48",
"name": "NLCD 2021 CONUS Land Cover",
"attribution": "MRLC",
"format": "image/png",
"transparent": True,
},
"NLCD 2019 CONUS Land Cover": {
"url": "https://www.mrlc.gov/geoserver/mrlc_display/NLCD_2019_Land_Cover_L48/wms?",
"layers": "NLCD_2019_Land_Cover_L48",
Expand Down
3 changes: 2 additions & 1 deletion geemap/geemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@


class MapDrawControl(ipyleaflet.DrawControl, map_widgets.AbstractDrawControl):
""" "Implements the AbstractDrawControl for the map."""
"""Implements the AbstractDrawControl for the map."""

_roi_start = False
_roi_end = False
Expand Down Expand Up @@ -115,6 +115,7 @@ def _remove_geometry_at_index_on_draw_control(self, index):
pass

def _clear_draw_control(self):
self.data = [] # Remove all drawn features from the map.
return self.clear()


Expand Down
24 changes: 15 additions & 9 deletions geemap/map_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,10 @@ def last_feature(self):
def count(self):
return len(self.geometries)

def reset(self, clear_draw_control=False):
def reset(self, clear_draw_control=True):
"""Resets the draw controls."""
if self.layer is not None:
self.host_map.remove_layer(self.layer)
self.data = [] # Remove all drawn features from the map.
self.geometries = []
self.properties = []
self.last_geometry = None
Expand All @@ -492,7 +491,10 @@ def remove_geometry(self, geometry):
self._remove_geometry_at_index_on_draw_control(index)
if index == self.count and geometry == self.last_geometry:
# Treat this like an "undo" of the last drawn geometry.
self.last_geometry = self.geometries[-1]
if len(self.geometries):
self.last_geometry = self.geometries[-1]
else:
self.last_geometry = geometry
self.last_draw_action = DrawActions.REMOVED_LAST
if self.layer is not None:
self._redraw_layer()
Expand Down Expand Up @@ -543,7 +545,7 @@ def _clear_draw_control(self):
raise NotImplementedError()

def _get_synced_geojson_from_draw_control(self):
"""Returns an up-to-date of GeoJSON from the draw control."""
"""Returns an up-to-date list of GeoJSON from the draw control."""
raise NotImplementedError()

def _sync_geometries(self):
Expand Down Expand Up @@ -601,11 +603,15 @@ def _handle_geometry_deleted(self, geo_json):
geometry = common.geojson_to_ee(geo_json, False)
self.last_geometry = geometry
self.last_draw_action = DrawActions.DELETED
i = self.geometries.index(geometry)
del self.geometries[i]
del self.properties[i]
self._redraw_layer()
self._geometry_delete_dispatcher(self, geometry=geometry)
try:
index = self.geometries.index(geometry)
except ValueError:
return
if index >= 0:
del self.geometries[index]
del self.properties[index]
self._redraw_layer()
self._geometry_delete_dispatcher(self, geometry=geometry)


class LayerManager(ipywidgets.VBox):
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ nav:
- workshops/GEE_Workshop_2022_Part2.ipynb
- workshops/AmericaView_2023.ipynb
- workshops/SciPy_2023.ipynb
- workshops/G4G_2023.ipynb
- Notebooks:
- notebooks/00_geemap_key_features.ipynb
- notebooks/01_geemap_intro.ipynb
Expand Down
36 changes: 30 additions & 6 deletions tests/fake_ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@ def getInfo(self):


class Geometry:
def __init__(self, *_, **kwargs):
geometry = None

def __init__(self, *args, **kwargs):
if len(args):
self.geometry = args[0]
if kwargs.get("type"):
self.geom_type = kwargs.get("type")

@classmethod
def Point(self, *_, **__):
def Point(self, lat, **__):
return Geometry(type=String("Point"))

@classmethod
Expand All @@ -53,6 +57,9 @@ def BBox(self, *_, **__):
def type(self, *_, **__):
return self.geom_type

def __eq__(self, other: object):
return self.geometry == getattr(other, 'geometry')


class String:
def __init__(self, value):
Expand All @@ -63,8 +70,11 @@ def compareTo(self, other_str):


class FeatureCollection:
def __init__(self, *_, **__):
pass
features = []

def __init__(self, *args, **_):
if len(args):
self.features = args[0]

def style(self, *_, **__):
return Image()
Expand All @@ -75,10 +85,19 @@ def first(self, *_, **__):
def filterBounds(self, *_, **__):
return FeatureCollection()

def __eq__(self, other: object):
return self.features == getattr(other, 'features')


class Feature:
def __init__(self, *_, **__):
pass
feature = None
properties = None

def __init__(self, *args, **_):
if len(args) > 0:
self.feature = args[0]
if len(args) >= 2:
self.properties = args[1]

def geometry(self, *_, **__):
return Geometry(type=String("Polygon"))
Expand All @@ -99,6 +118,11 @@ def getInfo(self, *_, **__):
},
}

def __eq__(self, other: object):
featuresEqual = self.feature == getattr(other, 'feature')
propertiesEqual = self.properties == getattr(other, 'properties')
return featuresEqual and propertiesEqual


class ImageCollection:
def __init__(self, *_, **__):
Expand Down
22 changes: 22 additions & 0 deletions tests/fake_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def __init__(self):
self.zoom = 7
self.layers = []
self.ee_layer_dict = {}
self.layers = []
self.geojson_layers = []

self._recognized_attrs = self.__dict__.keys()
Expand Down Expand Up @@ -36,6 +37,27 @@ def click(self, coordinates, event_type):
def get_scale(self):
return self.scale

def find_layer_index(self, name):
layers = self.layers

for index, layer in enumerate(layers):
if layer.name == name:
return index

return -1

def add_layer(self, layer):
self.layers.append(layer)

def remove_layer(self, layer):
self.layers.remove(layer)

def substitute(self, old_layer, new_layer):
i = self.find_layer_index(old_layer)
if i >= 0:
self.layers[i] = new_layer
pass

@property
def cursor_style(self):
return self.default_style.get("cursor")
Expand Down
Loading

0 comments on commit 0ab0903

Please sign in to comment.