select multiple entities with or without keyboard

150 views
Skip to first unread message

Project_2017

unread,
Aug 14, 2017, 6:59:03 AM8/14/17
to cesium-dev
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

Gabby Getz

unread,
Aug 22, 2017, 4:37:28 PM8/22/17
to cesium-dev, pink6...@gmail.com
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

Reply all
Reply to author
Forward
0 new messages