I am trying to get the pixel size of an Ellipse entity. I want this information so I can draw a Point entity (which takes pixels for its size) with the same on-screen size in pixels of the Ellipse.
For my usecase, my ellipses are circles, so the major and minor axis are the same.
var positionsArray = Cesium.Cartesian3.unpackArray(ellipsePositions.outerPositions);
//compute bounding sphere
var boundingSphere = Cesium.BoundingSphere.fromPoints(positionsArray);
//compute size of each pixel in meters
var pixelSize = viewer.camera.getPixelSize(boundingSphere, viewer.scene.drawingBufferWidth, viewer.scene.drawingBufferHeight);
//compute number of pixels that original ellipse appears to be
var sizeInPixels = (2 * boundingSphere.radius) / pixelSize;
var newPoint = t._viewer.entities.add({
point: {
pixelSize: sizeInPixels,
color: Cesium.Color.GREEN,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
}
}); //I set the position later
Thanks for posting your solution here! I think what makes it complicated is just that the bounding sphere is not exposed on the Entity API. This is a private class, but this is how the Viewer accesses bounding spheres for entities:
This example is giving very different values depending the latitude position… north and south pole are returning huge difference… any idea why? thanks.