Hello,
I’m want access the ID of a feature in a MVTLayer (or even better would be all of its properties) which is inside a Panel pane. Here is working example (or open it in Colab):
import panel as pn
import pydeck
from functools import partial
pn.extension("deckgl")
view_state = pydeck.ViewState(
latitude = 33.740,
longitude = 35.905,
zoom = 10,
max_zoom = 11.49,
pitch = 45,
bearing = 0
)
layer = pydeck.Layer(
type = 'MVTLayer',
data = "https://raw.githubusercontent.com/bertcoerver/MVTile_tests/main/tpc_folder/{z}/{x}/{y}.pbf",
get_line_color = [0, 255, 0],
get_fill_color = [155, 0, 100],
line_width_min_pixels = 1,
pickable = True,
)
deck = pydeck.Deck(
layers = [layer],
initial_view_state = view_state,
map_style = "light",
)
pn_deck = pn.pane.DeckGL(deck)
def on_map_click(event, deck):
print(deck.layers[0])
print(event.obj.click_state)
print(event.obj.click_state["index"])
# How to find the ID thats shown in the tooltip
pn_deck.param.watch(partial(on_map_click, deck = deck), ["click_state"])
pn.Column(pn_deck)
When I hover over the map I can see the ID in the tooltip. When I click the map, there is a callback function (called on_map_click
) in which I have access to the coordinates of the click, and the Deck.
So, given the variable deck
(which contains the layer) and a coordinate, can I retrieve the corresponding ID (or properties)?
Thanks for any help!
Bert