select multiple entities with or without keyboard

Hi,
I came across few example where you can select several building in the view with holding down the ctrl button on the keyboard.
one example The VirtualCityMAP ( https://berlin.virtualcitymap.de/ )

I have been trying to write a similar code to use for my data and be able to select several buildings, but just couldn't figure it out.

can someone help me out with this?

I have the code to change the color of the first selected building, but now have to add entities :

var scene = viewer.scene;
var handler = viewer.screenSpaceEventHandler;
handler.setInputAction(function(click) {
    var pickedObject = scene.pick(click.position);
    if (Cesium.defined(pickedObject) ) {
        highlightedEntity = pickedObject.id;
    console.log (pickedObject.id);
    
    } else{
        highlightedEntity = undefined;
    }
    
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

after the selection of several buildings, I'd like to run an sql query on the selected entities.

Thank you

In your click event handler function, you can add a modifier for holding down the control key. Instead of tracking one highlighted entity, you can add to a list of entities like so:

var scene = viewer.scene;
var handler = viewer.screenSpaceEventHandler;
handler.setInputAction(function(click) {
var pickedObject = scene.pick(click.position);
if (Cesium.defined(pickedObject) ) {
highlightedEntities.push(pickedObject.id);
console.log (pickedObject.id);
}

}, Cesium.ScreenSpaceEventType.LEFT_CLICK, Cesium.KeyboardEventModifier.CTRL);

You’d want to change the color of each highlighted entity as they are added to the list.

Hope that helps!

Thanks,

Gabby