Отображение полилинии (с некоторой высотой) в цезии

Может кто-нибудь, пожалуйста, скажите мне, что не так с этим фрагментом кода?

    Cesium.Math.setRandomNumberSeed(1234);

    var viewer = new Cesium.Viewer('cesiumContainer');
    var entities = viewer.entities;
    var boxes = entities.add(new Cesium.Entity());
    var polylines = new Cesium.PolylineCollection();

    //Create the entities and assign each entity's parent to the group to which it belongs.
    for (var i = 0; i < 5; ++i) {
        var height = 100000.0 + (200000.0 * i);
        entities.add({
            parent : boxes,
            position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
            box : {
                dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
                material : Cesium.Color.fromRandom({alpha : 1.0})
            }
        });
        entities.add({
            parent : polylines,
            position : Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height),
            polyline : {
                width : new Cesium.ConstantProperty(2),
                material : Cesium.Color.fromRandom({alpha : 1.0}),
                followSurface : new Cesium.ConstantProperty(false)
            }
        });
    }
    viewer.zoomTo(viewer.entities);

Он отображает поля с заданными координатами, но когда я пытаюсь нарисовать полилинию, выдает эту ошибку: Uncaught TypeError: Cannot read property 'push' of undefined (в строке 300 https://cesiumjs.org/Cesium/Source/DataSources/Entity.js)

Я хочу что-то вроде этого https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases

Заранее спасибо.


person Mushu    schedule 18.05.2015    source источник


Ответы (1)


Вы смешиваете Entity API (API более высокого уровня с отслеживаемыми объектами с именами и описаниями) с Primitive Graphics API (уровень ниже, который просто отображает графические примитивы).

EDIT: похоже, Скотт Рейнольдс также ответил на этот вопрос на странице . список рассылки, и вы разместили дополнительный вопрос. Здесь я позаимствовал код "вертикальных линий" у Скотта, удалил "родительские" отношения, поскольку они здесь не используются, и добавил интерактивные описания информационных окон ко всем объектам.

Cesium.Math.setRandomNumberSeed(1234);

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

var prevHeight = 0.0;
for (var i = 0; i < 5; ++i) {
    var height = 100000.0 + (200000.0 * i);
    entities.add({
        name : 'Box ' + i,
        description : 'This box is at height: ' + height.toLocaleString() + ' m',
        position : Cesium.Cartesian3.fromDegrees(-106.0, 45.0, height),
        box : {
            dimensions : new Cesium.Cartesian3(90000.0, 90000.0, 90000.0),
            material : Cesium.Color.fromRandom({alpha : 1.0})
        }
    });
    entities.add({
        name : 'Line ' + i,
        description : 'This line is from height ' + prevHeight.toLocaleString() +
            ' m to height ' + height.toLocaleString() + ' m',
        position : Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height),
        polyline : {
            positions: [
                Cesium.Cartesian3.fromDegrees(-86.0, 55.0, prevHeight),
                Cesium.Cartesian3.fromDegrees(-86.0, 55.0, height)
            ],
            width : new Cesium.ConstantProperty(2),
            material : Cesium.Color.fromRandom({alpha : 1.0}),
            followSurface : new Cesium.ConstantProperty(false)
        }
    });

    prevHeight = height;
}
viewer.zoomTo(viewer.entities);
person emackey    schedule 18.05.2015
comment
Большое спасибо @emackey. Оно работает. Но я хочу отобразить полилинию вертикально. Как в это - person Mushu; 19.05.2015