I added a polygon to the scene, but Flyto was in the wrong place.
demo
Wrong boundingsphere, causing flyto to wrong location.
const redPolygon = viewer.entities.add({
name: "Red polygon on surface",
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
115.43061847, 27.31856824,
115.43062375, 27.31867814,
115.43080275, 27.31866854,
115.43079699, 27.31856296,
115.43061847, 27.31856824
]),
material: Cesium.Color.RED,
},
});
viewer.flyTo(redPolygon);
Recalculated boundingsphere:
const redPolygon = viewer.entities.add({
name: "Red polygon on surface",
polygon: {
hierarchy: Cesium.Cartesian3.fromDegreesArray([
115.43061847, 27.31856824,
115.43062375, 27.31867814,
115.43080275, 27.31866854,
115.43079699, 27.31856296,
115.43061847, 27.31856824
]),
material: Cesium.Color.RED,
},
});
const positions = redPolygon.polygon.hierarchy.getValue(Cesium.JulianDate.now()).positions;
const boundingsphere = Cesium.BoundingSphere.fromPoints(positions);
viewer.camera.flyToBoundingSphere(boundingsphere);