Skip to content

chore(widgets): Encapsulate the hacky / complex setViewState() #9596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ibgreen
Copy link
Collaborator

@ibgreen ibgreen commented Apr 23, 2025

Closes #

Background

For discussion

  • Right now several widgets control the view state, which is possible with some hacky and convoluted code.
  • Instead of duplicating this in each widgets, suggest we move it up to Widget or WidgetManager.

TODO -

  • Update ResetViewWidget
  • Update GeolocateWidget
  • Update CompassWidget
  • Update ZoomWidget

Change List

  • Add Widget.setViewState
  • Use Widget.setViewState in the widgets.

@ibgreen ibgreen requested a review from chrisgervang April 23, 2025 13:59
Copy link
Collaborator

@chrisgervang chrisgervang left a comment

Choose a reason for hiding this comment

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

I'm favorable of adding a utility. View state isn't relevant to all widgets so we could also consider a ViewStateWidget subclass.

Requesting changes since the code looks broken in a few places

@@ -95,31 +92,6 @@ export class GeolocateWidget extends Widget<GeolocateWidgetProps> {
handleCoordinates = coordinates => {
this.setViewState(coordinates);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is broken

Comment on lines -102 to -103
const viewId = this.props.viewId || (viewState?.id as string) || 'default-view';
const viewport = this.viewports[viewId] || {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is necessary in widget that set view state

Comment on lines -118 to -122
onViewportChange(viewport: Viewport) {
this.viewports[viewport.id] = viewport;
}

viewports: Record<string, Viewport> = {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Keep

@@ -61,18 +64,10 @@ export class ResetViewWidget extends Widget<ResetViewWidgetProps> {

handleClick() {
const initialViewState = this.props.initialViewState || this.deck?.props.initialViewState;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We really ought to combine what this widget does and what compass widget does so that they can be used in either mode (initialViewState/viewState)

A user managing viewState would be able to use this widget too if we made homeViewState a widget prop, and stored viewports in the widget like the others.

In compass, we don't need to expose a prop but just check if initialViewState is in use.

* @note this code abuses protected methods and should be refactored,
* but does work for now until we have a cleaner solutions.
*/
setViewState({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Make protected?

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.

2 participants