Open
Description
As a workaround for #62 I'm trying to show some dynamic info as a marker is moved on the map using a popup. I must be doing something stupid because I can make the popup appear more than once. Or am I expecting the wrong thing and I cannot "hide" a popup and make it reappear again, after it is closed? I see that it is still in the layers
attribute of the map after being closed.
from ipyleaflet import Map, Marker, Popup
from ipywidgets import HTML, Output
m = Map(center=[0, 0], zoom=1)
m.layout.height = "200px"
display(m)
popup = Popup(
location=m.center,
child=HTML("foobar"),
close_on_escape_key=False
)
out = Output()
display(out)
@out.capture()
def moved(event, location):
"Show popup for marker iff moved to the Northern hemisphere."
global m, popup
print(event, location)
if event == "move":
lat, lon = location
if lat >= 0:
print("lat >= 0")
popup.child.value = "North"
popup.location = [lat, lon]
if popup not in m.layers:
m.add_layer(popup)
marker = Marker(location=m.center)
marker.on_move(moved)
m += marker