Hello,
We've been trying to animate opacity changes on a few multipolygons from a GeoJSON data source.
Currently, we're iterating through the datasource's entities every second or so using `setInterval()`
for (var entity_idx = 0; entity_idx < region.entities.values.length; entity_idx++) {
var entity = region.entities.getById(region.entities.values[entity_idx].id);
entity.polygon.material.color = REGION_COLOR[name].withAlpha(state[name]);
}
This functions reasonably well and has been the only way we could determine to animate polygones in this way in cesium. The entire code is below:
// State for the intervals.
var state = {
foo: 0,
//...
};
var intervalId = window.setInterval(_ => {
// Check done at the bottom!
let done = 0;
for (var region_idx = 0; region_idx < viewer.dataSources.length; region_idx++) {
var region = viewer.dataSources.get(region_idx);
// ...
if (state[name] >= target+0.1) {
done++;
continue;
} else {
// Set each polygon's new color.
state[name] += 0.05;
for (var entity_idx = 0; entity_idx < region.entities.values.length; entity_idx++) {
var entity = region.entities.getById(region.entities.values[entity_idx].id);
entity.polygon.material.color = REGION_COLOR[name].withAlpha(state[name]);
}
}
}
if (done >= 5) { window.clearInterval(intervalId); return; }
}, 1000);
We noticed with this method there is flickering every interval, it seems to be when cesium redraws. The polgons will go opage for just a frame or two and then turn the desired opacity.
Is there a preferred way of animating opacity or is there a tactic to counteract this flickering?
Thanks,
Andrew