ipyleaflet
ipyleaflet copied to clipboard
Popup works with Polyline but not GeoData line
I searched in the issues - it seems like there are several which mention geojson not working but not the combination I mentioned above.
Is it expected that the popup would not work on a line drawn from GeoData?
Here is the example:
from ipyleaflet import Map, Polyline, CircleMarker, GeoData
from shapely.geometry import LineString
import pandas as pd
import geopandas
import ipywidgets as widgets
import numpy as np
m = Map(center = (42.5, -41), zoom =2)
polyline_data = [
[45.51, -122.68],
[37.77, -122.43],
[34.04, -118.22]
]
geodata_data = [
[1, 35.51, -122.68],
[1, 27.77, -122.43],
[1, 24.04, -118.22]
]
line = Polyline(
locations=polyline_data,
color="green" ,
fill=False
)
line.popup = widgets.HTML(value=f"""Truck: a, green""")
m.add_layer(line)
df = pd.DataFrame(geodata_data, columns=['seq', 'latitude', 'longitude'])
gdf = geopandas.GeoDataFrame(
df, geometry=geopandas.points_from_xy(df.longitude, df.latitude))
geo_string = df.groupby('seq')['geometry'].apply(lambda x: LineString(x.tolist()))
geo_base = geopandas.GeoDataFrame(geo_string)
geo_done = GeoData(
geo_dataframe=geo_base,
style={'color': 'red'},
fill=False
)
geo_done.popup = widgets.HTML(value=f"""Truck: b, red""")
m.add_layer(geo_done)
m
When the PolyLine is clicked on (it is in green), the popup shows up:

When the GeoData line is clicked on, no popup shows up:

Adding content from chrome developer tools when
geo_done.popup = widgets.HTML(value=f"""Truck: b, red""")
from the above script is executed.
manager-base.js:86 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'then')
at x.ManagerBase.create_view (manager-base.js:86:1)
at Ie.WidgetView.create_child_view (widget.js:604:1)
at 138.b2f77ccfa8f450f6ab1d.js:formatted:2101:94
