Hello everyone,
I import a BuildingSceneLayer in a webscene and and when I click on a component of the 3d model a popup appears with information about that component. I want to access some of these information and use it. I thought it should be straightforward but I cannot seem to extract these information.
I tried with an 'on-click ' event and 'hitTest':
but only the first of the entries displayed in the popup in found in 'attributes' (see attached screenshots).
Thank you in advance for the time and help.
Solved! Go to Solution.
Thanks for reaching out! I think I found what is missing in your code.
Firstly, in order to read the attributes after a hitTest, you need to make them accessible first by configuring the property outFields on the BuildingSceneLayer (see this link, under "Querying"). If you want to make all attributes accessible, use "*". But this is not advised, since it slows down the whole process, so it is better to list only the attributes which are needed.
Secondly, you actually don't need to make a query. After adding the necessary attributes in the outFields property, you can access them directly from the result of the hitTest by reading response.results[0].graphic.attributes.
Here a code snippet:
buildingSceneLayer.outFields = ["*"]; // Make all of the attributes fields accessible
view.on("click", (event) => {
view.hitTest(event).then((response) => {
// check if a graphic is returned from the hitTest
if (response.results[0].graphic) {
// Read the attributes directly from the results from the hitTest
console.log(response.results[0].graphic.attributes);
}
});
});
I hope this helps, if you have further questions just ask 😉
Daniel
Thanks for reaching out! I think I found what is missing in your code.
Firstly, in order to read the attributes after a hitTest, you need to make them accessible first by configuring the property outFields on the BuildingSceneLayer (see this link, under "Querying"). If you want to make all attributes accessible, use "*". But this is not advised, since it slows down the whole process, so it is better to list only the attributes which are needed.
Secondly, you actually don't need to make a query. After adding the necessary attributes in the outFields property, you can access them directly from the result of the hitTest by reading response.results[0].graphic.attributes.
Here a code snippet:
buildingSceneLayer.outFields = ["*"]; // Make all of the attributes fields accessible
view.on("click", (event) => {
view.hitTest(event).then((response) => {
// check if a graphic is returned from the hitTest
if (response.results[0].graphic) {
// Read the attributes directly from the results from the hitTest
console.log(response.results[0].graphic.attributes);
}
});
});
I hope this helps, if you have further questions just ask 😉
Daniel
Thank you very much that is exactly what I was missing!
Best. Davide