Sandcastle example: Cesium Sandcastle
Browser: Google Chrome 119.0.6045.160
Operating System: Microsoft Windows 10 Professional
Source Code:
const viewer = new Cesium.Viewer(“cesiumContainer”);
const instances = [ ];
const polygonGeometry1 = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy([{ “x”: -2400641.090816039, “y”: 5381130.100542436, “z”: 2433328.5092790457 }, { “x”: -2400474.9719961607, “y”: 5381408.726737343, “z”: 2432879.19963749 }, { “x”: -2401689.930302587, “y”: 5380956.179691228, “z”: 2432682.408250566 }, { “x”: -2401636.078986657, “y”: 5380731.1518189395, “z”: 2433229.5619592783 }, { “x”: -2401056.3660955857, “y”: 5380825.658537882, “z”: 2433590.23144021 }])
});
const polygonInstance1 = new Cesium.GeometryInstance({
geometry: polygonGeometry1,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.AQUA.withAlpha(0.3))
},
});
instances.push(polygonInstance1);
const polygonGeometry2 = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy([{ “x”: -2401516.764516469, “y”: 5380675.1539282, “z”: 2433469.5256546633 }, { “x”: -2401099.3682896723, “y”: 5381176.246928616, “z”: 2432777.94279018 }, { “x”: -2401535.3805373986, “y”: 5381232.170150966, “z”: 2432227.516087851 }, { “x”: -2402269.347054639, “y”: 5380837.068363779, “z”: 2432375.8157362673 }, { “x”: -2401942.311879878, “y”: 5380556.648291801, “z”: 2433312.607624896 }])
});
const polygonInstance2 = new Cesium.GeometryInstance({
geometry: polygonGeometry2,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.YELLOW.withAlpha(0.5))
},
});
instances.push(polygonInstance2);
const polygonGeometry3 = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy([{ “x”: -2401267.806317249, “y”: 5380732.599506225, “z”: 2433587.3856536835 }, { “x”: -2401094.7140932013, “y”: 5380973.462258056, “z”: 2433228.0018187007 }, { “x”: -2401456.962450918, “y”: 5380918.131284394, “z”: 2432994.434511724 }, { “x”: -2401926.5443844274, “y”: 5380661.93202834, “z”: 2433096.8101673303 }, { “x”: -2401555.4938714677, “y”: 5380567.300366957, “z”: 2433668.429810298 }])
});
const polygonInstance3 = new Cesium.GeometryInstance({
geometry: polygonGeometry3,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED.withAlpha(0.7))
},
});
instances.push(polygonInstance3);
const polygonGeometry4 = new Cesium.PolygonGeometry({
polygonHierarchy: new Cesium.PolygonHierarchy([{ “x”: -2401456.932098427, “y”: 5380844.045173162, “z”: 2433157.2129374146 }, { “x”: -2401007.840056206, “y”: 5381366.335047787, “z”: 2432449.993122666 }, { “x”: -2401934.5380039974, “y”: 5381010.967925442, “z”: 2432322.116788277 }, { “x”: -2402493.0858713463, “y”: 5380702.537193162, “z”: 2432451.9243560797 }, { “x”: -2401735.4288811344, “y”: 5380742.196945204, “z”: 2433107.8922376856 }])
});
const polygonInstance4 = new Cesium.GeometryInstance({
geometry: polygonGeometry4,
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.GREEN)
},
});
instances.push(polygonInstance4);
viewer.scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstances: instances,
appearance: new Cesium.PerInstanceColorAppearance()
}));
viewer.camera.flyTo({
destination:{x: -2403509.8429785646, y: 5385086.594574532, z: 2430897.2611216223},
orientation : {
heading:6.271242180095195,
pitch:-0.7264978610534887,
roll:0.00003630429651302336
}
});
Overlaps between polygons render incorrectly.
First camera perspective screenshot of incorrect overlaps between polygons:
Secondly camera perspective screenshot of incorrect overlaps between polygons:
Screenshot of correct overlaps between polygons: