I’ve put a small example online, and saw some heavy rendering going on, making my computer freeze.
Here’s the sample code (you can just paste it to sand castle):
function generateCoordinates(radius, centerLong, centerLat){
var r = radius/111300 // = 100 meters
, y0 = centerLat
, x0 = centerLong
, u = Math.random()
, v = Math.random()
, w = r * Math.sqrt(u)
, t = 2 * Math.PI * v
, x = w * Math.cos(t)
, y1 = w * Math.sin(t)
, x1 = x / Math.cos(y0);
var newPos = ({latitude: y0 + y1, longitude: x0 + x1});
return new Cesium.Cartesian3.fromDegrees(newPos.longitude * 180/Math.PI, newPos.latitude * 180/Math.PI);
}
function addEntity(params, collection){
var entity = collection.getOrCreateEntity(params.id);
var keys = Object.keys(params);
keys.forEach(function(value){
if (value != 'id')
entity[value] = params[value];
});
}
function getRandomId(){
return ids[Math.floor(Math.random()*ids.length)];
}
function addOrUpdateEntities(n){
entities.suspendEvents();
for (var i = 0; i < n; i++){
ids.push(i);
params = {
id: i,
position: generateCoordinates(100000, startingLocation.centerLong, startingLocation.centerLat),
label: {
text: i.toString(),
font: '8px sans-serif'
},
billboard: {
image: pinBuilder.fromColor(Cesium.Color.ROYALBLUE, 48).toDataURL(),
width : 32, // default: undefined
height : 32 // default: undefined
}
};
addEntity(params, entities);
}
entities.resumeEvents();
}
var pinBuilder = new Cesium.PinBuilder();
var vm = {};
var params;
vm.cesium = new Cesium.Viewer(cesiumContainer, {
baseLayerPicker: false,
fullscreenButton: false,
homeButton: false,
sceneModePicker: false,
selectionIndicator: false,
timeline: false,
animation: false,
geocoder: false
});
var entities = vm.entities = vm.cesium.entities;
var randomImage;
var n = 10000; //number of starting entities
var id, params;
var ids = [];
//Grand Island, Nebraska in radians
var startingLocation = {
centerLong: (-98.343286 * Math.PI / 180),
centerLat: (40.923664 * Math.PI / 180)
};
vm.cesium.camera.flyTo({
destination: new Cesium.Cartesian3.fromDegrees(startingLocation.centerLong * 180/Math.PI, startingLocation.centerLat * 180/Math.PI, 5000000)
});
addOrUpdateEntities(n);
``
I attach images that show the amount the rendering cycle takes - more than 90% of the time, the app is rendering. When I tried to measure using the timeline tool, the app was way below 60Hz (more like 10Hz at best). I’ve checked this on a stronger (offline) computer, while this (online) computer just crashed every time I tried the timeline tool.
Am I doing something wrong in the handling of entities here?