Entity viewFrom property example

1,905 views
Skip to first unread message

D2P

unread,
Apr 6, 2015, 9:59:29 PM4/6/15
to cesiu...@googlegroups.com
Hello,

Can somebody provide an example of what the expected format of setting the viewFrom property of an entity is?

I would like to set the default view to be directly above the entity (like a 2D view), a specified distance above, and a specified rotation.

I'm not sure what the format of setting the property is supposed to be, and I have been unable to find any examples.

Thank you!

Hyper Sonic

unread,
Apr 7, 2015, 3:58:06 PM4/7/15
to cesiu...@googlegroups.com, stephe...@gmail.com
lookAt function should work, can read about it here http://cesiumjs.org/Cesium/Build/Documentation/Camera.html

D2P

unread,
Apr 7, 2015, 9:54:15 PM4/7/15
to cesiu...@googlegroups.com, stephe...@gmail.com
Thanks Hyper, but I think I am really looking for the viewFrom property, not the lookAt function. I want to set the default camera location in relation to the entity, at the time of creating the entity. When the trackedEntity property is set, I want the camera to default to this camera position for this specific entity.

I tried this, but it did not change the camera position at all.

entity.viewFrom = new Cesium.HeadingPitchRange(heading, Cesium.Math.toRadians(-90), 1000.0);

Hyper Sonic

unread,
Apr 7, 2015, 10:13:03 PM4/7/15
to cesiu...@googlegroups.com, stephe...@gmail.com
OK, I didn't know that it was a entity property. Briefly looking through the source I see it here and there, but I don't see where it's used to set the camera position, though I didn't do an exhaustive search.


Willem

unread,
Apr 8, 2015, 4:06:31 AM4/8/15
to cesiu...@googlegroups.com, stephe...@gmail.com
Briefly looking at the code and the API documentation ('A suggested initial offset for viewing this object.'), I think it expects a Cartesian3 that defines the offset (defined in the east-north-up reference frame).

Willem

Hyper Sonic

unread,
Apr 8, 2015, 12:49:33 PM4/8/15
to cesiu...@googlegroups.com, stephe...@gmail.com
Cool thing about looking at the code is that the reference doc is built into it, though it's not nicely formatted. I was looking through these 2 files:

