Veer7
Veer7

Reputation: 21493

adding `name` and `description` box for `Cesium PolylineCollection`

On the cesium sandcastle page @ https://cesiumjs.org/Cesium/Build/Apps/Sandcastle/?src=Polyline.html&label=Geometries

enter image description here

You can see, when I click on the purple line I get a box(top right corner of the image) indicating name of the Cesium [Polyline][2] as "Purple straight arrow at height". How can I add the same name box for the [PolylineCollection][2] (line no 5 in code below)?

Here is the code

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



var lineCollection = new Cesium.PolylineCollection(); // line no 5
lineCollection.add({
        name : "Hi",
        description : "Hi description",
        positions : Cesium.Cartesian3.fromDegreesArrayHeights([-75, 53, 500000,
                                                               -125, 53, 500000]),
        width : 10,
        followSurface : false
    });
viewer.scene.primitives.add(lineCollection);



var purpleArrow = viewer.entities.add({
    name : 'Purple straight arrow at height',
    polyline : {
        positions : Cesium.Cartesian3.fromDegreesArrayHeights([-75, 43, 500000,
                                                               -125, 43, 500000]),
        width : 10,
        followSurface : false,
        material : new Cesium.PolylineArrowMaterialProperty(Cesium.Color.PURPLE)
    }
});


viewer.zoomTo(viewer.entities);

Upvotes: 3

Views: 724

Answers (1)

emackey
emackey

Reputation: 12448

Names and descriptions are part of the higher-level "Entity" API in Cesium. Down at the graphics primitive level, where PolylineCollection is, there is no such thing.

Do you need to be using the lower-level API? Typically, users who want high-level functions like the green selection indicator, info boxes, names & descriptions, etc., should stick to Entities, not primitives.

That said, there's a way to detect when primitives are "picked" by the mouse, and look up some names and info, and command the info box to manually update. All this logic is built-in to the Entity layer though, so you should think twice before re-implementing it in your own app.

Upvotes: 2

Related Questions