adding on_click event to pydeck.gl map to to open URLs

13 Views Asked by At

I have a pydeck scatterplot layer and want to be able to click on one of the features and go to a URL provided by one of the features data fields. I have read through the documentation but haven't been able to find a close enough example or get anything to work. Here's the code I have so far:

def on_click(info):
    if info.object:
        url = info.object['url']
        window.open(url)

layers = [
    pdk.Layer(
        "ScatterplotLayer",
        data=overview_map,
        get_position="geometry.coordinates",
        pickable=True,
        filled=True,
        get_fill_color=[254, 189, 51],
        auto_highlight=True,
        width_min_pixels=5,
        radius_min_pixels=3,
        on_click=on_click,
    ),
]
view_state = pdk.ViewState(latitude=8.484153, longitude=40.367431, zoom=5, bearing=0, pitch=0)
r = pdk.Deck(layers, initial_view_state=view_state, tooltip={"html": "<b>Site ID:</b> {site_id}""</br><b>Name:</b> {site}""</br><b>Closed:</b> {Closed}""</br><b>Open:</b> {Open}", "style": {"backgroundColor": "#ffe9c0","color": "#30302f"}})
r
0

There are 0 best solutions below