ipyleaflet
ipyleaflet copied to clipboard
Popup attribute of a layer is not a popup instance
The popup attribute of a Layer is not a Popup instance, it's created in the frontend, which means that we cannot control the popup attributes from the backend (close_button, max_width, min_width, class_name...). We can only control the content of the popup from the backend.
I just ran into this when I was adding bqplot into the popup.
Here is an example:
import ipyleaflet as ipyl
import bqplot as bq
import random
random.seed(10)
####################
# build the map
####################
center = (33.8, -84.2)
m = ipyl.Map(center=center, zoom=9)
m.layout.height = '700px'
####################
# add rect
####################
rect = ipyl.Rectangle(
bounds=((33.92450383333333, -84.3598925), (34.013317, -84.25771166666667)),
fill_color = 'red',
)
m.add_layer(rect)
####################
# buld plot for popup
####################
countof = [random.randint(1, 100) for i in range(100)]
x_values_int = [x for x in range(len(countof))]
x_vals = x_values_int
y_vals = countof
x_scale = bq.LinearScale()
y_scale = bq.LinearScale()
ax_x = bq.Axis(
scale=x_scale,
grid_lines='none',
visible=False,
)
ax_y = bq.Axis(
scale=y_scale,
orientation='vertical',
grid_lines='none',
visible=False,
)
bars = bq.Bars(
x=x_vals,
y=y_vals,
colors=['red'],
scales={'x': x_scale, 'y': y_scale},
)
base_plot = bq.Figure(marks=[bars], axes=[ax_x, ax_y])
base_plot.title = """some title"""
base_plot.layout.height = '300px'
base_plot.layout.width = '600px'
rect.popup = base_plot
m
Screenshot:

I have tried things such as:
rect.popup.min_width = 800
rect.popup.max_width = 900
Then I can inspect
rect.popup.min_width
and the value shows 800, so it is being stored.
I see this ticket is from 2018 - so I am not sure if there is a workaround that I have missed or if anyone has any ideas of how to control the popup width.