Skip to content
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

Moved Viewer functionality to CesiumWidget class #12202

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jfayot
Copy link
Contributor

@jfayot jfayot commented Sep 18, 2024

Description

This is a proposal to move Viewer functionalities not related to widgets to CesiumWidget class as proposed in #11967.

Issue number and link

#11967

Testing plan

  • Updated ViewerSpec.js
  • Updated CesiumWidgetSpec.js
  • Updated Cesium Widget sandcastle

I kept duplicate tests in ViewerSpec, may be some can be removed as they are implemented in CesiumWidgetSpec now?

Author checklist

  • I have submitted a Contributor License Agreement
  • I have added my name to CONTRIBUTORS.md
  • I have updated CHANGES.md with a short summary of my change
  • I have added or updated unit tests to ensure consistent code coverage
  • I have updated the inline documentation, and included code examples where relevant
  • I have performed a self-review of my code

Copy link

Thank you for the pull request, @jfayot!

✅ We can confirm we have a CLA on file for you.

@ggetz
Copy link
Contributor

ggetz commented Sep 18, 2024

@jjspace Could you please take a pass on this PR and see if this is a direction we'd like to go API-wise? Please be mindful of any breaking changes, and deprecate or preserve functionality where we can.

@jfayot
Copy link
Contributor Author

jfayot commented Sep 20, 2024

@jjspace any update on this one? 👀

Copy link
Contributor

@jjspace jjspace left a comment

Choose a reason for hiding this comment

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

Thanks @jfayot, this is looking good. sorry for the delay, github doesn't make it very easy to review diffs for things that move between files... I had a few initial comments

I kept duplicate tests in ViewerSpec, may be some can be removed as they are implemented in CesiumWidgetSpec now?

Generally we don't write specs that test "dependencies" of an object. I would say any tests that are for viewer functions that are now just passed through to widget functions should be removed.

Comment on lines -1748 to -1750
this.screenSpaceEventHandler.removeInputAction(
ScreenSpaceEventType.LEFT_CLICK
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this is still needed for the pickAndSelectObject that's added?

Comment on lines +529 to +532
this._screenSpaceEventHandler.setInputAction(
pickAndTrackObject,
ScreenSpaceEventType.LEFT_DOUBLE_CLICK
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this click handler should be moved back to the Viewer. Moving the functionality to track an entity into the CesiumWidget is good so you can do CesiumWidget.trackedEntity = ... but setting up the click handler interaction is a Viewer oriented feature. Basically I would expect the handler in Viewer to be able to do this._cesiumWidget.trackedEntity = pickEntity() (with the extra checks it previously had).

Comment on lines -957 to -960
cesiumWidget.screenSpaceEventHandler.setInputAction(
pickAndTrackObject,
ScreenSpaceEventType.LEFT_DOUBLE_CLICK
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given my other comment this should be brought back.

Comment on lines 1636 to +1642
// Unsubscribe from data sources
const dataSources = this.dataSources;
const dataSourceLength = dataSources.length;
for (i = 0; i < dataSourceLength; i++) {
for (let i = 0; i < dataSourceLength; i++) {
this._dataSourceRemoved(dataSources, dataSources.get(i));
}
this._dataSourceRemoved(undefined, this._dataSourceDisplay.defaultDataSource);
this._dataSourceRemoved(undefined, this.dataSourceDisplay.defaultDataSource);
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic now lives in CesiumWidget.destroy() too, is it still needed here?

},

/**
* Gets or sets the data source to track with the viewer's clock.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Gets or sets the data source to track with the viewer's clock.
* Gets or sets the data source to track with the widget's clock.

I'll comment on a couple other instances of this but please do a pass yourself to make sure code copied over refers to a widget not a viewer in this file

* @param {ContextOptions} [options.contextOptions] Context and WebGL creation properties passed to {@link Scene}.
* @param {Element|string} [options.creditContainer] The DOM element or ID that will contain the {@link CreditDisplay}. If not specified, the credits are added
* to the bottom of the widget itself.
* @param {Element|string} [options.creditViewport] The DOM element or ID that will contain the credit pop up created by the {@link CreditDisplay}. If not specified, it will appear over the widget itself.
* @param {DataSourceCollection} [options.dataSources=new DataSourceCollection()] The collection of data sources visualized by the widget. If this parameter is provided,
* the instance is assumed to be owned by the caller and will not be destroyed when the viewer is destroyed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* the instance is assumed to be owned by the caller and will not be destroyed when the viewer is destroyed.
* the instance is assumed to be owned by the caller and will not be destroyed when the widget is destroyed.

Comment on lines +1434 to +1438
function clearZoom(viewer) {
viewer._zoomPromise = undefined;
viewer._zoomTarget = undefined;
viewer._zoomOptions = undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

For this and a handful of functions below that were moved over the argument names should be swapped out so they don't refer to a viewer anymore

Suggested change
function clearZoom(viewer) {
viewer._zoomPromise = undefined;
viewer._zoomTarget = undefined;
viewer._zoomOptions = undefined;
}
function clearZoom(widget) {
widget._zoomPromise = undefined;
widget._zoomTarget = undefined;
widget._zoomOptions = undefined;
}

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.

3 participants