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

Allow to zoom to any layer or object3D from the viewer #1906

Open
jailln opened this issue Sep 22, 2022 · 3 comments
Open

Allow to zoom to any layer or object3D from the viewer #1906

jailln opened this issue Sep 22, 2022 · 3 comments

Comments

@jailln
Copy link
Contributor

jailln commented Sep 22, 2022

I think that an helpful API enhancement would be to add a zoomTo method to View that could either take a layer id or an object3D as parameter.

To zoom to a layer, we could use the boundingBox attribute of layers (see #1903 ) and the CameraUtils methods (see #1904).
To zoom to a 3D object, we could also use CameraUtils methods after computing the Object3D bounding box with something like this:

var box = new THREE.Box3();
box.setFromObject(object3d);

MapBox and Cesium have a similar API for this usecase (map.zoomTo() or viewer.zoomTo() respectively) and it's actually quite useful.

@mgermerie
Copy link
Contributor

Hi, thanks for the suggestion !
I agree that it could be useful to have a method in View allowing to zoom on a layer data or an object3d.

There is a method in CameraUtils called transformCameraToLookAtTarget which can zoom to a given Extent. It is used in this example to zoom to a ColorLayer data extent.
I don't know if the Source of any Layer has an extent defined. If that is the case, we could just zoom on this extent for the layers, without needing to compute boundingBox for each Layer.

In any case, it would indeed be nice to have it available in the View.

I shall investigate a bit more on this and let you know of my findings.

@jailln
Copy link
Contributor Author

jailln commented Sep 27, 2022

I agree with you that we don't need a boundingBox for each layer to implement a zoomTo method. However, I still think that each layer should have a boundingBox attribute because it is not really costly to compute nor to store and it is commonly used in many processes that itowns' users might implement and also commonly available in other geospatial visualization frameworks, so it's not only related to this issue for me (that's why I opened two separated issues).

There is a method in CameraUtils called transformCameraToLookAtTarget which can zoom to a given Extent. It is used in this example to zoom to a ColorLayer data extent. I don't know if the Source of any Layer has an extent defined. If that is the case, we could just zoom on this extent for the layers, without needing to compute boundingBox for each Layer.

Yes actually there is and I used the same logic to zoom to a bounding box in #1904. However, I think we still need a method to zoom to a bounding box for several reasons:

  • It takes into account the Z dimension to compute the range of the camera while an extent does not
  • Zooming to a 3D bounding box is more flexible in the sense it doesn't suppose that the objects it is zooming to are on the ground and it can be easily used for threejs 3D objects.
  • transformCameraToLookAtTarget currently sets the tilt to 90 by default when zooming to an extent, but this could (should?) be made configurable.
  • Some layers (e.g. 3D Tiles layers) don't have an extent defined (we could compute it from the bounding box but that would mean computing the bounding box anyway).

@mgermerie
Copy link
Contributor

We could implement the possibility to pass bounding box as third parameter of transformCameraToLookAtTarget.

@mgermerie mgermerie added this to the 2.xx.x milestone Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants