I need to create a billboardCollection
in Cesium JS and put it inside a entity
.
I created two billboards and tryed to add it to a billboardColletion
and then use it when I created the entity
, but just the label is showing... None of the billboards appear.
This is my code so far:
var pos = Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222);
var pinBuilder = new Cesium.PinBuilder();
var pointBillboard = {
image: pinBuilder.fromColor(Cesium.Color.SALMON, 48),
verticalOrigin: Cesium.VerticalOrigin.BOTTOM
};
var lineBillboard = {
color: Cesium.Color.WHITE,
image: "img/white.png",
pixelOffset: new Cesium.Cartesian2(0, 0),
position: pos
};
var billboards = scene.primitives.add(new Cesium.BillboardCollection());
billboards.add(pointBillboard);
billboards.add(lineBillboard);
this.entity = mapa.getViewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-75.1641667, 39.9522222),
billboard: billboards,
label: {
text: ' Ponto',
verticalOrigin: Cesium.VerticalOrigin.TOP,
horizontalOrigin: Cesium.HorizontalOrigin.RIGHT,
font: '11px Helvetica',
fillColor: Cesium.Color.WHITE,
outlineWidth: 1,
style: Cesium.LabelStyle.FILL
}
});
Is there any way to insert a billboardCollection
inside an entity
?
Thanks a lot!
No, sorry, you're mixing two different layers of the API here. The billboardCollection is part of the graphics primitive layer, and Entities are built on top of that but don't include primitives directly in this manner.
I notice that you're already calling scene.primitives.add
on the billboardCollection, so it's already in the scene. The pin isn't showing because you forgot to add position: pos
to your pointBillboard
definition. The billboards in this collection can exist completely separately from any entities that are also in the scene.
Each entity in the scene is allowed exactly one billboard, not a collection. Under the hood, many entities pool their billboards into a single collection. That collection is separate from the collection that you constructed in your own code.
In the docs, note that entity.billboard
takes a BillboardGraphics
which is essentially a description of how a single billboard's definition changes over time. It does not take an actual primitive billboard or billboardCollection.
Typically, if you have only "thousands" of billboards, you can use one entity per billboard. But if you have a lot more than that, you may have to give up the high-level entities and construct your own billboardCollection directly, as you've done here.