Giter Site home page Giter Site logo

Comments (5)

dcooley avatar dcooley commented on June 26, 2024 1

Thanks for the extra detail. And I've been meaining to revisit the viewState logic / code so thanks for bringing this up. When I first implemented it I had a lot of issues getting it to work in both a shiny & non-shiny environment, and getting the map & layers to update correctly.

I'll try and set some time aside next week to look at this in more detail.

from mapdeck.

dcooley avatar dcooley commented on June 26, 2024

Thanks for the PR - now merged

from mapdeck.

dcooley avatar dcooley commented on June 26, 2024

Something in this commit causes the map to freeze, so I've reverted to the commit before this.

from mapdeck.

dcooley avatar dcooley commented on June 26, 2024

something else was wrong so I've fully reverted this

from mapdeck.

hdmm3 avatar hdmm3 commented on June 26, 2024

Hi @dcooley, first of all apologies for those half-baked PRs. This time I'll share my thoughts first. I've been digging about the intended behaviour of deck.gl when using either initialViewState or viewState props. Here are some of my interpretations of what's going on when using the initialViewState prop:

  • At creation the viewState object will simply be set to the input initialViewState prop.
  • When using initialViewState, the onViewStateChange callback called during controller interaction, is internally followed by an update to the internal viewState here. This update will track changes to the viewState in a nested object viewState[viewId]. That way multiple views can save their own viewState independently. Most importantly, the current view state will be located in that nested object, instead of at the root viewState. Also the viewManager will be updated.
  • Currently, md_change_location overwrites the internal viewState through setProps({initialViewState}) effectively destroying the nested object created during onViewStateChange.
  • If a call to md_change_location is made after controller interaction, reading the values of the viewState object will pick stale values of the view instead of the most current ones.

In order to avoid fully overwriting the viewState, the initialViewState prop could be set in md_change_location as follows:

window[map_id + 'map'].setProps({
      initialViewState: {
        ...window[map_id + 'map'].viewState,
        [map_id]: {
          longitude: currentLon,
          latitude: currentLat,
          zoom: currentZoom,
          maxZoom: currentMaxZoom,
          minZoom: currentMinZoom,
          maxPitch: currentMaxPitch,
          minPitch: currentMinPitch,
          pitch: currentPitch,
          bearing: currentBearing,
          transitionInterpolator: transition === "fly" ? new deck.FlyToInterpolator() : new deck.LinearInterpolator(),
          transitionDuration: duration,
          controller: true}        
      }
    });

As such, the current viewState for the map_id could be retrieved using viewManager.getViewState(), as follows:

currentViewState = window[map_id + 'map'].viewManager?.getViewState(map_id) || window[map_id + 'map'].viewState;

getViewState() seems to be the safest approach. I'm not sure if after deck.gl 8+ the "default-view" viewId will even occur when the DeckGL views prop defines views with id as it's done with mapdeck.

I hope this helps!

from mapdeck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.