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

Camera controls #60

Closed
rokez98 opened this issue Sep 11, 2023 · 1 comment
Closed

Camera controls #60

rokez98 opened this issue Sep 11, 2023 · 1 comment

Comments

@rokez98
Copy link

rokez98 commented Sep 11, 2023

Hi, I have a question regarding camera controls.

Is there a way to access the camera controls to be able to zoom to the objects of my 3d scene? For now 'controls' property is always null when I try to access it via useThree hook

Thanks!

@RodrigoHamuy
Copy link
Owner

@rokez98 the camera is controlled by MapLibre/Mapbox. So this is out of the scope of react-three-map and more to do with react-map-gl.

Never the less, here is one way to achieve this. If you know your objects coordinates (lat long) and desired zoom level, you can use the map provider easeTo function.

Here is a declarative way to do it for example:

const EaseTo = ({latitude, longitude, zoom})=>{
  
  const map = useMap();

  useEffect(()=>{
    if(!map.current) return;
    map.current.easeTo({
      center: {lon: longitude, lat: latitude},
      zoom,
      duration: 0.3,
    })
  }, [map, latitude, longitude])

  return <></>
})
// use as <EaseTo latitude={number} longitude={number} zoom={number} />

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

No branches or pull requests

2 participants