How can I zoom on a routes - mapbox-android

what is the better way for zoom the map to show all the route after getting it?
I tried to do it with my Origin and Destination, but not working well if the route go over or down those.

You will need to create a bounding box for your camera to animate to.
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include((new LatLng(origin.latitude() , origin.longitude())))
.include((new LatLng(dest.latitude(), dest.longitude())))
.build();
map.animateCamera(CameraUpdateFactory.newLatLngBounds(latLngBounds, 250));

Related

Panning in React Three Fiber

When I right click, I can move my camera up and down. By default, when my model loads, half of its body is out of the frame. I want to move the camera down, so the whole body fits in the frame. Is there a setting to do this? I’ve tried using camera position but that didn’t work. Thank you!
when I come across cases like this I do this:
try to scale down the object first, so that I can see the whole picture
add axesHelpers to object or scene, to figure out which direction should I move to
change position of camera accordingly.

Prevent one shape from being mouse dragged through another THREE.js

I'm trying to prevent one object from going through another when I'm dragging it with the mouse. Collision detection is working, I just need to prevent the shape from being dragged through the other shape.
setForCollision: function(symbol){
let cube = new THREE.Box3().setFromObject(this.centerCube[1]);//shape is fixed in place
let cube1 = new THREE.Box3().setFromObject(symbol);//dragging with mouse
if(cube1.isIntersectionBox(cube)){
console.log(shapes touched);
//I tried repositioning. It repositions it but doesn't really stop me from dragging it. Any suggestions?
symbol.position.set(0,0,0);
}
Apparently the below is was working. I just needed to adjust the coordinates a little and it's working just fine.
object.position.set(-7,-10,1);

Threejs orbitalcontrols set target breaking camera rotation using mouse/touch

I am developing a standard panorama viewer, where a 360 picture is placed inside of a sphere and the user can look around using mouse and touch. I am using OrbtialControls for this and it is working fine.
The user can also load a new 360 picture, after loading the picture, I am trying to set the camera direction so that the user is looking in a certain direction. As I am using orbitalControls, I am using control.target.set(x,y,z) to do so. However that causes the camera to lock at that point and if I use the mouse or touch to look around, the camera position changes and it revolves around that point, rather than looking around inside the sphere.
Has anyone else seen this kind of behavior? Do I need to do something
The code is pretty simple.
controls.reset();
controls.target.set(window.newLookAt.x,window.newLookAt.y,window.newLookAt.z);
The purpose of controls.target.set(x,y,z) is to set the pivot point, so what you are facing is the expected behavior
Instead of setting the target (that has to be (0, 0, 0) in your case), why not putting the camera inside a THREE.Object3D and rotate this object
var camera = new THREE.PerspectiveCamera()
var container = new THREE.Object3D()
container.add( camera )
camera.position.set( 0, 0, 0.1 )
var controls = new THREE.OrbitControls( camera, renderer )
controls.target.set( 0, 0, 0 ) // Optional
container.rotate.y = Math.PI / 2 // Or whatever you want
So I ended up solving this myself. The issue was that my understanding of orbitControls was slightly off. All I needed to do was to set the target point in the same direction but way closer to the camera and presto, issue solved and things are working fine now.

Rotate text to face user when camera is rotated

If you take a look at my fiddle:
http://jsfiddle.net/jmg157/Y35cQ/1/
You'll see I have grid labels on the cube axes. What I'd like to do is whenever the user rotates around the cube, have the text rotate as well so that the numbers are always facing the user.
I tried things like xMarks.rotation = camera.rotation, where xMarksare the text objects, but no success. Any suggestions would be greatly appreciated.
three.js is now quaternion-based.
To make the text created with THREE.PlaneGeometry face the camera, do this:
mesh.quaternion = camera.quaternion; // EDIT - see note below
Updated fiddle: http://jsfiddle.net/Y35cQ/2/
An alternative is to use THREE.Sprite, which always faces the camera.
three.js r.63
EDIT - mesh.quaternion = camera.quaternion; no longer works. You must use this pattern instead:
mesh.quaternion.copy( camera.quaternion );
three.js r.67

TextGeometry to always face user?

I've added some text to my scene with THREE.TextGeometry, and the text seems to be stuck in whichever xy plane I place it. Any way to have it adjust to always be in plane with the screen- readable for the user?
Try
mesh.lookAt( camera.position );
The local z-axis of the mesh should then point toward the camera.
To make the text always face the screen (rather than the camera):
mesh.quaternion.copy(camera.quaternion);
Note that this differs from object.lookAt(camera); since this will result in different orientation depending on where on the screen the object is located.
Object3D.onBeforeRender can be used to update the orientation on each frame. It might be useful to disable frustum culling using Object3D.frustumCulled = false; to ensure that the callback always is triggered.

Resources