EntityView.prototype.update has this line
var viewFromProperty = entity.viewFrom;
then later this line
} else if (!defined(viewFromProperty) || !defined(viewFromProperty.getValue(time, offset3D))) {

Does viewFrom value somehow get handed off to offset3D ?

Matthew Amato

unread,
Apr 8, 2015, 3:54:29 PM4/8/15
to cesiu...@googlegroups.com
viewFrom hasn't worked since the Entity API was refactored and the zoomTo and flyTo properties were introduced in the Viewer.  I submitted an issue, which I'll try and look at for 1.9: https://github.com/AnalyticalGraphicsInc/cesium/issues/2628

Flipping the order of the first 2 if/else statments starting at https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/DataSources/EntityView.js#L299 so that the sphere is checked second and viewFrom first should get you back to the old behavior.

--
You received this message because you are subscribed to the Google Groups "cesium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cesium-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

D2P

unread,
Apr 9, 2015, 12:12:26 AM4/9/15
to cesiu...@googlegroups.com
Thanks Matt, glad to hear it's in the works.

It seems like every new feature I try to use each day doesn't work. :\

Since the viewFrom property isn't working, I tried to alternatively use zoomTo in the interim. While zoomTo went to the correct position of the entity and the correct pitch and range, it did not rotate to the specified heading. Instead, it rotated to a heading of 0 no matter what I provided.

viewer.zoomTo(entity, new Cesium.HeadingPitchRange(heading, Cesium.Math.toRadians(-90), 1000.0));

I even tried explicitly setting the heading again immediately after zoomTo, but again it did not change the heading.

viewer.camera.setView({
heading: Cesium.Math.toRadians(90)
});

If I remove the zoomTo line, the setView does rotate to 90 degrees correctly. It seems like the zoomTo function is permanently breaking the heading for some reason.

What am I doing wrong?

Hyper Sonic

unread,
Apr 9, 2015, 12:48:43 PM4/9/15
to cesiu...@googlegroups.com, stephe...@gmail.com
viewer.camera.lookAt has heading, pitch, and range.

D2P

unread,
Apr 9, 2015, 10:06:50 PM4/9/15
to cesiu...@googlegroups.com, stephe...@gmail.com

Unfortunately, it appears this too is broken (or I am doing something wrong). Both zoomTo and lookAt do not set the heading regardless of what heading you provide it. The heading will always be zero.

With lookAt, I am at least able to set the heading in a separate call to setView afterwards to correctly adjust the heading. With zoomTo, it seems to have a lasting effect and even other requests at changing the heading will not work afterwards.

Matthew Amato

unread,
Apr 17, 2015, 12:02:07 PM4/17/15
to cesiu...@googlegroups.com
FYI, I just opened a PR to fix `viewFrom`: https://github.com/AnalyticalGraphicsInc/cesium/pull/2648

On Thu, Apr 9, 2015 at 10:06 PM, D2P <stephe...@gmail.com> wrote:

Unfortunately, it appears this too is broken (or I am doing something wrong). Both zoomTo and lookAt do not set the heading regardless of what heading you provide it. The heading will always be zero.

With lookAt, I am at least able to set the heading in a separate call to setView afterwards to correctly adjust the heading. With zoomTo, it seems to have a lasting effect and even other requests at changing the heading will not work afterwards.

D2P

unread,
Apr 18, 2015, 2:18:13 PM4/18/15
to cesiu...@googlegroups.com
Thanks Matthew!

Jahan Randall-Demllo

unread,
Aug 6, 2015, 2:41:34 AM8/6/15
to cesium-dev
Now that this bug has been fixed as of 1.9, can an example of this property being set to as D2P asked be provided. As I too am interested to see how this is done.
My attempts to do so have been met with the camera tracking from the side.

entity.viewFrom = new Cesium.Cartesian3(0.0, -Cesium.Math.PI_OVER_TWO, viewer.scene.camera.position.z);
viewer.trackedEntity = entity;

I suppose there's something wrong with the way I'm attempting to do this.

Matthew Amato

unread,
Aug 17, 2015, 5:27:56 PM8/17/15
to cesiu...@googlegroups.com
viewFrom expects a Cartesian3 in East-North-Up coordinates, so for example the below code causes the camera to be placed 0 meters East, 750000 meters south, and 500000 up from the entity position.

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

var redBox = viewer.entities.add({
    position: Cesium.Cartesian3.fromDegrees(-107.0, 40.0, 300000.0),
    box : {
        dimensions : new Cesium.Cartesian3(400000.0, 300000.0, 500000.0),
        material : Cesium.Color.RED.withAlpha(0.5),
        outline : true,
        outlineColor : Cesium.Color.BLACK
    },
    viewFrom: new Cesium.Cartesian3(0, -750000, 500000)
});

viewer.trackedEntity = redBox;

This area of the code is due for an overhaul and we will probably switch to a heading/pitch/range style setting or something similar to what KML already does in favor the above, but that's how it works for now.

--

Willem van der Gugten

unread,
Jan 13, 2016, 9:48:59 AM1/13/16
to cesium-dev
Hi,

How can I calculate the viewFrom (in ENU) if I have Cartesian3 values for the camera- and the entity-position?
Something like this (pseudo-code):
var entityPosition = entity.position.getValue(viewer.clock.currentTime, new Cesium.Cartesian3());
var delta = Cesium.Cartesian3.subtract(entityPosition, viewer.camera.positionWC, new Cesium.Cartesian3());
viewFrom = fixedToEastNorthUp(entityPosition, delta);

I have probably looked at the wrong places, I can only find eastNorthUpToXYZ() functions.

Thanks, Willem

artille...@gmail.com

unread,
May 6, 2019, 10:48:35 AM5/6/19
to cesium-dev
> To unsubscribe from this group and stop receiving emails from it, send an email to cesiu...@googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

As of 2019/05/06, I am implementing the code that Matthew Amato provided and it's working perfectly. Thanks a lot for your help, Matthew!

ja...@vrana.cz

unread,
May 3, 2020, 11:12:57 AM5/3/20
to cesium-dev
This is how it's computed in Camera:


I'm surprised that this is not an API function.

Dne pondělí 6. května 2019 16:48:35 UTC+2 artille...@gmail.com napsal(a):

ja...@vrana.cz

unread,
May 3, 2020, 11:35:50 AM5/3/20
to cesium-dev
I ended up computing offset from angle, horizontal distance and vertical distance, which is simple:

new Cesium.Cartesian3(-Math.sin(radians) * hDistance, -Math.cos(radians) * hDistance, vDistance)

Dne neděle 3. května 2020 17:12:57 UTC+2 ja...@vrana.cz napsal(a):

Omar Shehata

unread,
May 4, 2020, 12:40:10 PM5/4/20
to cesium-dev
Hey Jakub,

Heads up that the forum has transitioned over to Discourse and this Google Group will be put into read-only mode today. Details about the transition here.

You can find this topic on the new forum here: https://community.cesium.com/t/entity-viewfrom-property-example/2299/15
Reply all
Reply to author
Forward
0 new messages