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.

Map Viewport doesn't always update according to ViewState

See original GitHub issue

Hey there,

Description

There seems to be a problem with the OrthographicView viewport not always reflecting the viewState prop when my map loads.

Essentially, I am trying to dynamically control the viewState to constrain my view to a bounding box. A simplified version of my code is the following:

const Map = ({maxBounds}) => {
    const [viewState, setViewState] = useState(null)
    const [isMapLoaded, setIsMapLoaded] = useState(false)

   useEffect(() => {
    if (isMapLoaded) {
        const {minZoom, target} = calculateInitialViewState(maxBounds)
       setViewState(vs => ({...vs, zoom: minZoom, minZoom, target}))
    }
  }, [isMapLoaded, maxBounds] )

  const onViewStateChange = ({viewState: vs}) => {
    const {target, zoom} = calculateBoundedViewState(vs, maxBounds)
    setViewState({ ...vs, target, zoom })
  }

  return (
    <DeckGL
        onLoad={() => setIsMapLoaded(true)}
        viewState={viewState}
        onViewStateChange={onViewStateChange}
       views={new OrthographicView()}
       controller={true}
    >
        {layers}
    </DeckGL>
  )
}

The problem occurs about 20% of the times I reload the page. I’ll console.log what the current viewState is, and about 20% of the time, the viewport does not reflect that. It seems like the times it doesn’t work, the viewManager has a an {} as it’s viewState, and therefore what i see is a viewport centered at target: [0,0] and zoom: 0.

It looks to me like a lot of changes were made with viewState / initialViewState around version 8.1 that still don’t seem to be super clearly documented. Did something change that might be causing this bug?

I noticed a similar issue (https://github.com/visgl/deck.gl/issues/4489#issue-599475498), but since it is closed I figured I would open a new one.

Thanks!

Environment

Framework Version: [e.g. deck.gl 8.2.0-alpha.1] Browser Version: [e.g. Chrome 81.0] OS: [e.g. Mac OS X 10.14]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
Pessimistresscommented, Feb 20, 2021

This will be fixed in 8.5.0. You can try it right now with 8.5.0-alpha.1.

0reactions
lukaszbarkowskicommented, Jul 7, 2020

@Pessimistress It looks like it is passed to <DeckGL> correctly, but for some reason the original transition to default state doesn’t stop. I don’t specify transitionInterruption so I guess it should stop the actual one and start the new one ?

Updated demo with console.logs image

Read more comments on GitHub >

github_iconTop Results From Across the Web

React does not recognize the `viewState` prop on a DOM ...
I used some third-party package to make tooltip display in maps. The renderTooltip props is assigned by the input renderTooltip function I ...
Read more >
Troubleshooting Error Deserializing ViewState - Cannot ...
When a user has an old session opened on the browser and the OutSystems Platform Server is updated or upgraded, the view state...
Read more >
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 >
react-map-gl | default (Map) - GitHub Pages
Default: 'auto' ... The initial view state of the map. ... The camera does not actually change until the application updates the view...
Read more >
ASP.NET MVC Interview Questions - C# Corner
NET MVC framework doesn't use View State and thus reduces the ... help you to define a URL structure and map the URL...
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