question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to update Deck.GL viewport dynamically

See original GitHub issue

Steps to repro:

  1. Run this file:
import streamlit as st
import numpy as np
import pandas as pd

df = pd.DataFrame(
    np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4],
    columns=['lat', 'lon'])

x = st.deck_gl_chart(
    viewport={
        'latitude': 0,
        'longitude': 0,
        'zoom': 11,
        'pitch': 50,
    },
    layers=[{
        'type': 'ScatterplotLayer',
        'data': df,
    }])

x.deck_gl_chart(
    viewport={
        'latitude': 37.76,  # ← this changed
        'longitude': -122.4,  # ← this changed
        'zoom': 11,
        'pitch': 50,
    },
    layers=[{
        'type': 'ScatterplotLayer',
        'data': df,
    }])

Actual: the chart is centered a (0,0), in the Atlantic ocean Expected: the chart is centered at (37, -122)

Complication: need to figure out what the desired behavior is for when the user recenters the map via the UI, and then a script rerun is triggered.

My gut feeling is that if the rerun has the same viewport as from when before the user interacted (or, may if the proto being sent is the same), the user’s interaction should take precedence. Otherwise, the new viewport setting should take precedence. This is similar to how we handle widgets.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
StefanoFioravanzocommented, Oct 30, 2019

Is there any workaround (even ugly and hacky - I don’t really care right now) to make the map fly to a specific location, until this is fixed? I have a select option and every time I select a new element (that is associated to a pair of coordinates) I would like the map to fly to that location.

1reaction
neliseiskacommented, Apr 29, 2020

I was able to do update the map with this workaround:

import time

import pandas as pd
import pydeck as pdk
import streamlit as st

all_cities = pd.DataFrame(
    [(40.7127837, -74.0059413), (34.0522342, -118.2436849), (41.8781136, -87.6297982)],
    ["New York", "Los Angeles", "Chicago"],
    ["lat", "lon"],
)

selected_city = st.selectbox("Select city", all_cities.index)

x = st.info("Updating map")
time.sleep(1)

x.pydeck_chart(
    pdk.Deck(
        map_style="mapbox://styles/mapbox/light-v9",
        initial_view_state=pdk.ViewState(
            latitude=all_cities.loc[selected_city, "lat"],
            longitude=all_cities.loc[selected_city, "lon"],
            zoom=11,
            pitch=0,
        ),
        layers=[],
    )
)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Views and Projections - deck.gl
Whenever viewState updates, the view creates a new viewport under the hood. Typically, the deck.gl user does not need to work with viewports...
Read more >
Upgrade Guide - deck.gl
All dynamic attributes now must be explicitly specified. This change makes sure that using default values results in best performance. Views and Controllers....
Read more >
What's New - deck.gl
Tiled layers now use a request scheduler to prioritize loading the most recently visible tiles during viewport navigation. See the new maxRequests prop....
Read more >
Layer Class - deck.gl
deck.gl automatically applies gamma to the opacity in an attempt to make opacity changes appear linear (i.e. the perceived opacity is visually proportional...
Read more >
Adding Interactivity - deck.gl
Controlling the Camera. Out of the box, deck.gl offers viewport controllers that map keyboard, mouse or touch input to camera state change. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found