SceneLayer and ScenLayerView query support

1550
11
10-20-2017 09:44 AM
Yunpiao_WhitneyBai
New Contributor II

Hello,

I published a sceneLayer to AGOL through a scene layer package. I'm trying to query the scene layer view / this scene layer using  queryFeature() method. But I found that none of the attributes  support query when I use getFieldUsageInfo(field) to check the field.

Since the this scene layer contains a large dataset, I really want to query the layerView instead of the whole layer using queryTask or linked Featurelayer. Does anyone know how can I fix this issue to make the field support query? 

thanks,

0 Kudos
11 Replies
ThomasSolow
Occasional Contributor III

You could use various methods to force the scene layer to fetch the fields you're interested in.  One way to do this is to modify the visualVariables of your simple renderer (assuming you're using a simple renderer) by adding "dummy variables," like this:

{
  type: "opacity",
  field: 'NAME',
  legendOptions: {
    showLegend: false
  }
}

This will force the scene layer into fetching the attribute NAME.  Then, when you perform sceneLayerView.queryFeatures() the returned graphics will have the NAME attribute.

You could also overwrite the collectRequiredFields method on your render like this:

renderer.collectRequiredFields = function(fields){
  sceneLayer.fields.forEach(fieldInfo => fields[fieldInfo.name] = true)
}

That should force the scene layer to fetch all fields, but it might break something else.  When I try it on a sample layer it looks like one of the fields is not able to be fetched, so a lot of errors get thrown.

Keep in mind that the attributes on the scene layer can't be changed.  My understanding is that this is what the companion feature layer is for.

Yunpiao_WhitneyBai
New Contributor II

Hi Thomas,

Thanks for the response. 

I tried to add additional visualVariables to my sceneLayer before the query, and It worked, I can see that my layer.renderer.requiredFields has those additional fields that I added in visualVariables, but still I'm catching errors with queryFeatures().

If I use the sceneLayer.queryFeatures(), it gives me this: 

If I use its sceneLayerView.queryFeatures(), I got an different error: 

Thank you

 

0 Kudos
ThomasSolow
Occasional Contributor III

Try setting the where property of your Query object to null.  Setting outFields to null is also probably a good idea.

0 Kudos
RalucaNicola1
Esri Contributor

First of all some theory about how this works: 

1. Publishing a scene layer from an slpk will create a scene layer without an associated feature layer. Therefore, you can't query the scene layer (queries on scene layer are redirected to the associated feature layer which doesn't exist in your case). The only option in this case is to query the scene layer view.

2. Scene layer view queries on the other hand have a more limited functionality. First of all you can only query the features that are currently loaded (so not the whole layer). Second of all the number of properties that can be used for a query is limited: you can't use where for example (therefore the error). For queryFeatures only outFields and objectIds properties can be used. You don't need to send dummy variables on the renderer‌, you can set them in the outFields and that will return them in the query on the layer view (FYI @Thomas_Solow).

Second: what is your use case? We might help you better by knowing what the goal is.

And a few more tips:

If you need to query features based on attributes then one options is to publish the scene layer from a feature layer in AGO (see here a blog post on how to do this or official documentation if you prefer) and then use the query on the scene layer which supports where and which in this case will work because you'll have an associated feature layer.

Another options is to publish a feature layer with the attributes and the same objectIds as the features have in the scene layer and manually link the two like in this sample: Query a SceneLayer's linked FeatureLayer | ArcGIS API for JavaScript 4.5.

0 Kudos
ThomasSolow
Occasional Contributor III

Raluca Nicola wrote:

You don't need to send dummy variables on the renderer, you can set them in the outFields and that will return them in the query on the layer view (FYI @Thomas_Solow).

 

That's a good point.  For most users this does seem like the right approach.

But if you set outFields on the Query, the layer will send one request to the scene service for each attribute in outFields, and this question did specify wanting to avoid querying the service.

SceneLayerView.queryFeatures seems to stick to what's in the client already as long as you don't specify outFields.  The goal of forcing the scene layer to fetch attributes with dummy variables (or however you do it) is to keep subsequent queries for specific features in the client while still including all the attributes the user is interested in.

Eliminating those later requests in exchange for requesting the attributes up-front may be of questionable value, but there are probably some situations where it's a good idea.  Imagine you know in advance that you want access to a certain field on every feature that gets rendered, say for a feature table, or in order to mark each feature in a custom way.

0 Kudos
Yunpiao_WhitneyBai
New Contributor II

I tried to remove the where clause and use a filter after it is resolved. And it works now. I actually tried hack into renderer.requiredFields instead of adding dummy field. I guess it works in the same way. 

thank you 

0 Kudos
RalucaNicola1
Esri Contributor

Could you guys tell me why you prefer this over the public API? If I understood correctly you want to have only one request with all the data in the beginning rather than making several requests?

What is the end goal for you Yunpiao?

0 Kudos
Yunpiao_WhitneyBai
New Contributor II

Hi Raluca,

Thanks for your detailed explanation. Actually, I tried exactly same thing to publish scene layer from pro, but I found the field information is not included when I  tried to publish a scene layer using feature service in AGO.  Below is a sample back to July this year. The scene layer published from feature service only includes drawing information and no fields info at all. Therefore, I choose to use slpk instead. Do you have any idea why this happens? 

thanks,

0 Kudos
RalucaNicola1
Esri Contributor

hmm, that sounds like a bug. Did the buildings display? Do you still have the service? It would be useful if you could pass it along so we can investigate.

0 Kudos