How tileset property using?

I am using a tileset from Cesium ion, and I want to create pins only on “building” with the “hospital” attribute. When using ‘tileLoad’ and ‘tileVisible’ to generate pins, I cannot create them because the tiles do not load when viewed from a distance. When I zoom in, load the tiles, and then zoom out, I can see the created pins. TileVisible seems like a plausible solution, but it also does not create pins when viewed from far away. Additionally, due to the large amount of data continuously loading, the screen may freeze and crash. Therefore, I am attempting to directly use the values I presume are in the viewer properties when the tileset is first loaded. However, I am unsure of the correct path and how to use it properly.

I accessed the tileset via this._viewer.scene.primitives.get(0). I would like to know how to obtain the property values from this point.

What kind of application is it? Are you meaning you’re creating pins automatically when you load a tileset? One per tile, or something else? Do you have any database or place to save your data, or is it a simple app that lives in isolation, like a live viewer where things come and go?

Cheers,

Alex

To answer your question briefly, it is closer to automatically creating pins when the tileset is loaded. Also, there is no separate database space, and it is a simple app that operates independently.

So you’re creating one pin per tile loaded, or do you do further analysis to make a pin? Ie, how do you define and store the pins? The best way would be to have a global storage area for these pins, so that you can create them by zooming around, and then it’s cached / stored for the next user that comes along. But barring that …

The properties are lazily loaded, so it’s tricky to avoid this kind of issue. If you want to be brave you could quickly zoom to the bounding circle to trigger the loading of tiles, and quickly zoom back again to where you were, possibly freezing the canvas while you’re doing it. The other way is to hook into one of the events (hmm, was it allTilesLoaded?) which (at least in older versions) triggered all tiles to load, but yeah, heavy on the resources, of course.

Cheers,

Alex

Currently, the code is using tileset.tileVisible.addEventListener to obtain the length of tile.content , and using a for loop to assign values to the following variables:

const feature = content.getFeature(i);
const building = feature.getProperty(‘building’);
const long = feature.getProperty(‘cesium#longitude’);
const lat = feature.getProperty(‘cesium#latitude’);

Then, entities.add is used to create pins with the long and lat variable values as the positions.

However, when creating pins with this code, it does not work (or creates very few pins) when starting from the globe view. The user wants to read all the information from the tileset and create pins at the respective positions, regardless of the zoom level. This is why they responded to your question that they want to create pins when loading the tileset.

Try playing around with something like this;

myTileset.allTilesLoaded.addEventListener(function() {
   // create pins here
});

Cheers,

Alex

Thank you.
I am using the following code to get tileset information:

this.tileset.allTilesLoaded.addEventListener(() => {
    console.log('tileset load success.');
    const primitives = this._viewer.scene.primitives;
    for (let i = 0; i < primitives.length; i++) {
        const primitive = primitives.get(i);
        if (primitive instanceof Cesium.Cesium3DTileset) {
            const content = primitive.root.content;
            const batchTable = content.batchTable;

            // total feature length
            const featuresLength = content.featuresLength;
            console.log(`total feature length: ${featuresLength}`);
            for (let i=0; i<featuresLength; i++) {

                // features properties
                const featureProperties = batchTable.getFeature(i);
                console.log(`features properties:`, featureProperties);

                // features building property
                const featureBuilding = batchTable.getProperty(i, 'building');
                console.log(`features building property: ${featureBuilding}`);
            }
        }
    }
});

However, I don’t know where all the tileset information is located. This way, it keeps getting only the properties of the first tile. I wonder if there is a wrong part, and if this method cannot be used.

Hiya,

There’s other events for that, most useful is;

tileset.tileLoad.addEventListener(function(tile) {
    console.log('A tile was loaded.', tile );
});

In the returning Tile are the properties and such that you’re after. I also seem to remember I wrote a function to traverse the tileset (returns an array of all bounding spheres) which might trigger the loading of them all. Here’s a modified version:

 function traverseTiles ( tile = null, ret = [], depth = 0 ) {

    if ( !tile ) {
        return ret;
    }

   if ( tile._boundingVolume && tile._boundingVolume._boundingSphere ) {
        var bound = tile._boundingVolume._boundingSphere;
        ret.push({
           level: depth,
           sphere: bound,
           pos: bound.center,
           rad: bound.radius
        });
    }
    
    if ( tile.children ) {
      tile.children.forEach( nextTile => {
          ret = traverseTiles ( nextTile, ret, depth + 1 );
      });
    }

    return ret;
  }

Just call it at the start with;

var bounds = traverseTiles ( mytileset._root );
console.log('## mytileset bounds', bounds );

There should be something useful in there somewhere. :slight_smile:

Cheers,

Alex