Trouble with polylines

899 views
Skip to first unread message

dracoooo26

unread,
May 18, 2015, 6:26:03 AM5/18/15
to cesiu...@googlegroups.com

Can someone please tell me what's wrong with this piece of code?

    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);

It displays boxes at the given coordinates but when I am trying to draw a poly-line it gives this error: Uncaught TypeError: Cannot read property 'push' of undefined (on line 300 ofhttps://cesiumjs.org/Cesium/Source/DataSources/Entity.js)

I want something like this https://cesiumjs.org/Cesium/Apps/Sandcastle/index.html?src=Custom%20DataSource.html&label=Showcases

Thanks in advance.

Scott Reynolds

unread,
May 19, 2015, 9:16:48 AM5/19/15
to cesiu...@googlegroups.com
The crash is caused by attempting to use a PolylineCollection as the parent of an entity.  You can eliminate the crash by changing line 6 to

var polylines = entities.add(new Cesium.Entity());

At which point you will need to supply positions to the PolylineGraphics object to have a line drawn.

Scott
Message has been deleted

dracoooo26

unread,
May 20, 2015, 1:33:03 AM5/20/15
to cesiu...@googlegroups.com
Thank you so much. 
I want a vertical line. Can you please help me with that.

Scott Reynolds

unread,
May 20, 2015, 9:44:13 AM5/20/15
to cesiu...@googlegroups.com
Below you will find code to draw a polyline from one height to the next, similar to what you did with the boxes.

    Cesium.Math.setRandomNumberSeed(1234);

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

    //Create the entities and assign each entity's parent to the group to which it belongs.
    var prevHeight = 0.0;
    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 : {
                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);

dracoooo26

unread,
May 21, 2015, 12:04:29 AM5/21/15
to cesiu...@googlegroups.com
Thank you so much! You made my day.

dracoooo26

unread,
May 21, 2015, 12:43:37 AM5/21/15
to cesiu...@googlegroups.com
How can I display tooltip when I hover over the polyline?

Mike LP

unread,
May 22, 2015, 10:03:03 AM5/22/15
to cesiu...@googlegroups.com, naya...@gmail.com
onHover is going to be a difficult proposition because of the expense of auto picking at each pixel the mouse hovers over.  You're better off with a click event for triggering a tooltip.

bushra...@kics.edu.pk

unread,
May 29, 2015, 3:35:19 AM5/29/15
to cesiu...@googlegroups.com, naya...@gmail.com

Mike LP

unread,
May 29, 2015, 10:33:45 AM5/29/15
to cesiu...@googlegroups.com, bushra...@kics.edu.pk, bushra...@kics.edu.pk, naya...@gmail.com
I don't see why not :)

you could do this in 1 of 2 ways that I can think of off the top of my head.
  • Custom Canvas on Material on a single geometry
  • Multiple Geometries that have their position adjusted accordingly.
If your going to be displaying charts, presumably on a billboard or overlay, I personally would recommend the canvas route.

Anyone else have an alternative or recommendation?
Reply all
Reply to author
Forward
0 new messages