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

Refactor zoom for Cesium and Leaflet maps. #6815

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

Refactor zoom for Cesium and Leaflet maps. #6815

wants to merge 7 commits into from

Conversation

na9da
Copy link
Collaborator

@na9da na9da commented Jul 3, 2023

What this PR does

Fixes #6761

Changes:

  • Refactor zoom code path by moving the implementation of zoom behaviour for Cesium and Leaflet maps to Cesium/Zooming.ts and Leaflet/Zooming.ts. We could use a similar pattern to refactor picking code path by separating it to Map/Leaflet/Picking.ts and Map/Cesium/Picking.ts.
  • Separate code for 3D/2D zoom view computation from the actual zooming mechanism. We now have compute3dZoomView and compute2dZoomView functions that computes the zoom views for different target types. This makes it easier to understand and also improves extensibility without touching other parts of the code.
  • Improved zooming to clamped DataSource entities:
    if (boundingSphere && isAnyEntityClampedToGround) {
    // When zooming to clamped entities from a far away point, because the high
    // LOD terrain tiles have not yet been loaded, the computed bounding sphere
    // will be inaccurate and the resulting zoom might be far off from where
    // the entity is actually placed. To get a better focus on clamped
    // entities, we sample the terrain in highest detail to precisely clamp the
    // bounding sphere to the terrain before we zoom to it.
    await preciselyClampBoundingSphereToGround(
    boundingSphere,
    cesium,
    boundingSphere
    );

    This replicates a similar change to the Cesium Viewer. And here is a before and after example. See how when zooming to the Ducky, in the before example it is nowhere to be seen.
  • Add option to zoom to an array of MappableMixin.Instance types.
  • More spec coverage

Test me

  • Open this CI link and randomly test different types of items to see if they work as expected

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

item.rectangle.east - item.rectangle.west >= 360
) {
zoomToView = this.props.viewState.terria.mainViewer.homeCamera;
console.log("Extent is wider than world so using homeCamera.");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The idealZoom behaviour has been folded into the rest of the zoom code path.

await this.currentViewer.zoomTo(firstMappableItem, 0.0);
await this.currentViewer.zoomTo(mappables, 0.0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of zooming to first mappable in the workbench, we zoom to a view showing all the mappables.

@steve9164 steve9164 self-assigned this Jul 5, 2023
@nf-s nf-s assigned nf-s and unassigned steve9164 Sep 4, 2023
@nf-s
Copy link
Contributor

nf-s commented Sep 7, 2023

Copy link
Contributor

@nf-s nf-s left a comment

Choose a reason for hiding this comment

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

Looks great! This is so much cleaner than before. I just have two small comments

I tested with a bunch of catalog items and could only find one issue with this:

Improved zooming to clamped DataSource entities:
here is a before and after example. See how when zooming to the Ducky, in the before example it is nowhere to be seen.

This works for me in "3d terrain" mode, but in "3d smooth" mode I still get put under the globe. This may be out-of-scope for this PR, if so let me know and I can make a ticket

@@ -842,124 +836,7 @@ export default class Cesium extends GlobeOrMap {
}

doZoomTo(target: any, flightDurationSeconds = 3.0): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please type target here.

Also, can you please use ZoomTarget here

doZoomTo(
v: CameraView | Rectangle | MappableMixin.Instance,
t: any
): Promise<void> {

Comment on lines +30 to +32
* TODO: Can we can simplify by reducing everything to just CameraView?
*/
export type ZoomView3d = BoundingSphere | Cartesian3 | CameraView;
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 keeping ZoomView3d flexible will might help us in the long run - as then it will be easier to implement zoom behaviour for new catalog items/mappable items.

But there is a trade off in therms of maintenance costs. What do you think?

@nf-s nf-s removed their assignment Sep 18, 2023
This was referenced Sep 27, 2023
@nf-s nf-s mentioned this pull request Oct 24, 2023
@nf-s nf-s self-assigned this Nov 10, 2023
@nf-s nf-s mentioned this pull request Nov 15, 2023
@nf-s nf-s mentioned this pull request Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants