insh
September 22, 2015, 9:46am
1
I have encountered a stuck.I want to add label entity by an iteration. But after adding label entities by iteration,they don’t show on the globe,code like this:
var labels = Cesium.LabelCollection();
window.onload = function(){
viewer.dataSources.add(Cesium.KmlDataSource.load(’…/obor/kml/recountry.kml’));
var i;
for(i=0;i<145;i++)
{
labels.add({ //if i replace the “labels” by viewer.entities,it does show on the globe! why?
position : Cesium.Cartesian3.fromDegrees(all_lng_array[i], all_lat_array[i]),
label : {
text : all_name_array[i],
font : '22px YouYuan ',
}
})};
When using the lower level LabelCollection instead of entities, you need to add the collection to the scene for rendering:
var labels = viewer.scene.primitives.add(new Cesium.LabelCollection());
insh
September 26, 2015, 3:36pm
3
Thanks a million for your help!
As you told, I have modified my code clip like this:
var labels = viewer.scene.primitives.add(new Cesium.LabelCollection());
for(var i=0;i<all_name_array.length;i++)
{
labels.entities.add({
position : Cesium.Cartesian3.fromDegrees(all_lng_array[i], all_lat_array[i]),
label : {
text : all_name_array[i],
font : '18px YouYuan ',
fillColor : Cesium.Color.YELLOW,
outlineColor : Cesium.Color.WHITE,
outlineWidth : 1,
style : Cesium.LabelStyle.FILL_AND_OUTLINE
}});
};
However, it still doesn’t help ,the labels do not show on the globe.It must be something wrong in my code,…Eh…
But thanks a lot again!
在 2015年9月22日星期二 UTC+8下午5:46:45,zhangy…@gmail.com写道: