I am rendering a mapbox map using st.pydeck_chart, I have hex layers and other layers on the map. As soon as I interact with any element on the page the map reruns and view state resets to the initial state. Is there any way to cache the view state or hold it?
pydeck==0.9.1
streamlit==1.51.0
python version = 3.11.0
this is the code snippet,
import pydeck as pdkfrom typing import List, Optional, Dict, Any, Callable
class DeckBuilder:def init(self, initial_view_state: pdk.ViewState, on_view_state_change: Optional[Callable] = None):
self.initial_view_state = initial_view_stateself.on_view_state_change = on_view_state_change
def build_deck(
self,
layers: List[Optional[pdk.Layer]],
map_style: str,
map_provider_key: str,
tooltip: Optional[Dict[str, Any]] = None,
) -> pdk.Deck:
deck = pdk.Deck(
layers=[layer for layer in layers if layer is not None],
initial_view_state=self.initial_view_state,
map_provider="mapbox",
map_style=map_style,
api_keys={"mapbox": map_provider_key},
tooltip=tooltip or {},
)
#this only returns indices and objects as mentioned in st.pydeck_chart documentation
deck.deck_widget.on_view_state_change(self.on_view_state_change)
return deck