If you have the lat, long stored in the GeoJSON properties, you could access them directly when you load the GeoJSON. Here’s the code I use:
var dataSource = new Cesium.GeoJsonDataSource();
viewer.dataSources.add(dataSource);
dataSource.loadUrl(’…/…/SampleData/predios_FeatureCollection.geojson’).then(function() {
//Get the array of entities
var entities = dataSource.entities.entities;
var labels = scene.primitives.add(new Cesium.LabelCollection());
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
var id = entity.id;
var coordinadas = entity.properties.coordinates;
var coordsArreglo = coordinadas.split(’,’);
var lat = coordsArreglo[0];
var lon = coordsArreglo[1];
// Etiquetas para GeoJSON
labels.add({
position : Cesium.Cartesian3.fromDegrees(lat, lon),
text : id,
// CSS font-family
font : ‘8px SoberanaSans’,
fillColor : Cesium.Color.WHITE,
outlineColor : Cesium.Color.BLACK,
outlineWidth : 1,
style : Cesium.LabelStyle.FILL_AND_OUTLINE
});
}
});