Using latest version of Cesium 1.119
With no options for viewer object.
In below code, I’m drawing around 2000 entities. Just polygon boxes.
And trying to add Click event on it just to highlight it.
But when i do that, it just selects random entities. But it does happen in pattern, e.g. like same 4- entities will be selected if I continue clicking at one point.
viewer = new Cesium.Viewer('cesiumContainer');
.
.
.
.
$.each(AllBuildingDetails, function (index, EachBuilding) {
if(typeof EachBuilding != "undefined")
{
ent = viewer.entities.add({
id: "bldg-"+EachBuilding.id,
polygon : {
hierarchy : new Cesium.PolygonHierarchy(Cesium.Cartesian3.fromDegreesArray(eval("["+EachBuilding.LatLonCoordinatesString+"]"))),
material : Cesium.Color.fromCssColorString("#ff0000").withAlpha(0.5),
classificationType : Cesium.ClassificationType.BOTH
}
});
}
});
var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(click) {
var pickedObject = viewer.scene.pick(click.position);
console.log("pickedObject");
console.log(pickedObject);
console.log(pickedObject.id._id);
if(lastSelectedId != null)
viewer.entities.getById(lastSelectedId).polygon.material = Cesium.Color.RED.withAlpha(0.5);
viewer.entities.getById(pickedObject.id._id).polygon.material = Cesium.Color.RED.withAlpha(1);
lastSelectedId = pickedObject.id._id;
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
Here is what is happening