gee-community/geemap

split_map() issue when left_label and/or right_label is not None

kirimaru-jp opened this issue · 1 comments

When using split_map(), if left_label and/or right_label is not None , there is an exception

ERROR: Uncaught exception: Traceback (most recent call last):
File "/opt/conda/lib/python3.11/site-packages/ipywidgets/widgets/widget.py", line 222, in m
return(method(self, *args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.11/site-packages/ipywidgets/widgets/widget.py", line 767, in _handle_msg
self.set_state(state)
File "/opt/conda/lib/python3.11/site-packages/ipywidgets/widgets/widget.py", line 644, in set_state
with self._lock_property(**sync_data), self.hold_trait_notifications():
File "/opt/conda/lib/python3.11/contextlib.py", line 144, in exit
next(self.gen)
File "/opt/conda/lib/python3.11/site-packages/traitlets/traitlets.py", line 1502, in hold_trait_notifications
self.notify_change(change)
File "/opt/conda/lib/python3.11/site-packages/ipywidgets/widgets/widget.py", line 695, in notify_change
super().notify_change(change)
File "/opt/conda/lib/python3.11/site-packages/traitlets/traitlets.py", line 1517, in notify_change
return self._notify_observers(change)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.11/site-packages/traitlets/traitlets.py", line 1564, in _notify_observers
c(event)
File "/opt/conda/lib/python3.11/site-packages/geemap/geemap.py", line 3289, in close_btn_click
self.remove_control(left_control)
File "/opt/conda/lib/python3.11/site-packages/ipyleaflet/leaflet.py", line 2615, in remove_control
self.remove(control)
File "/opt/conda/lib/python3.11/site-packages/geemap/core.py", line 369, in remove
super().remove(widget)
File "/opt/conda/lib/python3.11/site-packages/ipyleaflet/leaflet.py", line 2690, in remove
raise ControlException('control not on map: %r' % item)
ipyleaflet.leaflet.ControlException: control not on map: WidgetControl(options=['position', 'transparent_bg'], position='bottomleft', widget=HTML(value='Deforestation over the full study period (1993-2016)', layout=Layout(padding='0px 4px 0px 4px')))

I believe it is due to the restoration the the previous value of self.controls :

self.controls = controls

before removing left_control and/or right_control

geemap/geemap/geemap.py

Lines 3288 to 3292 in f550fc9

if left_label is not None:
self.remove_control(left_control)
if right_label is not None:
self.remove_control(right_control)

I found a solution that fixed this issue, just remove them before:

  def close_btn_click(change):
      if left_label is not None:
          self.remove_control(left_control)

      if right_label is not None:
          self.remove_control(right_control)

      if change["new"]:
          self.controls = controls
          self.layers = layers[:-1]
          self.add(layers[-1])

      self.dragging = True
giswqs commented

It would be great if you can submit a pull request to fix it.