deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

Clean up different Controller / Control classes in deck.gl

Open howtimeflies0 opened this issue 9 years ago • 12 comments

There are multiple Controller classes, namely ViewportController MapController + MapControllerJS OrbitController

There is no reason that we have so many controllers. Let's merge them together and give it a good name, like UIContainer.

There are also multiple Control classes, namely Controls MapControls

Controls seems to be an OrbitControls (please confirm), so let's name it so. MapControls should be extended from a general Controls class, so let's create one and do that. Change Controls to Control

howtimeflies0 avatar Oct 05 '17 23:10 howtimeflies0

I actually started on this, staring with merging AnimationMapViewController into ViewportController.

1chandu avatar Oct 05 '17 23:10 1chandu

We have several people writing docs on this, recommending slightly different things. I wrote a draft RFC on the direction I have been working in.

The RFC lays out more of a vision than a detailed plan, but the idea is that make sure we have only one ViewState (currently we have MapState, OrbitState, FirstPersonState ... and all the high level event handling is in those state classes (pure ES6).

My idea was to have different ES6 controllers that could manipulate the common ViewState in different ways, and different ES6 Viewports that could display it in different ways - see the picture in the RFC. The intention is to provide ultimate "composability" for the app.

In this model, the React controller would probably be merged into the React DeckGL component and thus disappear completely. The DeckGL component could take a controllers list of ES6 controller classes, or possibly auto infer controllers from the Viewports list.

ibgreen avatar Oct 06 '17 00:10 ibgreen

@ibgreen Yes, I agree with your proposal. Current Controller should be merged to DeckGL or a UIContainer object and current Controls should be Controller. This should be done after we merged various Controller classes in deck.gl

I was just laying out very specific action items so that we could break out from discussion that various team members feel confusing. We should definitely do what you suggested in the RFC after this issue is closed.

howtimeflies0 avatar Oct 06 '17 17:10 howtimeflies0

@ibgreen Don't know all the background, looks like ViewState has to be a union of all the possible view properties, that could be messy in long term as we add more and more different kind of viewports.

jianhuang01 avatar Oct 06 '17 19:10 jianhuang01

looks like ViewState has to be a union of all the possible view properties, that could be messy in long term as we add more and more different kind of viewports.

Yes, this is an important discussion point, whether we believe that standardizing on single ViewState is too constraining.

The idea is that the ViewState is a container for

  • an (optional) lng/lat anchor,
  • a Vector3 position (interpreted as meter offset in geospatial modes)
  • a direction (which could be a Vector3 or pitch/bearing etc - we need to pick one representation)

As an example, something like OrbitControls currently stores two angles in their view state, but by using the conversions offered by SphericalCoordinates class in math.gl the existing code can work almost without modifications with a direction vector, or with pitch and bearing.

ibgreen avatar Oct 06 '17 19:10 ibgreen

@1chandu I have cleaned up the class names and file names around the controls, controller and viewport area, let me know if I can help anything which won't overlap a lot with your work in progress, so we can move forward faster.

jianhuang01 avatar Oct 06 '17 22:10 jianhuang01

@shaojingli . @ibgreen @jianhuang01 thanks for the class name cleanup, I think remaining work can be summarized as below, in the order mentioned.

  1. Merge ViewortAnimationController into ViewportController (currently I am working, this also includes making animation working for multiple viewports as ViewportController supports multipel viewports as of today)
  2. Change names of the controller/controls/states as per above dicussion/comments in other docs. (lets keep this to just name changes and not do any functional changs so that this can be done in parallel along with 1 and both can be merged with less effort.)
  3. We need to come to the the conclusion on what should be in ViewState, once we decide we can start making corresponding changes to the controllers and viewports that either update or consume this data. As @ibgreen mentioned above we can discuss and finalize on this.
  4. Depending on what we conclude in above step we can further create subtasks and work in parallel. This will be mostly changes to ViewState and Controllers (or any new name) and viewports. This can be worked in parallel.
  5. Merging ViewportController (on whatever new new we decide) into DeckGL
  6. Making al this work with non react apps too.

So may be you can start on 2 and on Monday we can all discuss and finalize 3 and 4.

1chandu avatar Oct 06 '17 22:10 1chandu

It is not clear to me how the unified ViewState class will work, as the geospatial viewports use a different method to pin the point under the cursor comparing to non-geospatial viewports. The OrbitController in deck.gl is not a good reference point when we make this assessment as it does not handle zoom and rotate properly.

Secondly, I would like to bring to attention that we need to examine how customization will work in this new architecture. Here are some of my favorite use cases:

  • Swap drag/shift-drag behavior
  • Custom event handling (e.g. right button drag, keyboard shortcuts)
  • Custom constraints (e.g. pitch is always positive in geospatial context but can be negative in non-geospatial)
  • Add custom callbacks (e.g. onPan, onRotate)
  • Use a custom viewport

Pessimistress avatar Oct 09 '17 18:10 Pessimistress

It is not clear to me how the unified ViewState class will work, as the geospatial viewports use a different method to pin the point under the cursor comparing to non-geospatial viewports.

My general idea is that we support two types of viewports; "first person viewports" where the camera is positioned by the ViewState and "third person viewports", like WebMercator and Orbit, where the camera is looking at the ViewState.

I've noodled on it for a while, and far as I can tell, it is possible to support all of these with a common set of ViewState fields.

Swap drag/shift-drag behavior

This would be in the controller, not the common ViewState. Controllers would be an extensible hierarchy to support any type of customization, but could certain include decent basic configuration options such as this.

Custom event handling (e.g. right button drag, keyboard shortcuts)

Agreed, the first person controller especially defines a lot of keyboard shortcuts, these need to interact well with other key bindings in the app. Not fully understood.

Custom constraints (e.g. pitch is always positive in geospatial context but can be negative in non-geospatial)

Constraints can be applied by controllers and viewports, the ViewState is just a position. As an expample, a geopspatial viewport might clamp pitch, or stop displaying the map, where as the FirstPersonViewport showing the same ViewState would keep rotating and let you look up into the sky.

Add custom callbacks (e.g. onPan, onRotate)

Possible by subclassing a Controller, but perhaps we can make stock Controllers customizable.

Use a custom viewport

Yes both custom viewports and custom controllers are explicitly supported in this vision. The key idea is that the ViewState makes them all work together in "infinitely composable" ways.

ibgreen avatar Oct 10 '17 00:10 ibgreen

Assuming you are keeping the functionalities of the current MapState in the new ViewState class, then constraints must be handled by ViewState. For example, zooming with mouse wheel causes panning in order to pin the location under the cursor. Constraints to zoom must be applied before the offset for pan is calculated.

Pessimistress avatar Oct 10 '17 01:10 Pessimistress

The vision is to move the "reducer" logic from the ViewState subclasses to the controllers. There would only be one ViewState and it would only represent a "position", it would not know how to update itself or respond to events.

ibgreen avatar Oct 10 '17 02:10 ibgreen

Will be handled in by our new view class.

jianhuang01 avatar Mar 02 '18 19:03 jianhuang01