lock entity with trackedEntity without zoom/tilt

1,205 views
Skip to first unread message

3ala...@gmail.com

unread,
Nov 20, 2018, 8:37:20 AM11/20/18
to cesium-dev
I need to lock camera on an entity on cesium while the entity moving. The entity and camera should be locked to center of the screen while the map moves on the background.

A half solution I found is to use the ( viewer.trackedEntity ) e.g. viewer.trackedEntity=entity.id << this will lock the camera to current entity target while the map moves. However, the main issue here is that the ( trackedEntity) zooms in to lowest point and tilt when this feature get activated. I don't want this zoom in or tilt feature when ( trackedEntity ) do the camera lock on the entity.

I tried to do
viewer.camera.zoomTo(100) after the (viewer.trackedEntity) but this doesn't work and not even good since initially the camera will be locked to the zoom level of ( trackedEntity ) feature.

I really need some help. How can I lock an entity and unlock it to current screen position while the map is moving.

Thanks.

Omar Shehata

unread,
Nov 20, 2018, 9:26:06 AM11/20/18
to cesium-dev
It looks like there's a "viewFrom" property on entities that might allow you to tweak that:


Here's another thread that ran into the same issue and seems to have found a solution. I haven't tried it myself, but let me know if that works:

3ala...@gmail.com

unread,
Nov 25, 2018, 2:33:35 AM11/25/18
to cesium-dev
Hi Omar,

You were so helpful, the ViewFrom helped me to tweak the camera to not make it zooms in and keep the view the same as it was.

However, I want to know how can I disable that feature which when using the viewer.trackedEntity to be centered on the view.

By default when I use viewer.trackedEntity the camera view is changed and animated to make the entity on the center of the screen, is there a way to disable this feature, I want the entity to be locked to same current position without changing the camera current view.

Thanks and appreciate your help already.

Omar Shehata

unread,
Nov 26, 2018, 10:26:00 AM11/26/18
to cesium-dev
Does the animation happen the same way regardless of how ViewFrom is set? Can you post the code you tried or a Sandcastle example of what you have so far? That'll help me see exactly what's going on. 

If it helps. this is the function in the source code which updates the camera when a trackedEntity is set:

aboody....@gmail.com

unread,
Nov 28, 2018, 6:07:25 PM11/28/18
to cesium-dev
Hi Omar,

I'm not really sure. I really need to get rid of this animation which cause the entity to be centered from ( trackedEntity )

I have posted my simple code. Just paste it on Sandcastle. You can see I added a move feature for the entity to keep it moving and on entity selection activate the trackedEntity feature.




-------------------------------

var viewer = new Cesium.Viewer('cesiumContainer');
viewer.clock.shouldAnimate = false;

viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees(-145.0744619, 50.0503706, 5000000.0)
});

viewer.trackedEntityChanged.addEventListener(function(entity) {
if (entity !== undefined) {
console.log('tracked ' + entity.id);
} else {
console.log('Stopped tracking.');
}
});

var entity;
var position = Cesium.Cartesian3.fromDegrees(-123.0744619, 44.0503706, 5000.0);
var heading = Cesium.Math.toRadians(220);
var pitch = 0;
var roll = 0;
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
var orientation = Cesium.Transforms.headingPitchRollQuaternion(position, hpr);
entity = viewer.entities.add({
id: 1,
position : position,
orientation : orientation,
model : {
uri : '../../../../Apps/SampleData/models/CesiumAir/Cesium_Air.glb',
minimumPixelSize : 128,
maximumScale : 20000
}
});

// move entity stright
var lon = -123.0744619;
var lat = 44.0503706;
var sign = 1;
var count = 0;
var i = setInterval(function(){
var diff = Cesium.Math.toRadians(1)*sign;
heading += diff;
pitch -= diff;
lon -= diff;
lat += diff;
position = Cesium.Cartesian3.fromDegrees(lon, lat, 5000.0);
count++;
entity.position = position;
}, 50);

// select entity and put camera lock on it
// toDO: don't animate camera to center , keep camera zoom to the same level
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(click) {
var pickedObject = viewer.scene.pick(click.position);
if (Cesium.defined(pickedObject)) {
console.log(pickedObject.id.id);
// viewer.trackedEntity = viewer.entities.getById(pickedObject.id.id);
entity.viewFrom = new Cesium.Cartesian3(0, 0, viewer.scene.camera.position.z);
viewer.trackedEntity = entity;
}else{
entity.viewFrom = undefined;
viewer.trackedEntity = undefined;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
Reply all
Reply to author
Forward
0 new messages