Select to view content in your preferred language

Query error: "SceneLayer queries are not available without an associated feature layer"

228
2
Jump to solution
09-23-2024 03:26 PM
janzagar_0
Emerging Contributor

I am making a web application that has a 3D web scene containing two layers. I want to get one of the layers and have users be able to run queries on the table and then the scene show all matching layers, similar to the "Select by Attribute" tool in ArcGIS Pro. I am a beginner to building web apps and I've run into some issues getting the query to work. I am using the following code:

webscene.loadAll().then(()=>{
                    const sceneLayer = webscene.layers.getItemAt(0);
                    sceneLayer.outFields = ["*"];
                    console.log(sceneLayer);

                    let query = sceneLayer.createQuery();
                    query.where = "Category = 'Topographic'";
                    query.outFields = ["Description", "ID", "Link", "Category"];
                    query.returnGeometry = true;

                    sceneLayer.queryFeatures(query).then((result) => {
                        console.log(result.features);
                    });
 

The first console.log() returns an Object that shows that shows the correct information for the layer I want to query. However, the second portion (the query) returns this error:

"SceneLayer queries are not available without an associated feature layer"

I uploaded the webscene to ArcGIS Online and all the component layers should be associated to the web scene, so I am confused as to why I am still getting this error.

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
SaschaBrunnerCH
Esri Contributor

This is the expected  behavior if the SceneLayer do not have an associated FeatureLayer. See Where do attributes come from?  for more details.
Query works only on the SceneLayerView for SceneLayers without an associated FeatureLayer. To keep in mind: The SceneLayerView query methods only execute queries against features that are visible in the view at the moment of the query.
Adopted code:

 

webscene.when(() => {
    const sceneLayer = webscene.layers.getItemAt(0);
    sceneLayer.outFields = ["*"];
    view.whenLayerView(sceneLayer).then((sceneLayerView) => {
        let query = sceneLayerView.createQuery();
        query.where = "Category = 'Topographic'";
        query.outFields = ["Description", "ID", "Link", "Category"];

        sceneLayerView.queryFeatures(query).then((result) => {
            console.log(result.features);
        });
    })
})

 


see also in the sample: Query client-side 3D extents 


View solution in original post

2 Replies
SaschaBrunnerCH
Esri Contributor

This is the expected  behavior if the SceneLayer do not have an associated FeatureLayer. See Where do attributes come from?  for more details.
Query works only on the SceneLayerView for SceneLayers without an associated FeatureLayer. To keep in mind: The SceneLayerView query methods only execute queries against features that are visible in the view at the moment of the query.
Adopted code:

 

webscene.when(() => {
    const sceneLayer = webscene.layers.getItemAt(0);
    sceneLayer.outFields = ["*"];
    view.whenLayerView(sceneLayer).then((sceneLayerView) => {
        let query = sceneLayerView.createQuery();
        query.where = "Category = 'Topographic'";
        query.outFields = ["Description", "ID", "Link", "Category"];

        sceneLayerView.queryFeatures(query).then((result) => {
            console.log(result.features);
        });
    })
})

 


see also in the sample: Query client-side 3D extents 


janzagar_0
Emerging Contributor

Sascha,

Thank you very much for your response. I tried your code and I finally do get an array as output in the console, but the array is empty. The "where" clause and the "outFields" are correct and should return a result. Regardless, I may require my queries to return geometry, which as I read is not possible with SceneLayerView queries. Is there a way to associate a feature layer with a scenelayer in AGOL?

0 Kudos