Skip to content

UI module RFC - #7512

Merged
Pessimistress merged 2 commits into
masterfrom
x/ui-rfc
Jan 9, 2023
Merged

Pessimistress merged 2 commits into
masterfrom
x/ui-rfc

Conversation

@Pessimistress

Copy link
Copy Markdown
Collaborator

Some relevant discussions: #5354 #6285

On top of the discussion topics raised in this document, I would also like to compile a list of use cases for this feature. What are the controls you currently use or hope to use? In what ways do they need to interact with the Deck instance?

Change List

  • New dev doc

@coveralls

coveralls commented Dec 12, 2022 •

Copy link
Copy Markdown

Coverage Status

Coverage: 90.07%. Remained the same when pulling 79d2cd4 on x/ui-rfc into b09ea63 on master.


### CSS packaging

react-map-gl (inherited from mapbox-gl) requires a separate CSS stylesheet be included in the page's head. deck.gl traditionally uses CSS-in-JS (see [getTooltip](/docs/api-reference/core/deck.md)). While I like the convenience of everything-in-one-bundle approach, the new UI module will have much more complex DOM structures, and it will be harder to design an API that allows users to customize the look and feel of their UI.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more complex DOM structures

Along these lines, how have you imagined UI be implemented such that it's easy to maintain, expressive, but also minimal? Would we employ react (or preact), HTML templates, or some other UI-in-JS framework to help? While a framework is possibly overkill, defining UI in vanilla JS can get messy and fragile.

I also acknowledge users can implement their own control as they please, but we'll be setting the example implementation.

I could imagine each instance of a UI controller mounting their own react-dom onto their container.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed, At the same time having to deal with the separate mapbox CSS is a pain, just an extra failure/frustration point for users.

I suppose it is possible to add a <style> element programmatically and have that be a long multiline string representing a proper style sheet.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kepler prolifically added classes to their DOM elements to allow for customization, and that works pretty well. It's stable, just a bit verbose.

It'd be nice to utilize CSS custom properties for easier theming too https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

These choices would allow us to separate end-user customization from implementation since the widget could be built with any CSS system as long as classes and properties were also used.


### Terminology

React and Mapbox users use "controls" to refer to UI components. However, we already call an input handler "controller" in the deck.gl context. I have seen users not differentiating the two in issues and discussions. I am concerned that introducing another concept called "control" is going to add to the confusion.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could existing input handler controllers be implemented as UI controllers? Three.js has unified their concept of a controller in this way.

https://threejs.org/examples/?q=controls#misc_controls_transform

The existing controller: Boolean prop is simpler than requiring the user to import and instantiate a controller class, but what prevents OrbitController from being implemented as a UIControl?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a much larger change than I'm willing to do in a minor release. Controller implementations are pretty deeply intertwined with the definition of Viewport and View classes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using the term "widget", e.g. import {NavigationWidget} from '@deck.gl/widgets'

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated
- Navigation: buttons to zoom / rotate / reset the viewport
- Fullscreen: button to enter / exit fullscreen mode
- Geolocate: button to track the user's location using the browser's Geolocation API
- Legend: visual comparison of sizes, colors etc. corresponding to the rendered layers and viewport

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A layer legend like the one in kepler.gl would be very useful. It'd be very challenging to represent every visual prop in every layer type, plus it could be an expensive operation to impute metrics from the data. I wonder how to balance this... perhaps users should be expected supply values themselves?

A world scale legend for MapView's zoom level.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other very useful components:

  • A compass rose - could offer both a 2D rose or a 3D / tilting rose
  • Distance ruler - Could support 3D views by showing distance scale at the place where it is rendered.
  • A simple temporal playback widget has been a top request from pydeck

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated
This RFC proposes to add a new module that packages common UI components that seamlessly integrate with deck.gl, including but not limited to:

- Marker: HTML element pinned to a location in the world space
- Navigation: buttons to zoom / rotate / reset the viewport

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each view controller type could have their own.

A gimble widget for OrbitView's orientation.

A mini globe for MapView or GlobeView.

Could it make sense to implement minimaps as a UI controller, since their often for navigation?


This RFC proposes to add a new module that packages common UI components that seamlessly integrate with deck.gl, including but not limited to:

- Marker: HTML element pinned to a location in the world space

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a note to evaluate nebula.gl's HTMLOverlay, Maplibre's Marker implementation.

I could see this using a similar interface as an IconLayer, except the rendered result is a single HTML element.

Would a good expectation be one Marker per location, or could multiple markers be placed by one UI Control? There are obvious performance implications if there are too many markers, but it seems pretty typical to pin up to a couple dozen Markers.

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated

Visualization applications often require some chrome around the WebGL canvas to offer better user experience. While it is possible for every app to implement their own UI components that interact with deck.gl, it is no trivial effort to implement them well.

This RFC proposes to add a new module that packages common UI components that seamlessly integrate with deck.gl, including but not limited to:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other use cases:

Animation with timeline libs, such as TheatreJS or motion dev tools.

Layer designer panels to speed up visual iteration using libraries, such as dat.gui or Leva.

In-world control widgets for positioning views, lighting, and other effects. Similar to transform controls and arc balls in three.js

nebula.gl (or libraries like it) could utilize this for their editable map UI elements.

Invert the implementation of @deck.gl/mapbox and @deck.gl/google-maps, so that we can specify a unified, neutral API for basemaps to implement.

ContextProvider={MapContext.Provider}
>
<StaticMap />
<NavigationControl />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would this work with multiple views? Will it be possible to attach multiple NavigationControls

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With React: https://deck.gl/docs/api-reference/react/deckgl#jsx-views

Without React: not sure, maybe we can support an additional parameter when adding the control:

new Deck({
  uiControls: [
    new NavigationControl({viewId: 'map'})
  ]
})

// or
deck.addUIControl(control: UIControl, viewId?: string)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@ibgreen ibgreen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sure this would be a very popular addition.

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated
- Navigation: buttons to zoom / rotate / reset the viewport
- Fullscreen: button to enter / exit fullscreen mode
- Geolocate: button to track the user's location using the browser's Geolocation API
- Legend: visual comparison of sizes, colors etc. corresponding to the rendered layers and viewport

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other very useful components:

  • A compass rose - could offer both a 2D rose or a 3D / tilting rose
  • Distance ruler - Could support 3D views by showing distance scale at the place where it is rendered.
  • A simple temporal playback widget has been a top request from pydeck

ContextProvider={MapContext.Provider}
>
<StaticMap />
<NavigationControl />

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

deck?: Deck;
container?: HTMLDivElement;

constructor(props: PropsT);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: IIRC interface doesn't support constructors? An alternative is abstract class which also can enforce method implementation, but maybe that is too heavyweight?

setProps: (props: PropsT) => void;

/// Event hooks
onViewStateChange?: () => void;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably good to get the view state here so that component can react to map tilting etc?

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated
1. Export a new interface `UIControl` from `@deck.gl/core`. It will define certain hook methods that a UI component can implement, along the lines of:

```js
interface UIControl<PropsT> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: UIControl seems a bit generic if they are strongly tied to deck.gl. Not sure maybe call them DeckControl?

constructor(props: PropsT);

/// Lifecycle hooks
onAdd: () => void;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Not sure if onInitialize / onFinalize makes any sense?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer add/remove since it's in the context of adding elements to the DOM.

Comment thread dev-docs/RFCs/v8.0/ui-module-rfc.md Outdated

### React

All components in `@deck.gl/ui` should work without React. `@deck.gl/react` can offer thin wrappers that work with the `DeckGL` component:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Wrappers or just JSX syntax like some existing constructs?

Any need to support refs and such things so that react apps can interact imperatively with these things?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some controls will benefit from ref / imperative APIs. For example the UserLocateControl in react-map-gl needs to support method trigger(). It will also be true for more complex controls, e.g. if Nebula implements this interface.


### CSS packaging

react-map-gl (inherited from mapbox-gl) requires a separate CSS stylesheet be included in the page's head. deck.gl traditionally uses CSS-in-JS (see [getTooltip](/docs/api-reference/core/deck.md)). While I like the convenience of everything-in-one-bundle approach, the new UI module will have much more complex DOM structures, and it will be harder to design an API that allows users to customize the look and feel of their UI.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed, At the same time having to deal with the separate mapbox CSS is a pain, just an extra failure/frustration point for users.

I suppose it is possible to add a <style> element programmatically and have that be a long multiline string representing a proper style sheet.


### CSS packaging

react-map-gl (inherited from mapbox-gl) requires a separate CSS stylesheet be included in the page's head. deck.gl traditionally uses CSS-in-JS (see [getTooltip](/docs/api-reference/core/deck.md)). While I like the convenience of everything-in-one-bundle approach, the new UI module will have much more complex DOM structures, and it will be harder to design an API that allows users to customize the look and feel of their UI.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate to styling is the question of layout. While often this is achieved via CSS, this can be error-prone and hard for users, especially if it means deploying a separate CSS file.

A common use case will be something like "put the compass in the top left, zoom controls on the bottom left, and the other controls along the right side etc". Would it be worth adding a parameter to the controls to specify the placement and have apply the correct CSS positioning, e.g.

new Deck({
  ...
  uiControls: [
    new NavigationControl({placement: 'bottom-left'}),
    new FullscreenControl({placement: 'top-right'})
  ]
})

Comment on lines +63 to +69
onViewStateChange?: () => void;
onRedraw?: () => void;
onHover?: (info) => void;
onClick?: (info) => void;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these hooks used to push data down from deck to the widget? Could there be more?

```js
interface UIControl<PropsT> {
/// Populated by core when mounted
deck?: Deck;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should the widget push a change to deck, like change the view state with a navigation widget? Should the widget call this.deck.setProps?


### CSS packaging

react-map-gl (inherited from mapbox-gl) requires a separate CSS stylesheet be included in the page's head. deck.gl traditionally uses CSS-in-JS (see [getTooltip](/docs/api-reference/core/deck.md)). While I like the convenience of everything-in-one-bundle approach, the new UI module will have much more complex DOM structures, and it will be harder to design an API that allows users to customize the look and feel of their UI.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kepler prolifically added classes to their DOM elements to allow for customization, and that works pretty well. It's stable, just a bit verbose.

It'd be nice to utilize CSS custom properties for easier theming too https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties

These choices would allow us to separate end-user customization from implementation since the widget could be built with any CSS system as long as classes and properties were also used.

@davidcalhoun

Copy link
Copy Markdown
Contributor

Navigation (namely zoom in/out) and scale legend (distance ruler) are the most critical from the perspective of the team I work on currently.

  • Navigation: needed because at the very least it makes it explicit to the user that the map is interactive - I think most users would then use their mouse scroll or pinch-zoom to zoom, but there is still likely a minority of users that would prefer to use the navigation control itself (just a guess, we haven't user tested this).

  • Scale legend / distance ruler: we're displaying geospatial data on the map, and the scale of the map is one of the first questions folks ask.

@Pessimistress
Pessimistress merged commit 4d5415b into master Jan 9, 2023
@Pessimistress
Pessimistress deleted the x/ui-rfc branch January 9, 2023 19:18
@chrisgervang

Copy link
Copy Markdown
Collaborator

While it's experimental, this anchor feature could use day reduce some of the complexity with positioning UI widgets https://developer.chrome.com/blog/tether-elements-to-each-other-with-css-anchor-positioning/

@chjch

chjch commented Jun 9, 2023

Copy link
Copy Markdown

Personally, I hope this great feature will be available soon. Is there a timeline for it to be implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants