Error when trying to add entities to Cesium.CesiumWidget

Hi,

I am trying to add an entity in a Cesium.CesiumWidget, through its entities collection but I get the following error:

TypeError: Cannot read property 'add' of undefined

I am actually trying to reproduce the Camera demo from Sandcastle but instead of using the standard Viewer, I try to use the Widget Viewer. Below is my src code:

var viewer = new cesium.CesiumWidget('cesiumContainer');

var west = -77.0;
var south = 38.0;
var east = -72.0;
var north = 42.0;

var rectangle = Cesium.Rectangle.fromDegrees(west, south, east, north);
    viewer.camera.setView({
        destination: rectangle
    });

// Show the rectangle. Not required; just for show.
    viewer.entities.add({
        rectangle : {
            coordinates : rectangle,
            fill : false,
            outline : true,
            outlineColor : Cesium.Color.WHITE
        }
    });

I use:

- Cesium 1.19
- Windows 10 Enterprise
- Google Chrome 49.0.2623.87 m

Hello,

This code is meant to use the Viewer, not the CesiumWidget.

Replace the first line of your example with

var viewer = new Cesium.Viewer(‘cesiumContainer’);

``

Best,

Hannah

Isn't it possible to add entities using the widget in any way?

Hi Hannah,

I finally tried to add some entities as stated in this thread.

https://groups.google.com/forum/embed/?place=forum/cesium-dev&showsearch=true&showpopout=true&hideforumtitle=true&fragments=true&parenturl=http%3A%2F%2Fcesiumjs.org%2Fforum.html#!searchin/cesium-dev/CesiumWidget/cesium-dev/2MQk1VNecWs/dgBlwqdABgAJ

Thank you for your reply!