I’m adding some buildings from a GeoJSON and looking to clamp these to the ground either while adding, or after adding to the scene.
I’m currenlty doing this:
async function loadEntitiesFromGeoJSON(dataSource) {
return new Promise((resolve, reject) => {
try {
viewer.dataSources.add(dataSource)
let entities = dataSource.entities.values;
let colorHash = {};
for (let i = 0; i < entities.length; i++) {
let entity = entities[i];
let id = entity.id;
let normalisedId = id.substr(0, id.lastIndexOf('_'));
if (normalisedId.includes('TheParade') || normalisedId.includes('QueensSouth') || normalisedId.includes('QueensNorth')){
dataSource.entities.removeById(entity.id)
continue;
}
let color = colorHash[normalisedId];
if (!color) {
color = Color.fromRandom({
minimumRed: 0.6,
maximumRed: 0.7,
minimumBlue: 0.8,
maximumBlue: 0.9,
minimumGreen: 0.75,
maximumGreen: 0.8,
alpha: 1,
});
colorHash[normalisedId] = color;
}
entity.polygon.material = color;
entity.polygon.outline = false;
entity.polygon.outlineColor = Color.BLACK;
if (!entity.properties.hasOwnProperty('levels')) {
entity.properties.levels = 1;
}
entity.polygon.extrudedHeight = entity.properties.levels * 4
}
resolve(true);
} catch (err) {
console.log(err);
changeSplashLoadingData(err);
reject(false);
}
})
}
After using the createWorldTerrain()
function however, all of these are below the world terrain line (because there’s no height data so they’re added at 0m). How can I clamp these entities to ground?