Repository navigation
UI module RFC - #7512
UI module RFC#7512
Conversation
|
|
||
| ### 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Could existing input handler controllers be implemented as UI controllers? Three.js has unified their concept of a controller in this way.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
How about using the term "widget", e.g. import {NavigationWidget} from '@deck.gl/widgets'
| - 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
|
||
| 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: |
There was a problem hiding this comment.
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 /> |
There was a problem hiding this comment.
How would this work with multiple views? Will it be possible to attach multiple NavigationControls
There was a problem hiding this comment.
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)
ibgreen
left a comment
There was a problem hiding this comment.
I am sure this would be a very popular addition.
| - 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 |
There was a problem hiding this comment.
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 /> |
| deck?: Deck; | ||
| container?: HTMLDivElement; | ||
|
|
||
| constructor(props: PropsT); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Probably good to get the view state here so that component can react to map tilting etc?
| 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> { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Nit: Not sure if onInitialize / onFinalize makes any sense?
There was a problem hiding this comment.
I prefer add/remove since it's in the context of adding elements to the DOM.
|
|
||
| ### React | ||
|
|
||
| All components in `@deck.gl/ui` should work without React. `@deck.gl/react` can offer thin wrappers that work with the `DeckGL` component: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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'})
]
})| onViewStateChange?: () => void; | ||
| onRedraw?: () => void; | ||
| onHover?: (info) => void; | ||
| onClick?: (info) => void; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
|
Navigation (namely zoom in/out) and scale legend (distance ruler) are the most critical from the perspective of the team I work on currently.
|
f4daf8f to
79d2cd4
Compare
|
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/ |
|
Personally, I hope this great feature will be available soon. Is there a timeline for it to be implemented? |
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
Deckinstance?Change List