Hi
I want to plot points and rectangles in 3D way above earth. I have code that, if in 3D, all works decently but when I switch to 2D, the rectangle shows in front of the points (sandcastle code below).
Any idea what is going on?
var viewer = new Cesium.Viewer(‘cesiumContainer’,{
skyBox: false,
skyAtmosphere : false
});
/**/
var rectangle = viewer.scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(-120.0, 20.0, -60.0, 40.0),
//vertexFormat : Cesium.EllipsoidSurfaceAppearance.VERTEX_FORMAT,
height : 300000.0
})
}),
appearance : new Cesium.EllipsoidSurfaceAppearance({
aboveGround : true,
material: new Cesium.Material({
// translucent: true,
fabric : {
type : ‘Image’,
uniforms : {
image : ‘…/images/Cesium_Logo_Color.jpg’
}
}
})
})
}));
var points = viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection());
points._rs = Cesium.RenderState.fromCache({
depthTest : {
enabled : true
},
depthMask : false,
blending : Cesium.BlendingState.PRE_MULTIPLIED_ALPHA_BLEND
});
function randomPoint () {
var phi = Math.random() * 2 * Math.PI;
var rho = Math.random();
var x = Math.sqrt(rho) * Math.cos(phi);
var y = Math.sqrt(rho) * Math.sin(phi);
var xmin = -120;
var xmax = -60;
var dx = xmax - xmin;
var ymin = 20;
var ymax = 40;
var dy = ymax - ymin;
var centerx = xmin + dx * 0.5;
var centery = ymin + dy * 0.5;
var r = dx * 0.5;
var px = centerx + x * r;
var py = centery + y * r;
var pt = Cesium.Cartesian3.fromDegrees(px, py, 500000);
points.add({
position : pt,
color: new Cesium.Color(0.9, 0.01, 0.9, 0.9),
pixelSize : 2,
scaleByDistance : new Cesium.NearFarScalar(1.0e1, 4, 8.0e6, 2)
});
}
viewer.zoomTo(viewer.entities);
for (var i = 0; i < 500; i++) {
randomPoint();
}
``