How to detect a picked tileset among other tilesets?

1. A concise explanation of the problem you're experiencing.

I have multiple tilesets loaded but not able to detect which tileset has been picked or visible, the piked feature returns 'object' but I'm not able to get any further information about the parent tileset.

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.

var tileset1 = new Cesium.Cesium3DTileset({ url: 'myB3DMtileset1' });
    viewer.scene.primitives.add(tileset1);
var tileset2 = new Cesium.Cesium3DTileset({ url: 'myB3DMtileset2' });
    viewer.scene.primitives.add(tileset2);

var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
handler.setInputAction(function(click) {
    var pickedObject = viewer.scene.pick(click.position);
    
    if (Cesium.defined(pickedObject) {

      //how to detect which tileset is picked, tileset1 or tilset2?

    }
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

In case multiple tilesets are loaded, I want to get the custom properties or name of the tilset that is either picked by mouse or is visible to the camera.

4. The Cesium version you're using, your operating system and browser.

If you’re looking at the built-in console in Sandcastle you’ll only see “object” printed out when you do

console.log(pickedObject);

``

But if you check the browser console, you should see an object of type Cesium3DTileFeature which has some useful properties but also has a reference to the tileset it can from.

You can then identify which tileset it is by giving them custom names/ids. So you could create them as:

var tileset1 = new Cesium.Cesium3DTileset({ url: ‘myB3DMtileset1’ });
viewer.scene.primitives.add(tileset1);
tileset1.id = 1;

var tileset2 = new Cesium.Cesium3DTileset({ url: ‘myB3DMtileset2’ });
viewer.scene.primitives.add(tileset2);
tileset2.id = 2

``

So that in your pick, you can then do:

var pickedObject = viewer.scene.pick(click.position);
if (Cesium.defined(pickedObject)) {
console.log(pickedObject.tileset.id);
}

``

Let me know if that works.

Hi Omar, Many Thank’s, that worked well :slight_smile: