deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

[Feat] Different tooltip per layer

Open ThomasBourgeois opened this issue 3 years ago • 4 comments

Target Use Case

At the moment, I'm doing a map with different layers regarding different assets that have different features. Currently the tooltip is really limited because for one of the layers I have the features I want displayed, but for the other layers the tooltip display null values.

Proposal

I know this is possible with plotly currently, where when you add a layer you specify the tooltip directly in that layer.

With pydeck that would be something like :

pdk.Layer(
    ...,
    tooltip="..."
)

ThomasBourgeois avatar Apr 04 '22 12:04 ThomasBourgeois

You can check which layer is picked with pickInfo.layer.

Pessimistress avatar Apr 04 '22 21:04 Pessimistress

You can check which layer is picked with pickInfo.layer.

How you do that with pydeck in Python? @Pessimistress

snehankekre avatar Jul 21 '22 08:07 snehankekre

Linking https://github.com/visgl/deck.gl/discussions/6512. It's a pity the parameter isn't implemented yet in pydeck as it's a fundamental feature and one must go through quite some hoops to style it, e.g. creating a custom column with the tooltip info. Does anyone have a good example for pickInfo.layer @snehankekre @Pessimistress? There is nothing about it in the pydeck docs.

Example custom tooltip for multiple layers

Let's say "luckily" (even though it's pretty unsafe) you can just create e.g. a new "tooltip" HTML text column in (geo)pandas for each layer you want to display. With this logic you need one separate table per layer.

Create an HTML table like this as column and pass the values from other cols you'd like to show in the tooltip with f-strings:

image

gdf["tooltip"] = f"""
<table>
    <tr>
        <th>Column 1</th>
        <th>Column 2</th>
    </tr>
    <tr>
        <td>Value 1</td>
        <td>Value A</td>
    </tr>
    <tr>
        <td>Value 2</td>
        <td>Value B</td>
    </tr>
    <tr>
        <td>Value 3</td>
        <td>Value C</td>
    </tr>
    <tr>
        <td>Value 4</td>
        <td>Value D</td>
    </tr>
    <tr>
        <td>Value 5</td>
        <td>Value E</td>
    </tr>
</table>
"""

gdf is the GeoDataFrame I use for one of my layers. The pydeck call:

r = pdk.Deck([
    polygons,
    all_points
      ],
    map_style= "light",
    tooltip={'html': '{tooltip}'},
    initial_view_state=view)

do-me avatar Feb 16 '24 13:02 do-me

Does anyone have a good example for pickInfo.layer

Unfortunately, I still don't. Unsure if it's possible in the current Python API.

snehankekre avatar Feb 20 '24 08:02 snehankekre