Setting 3D scene to zoom to the extent of feature layer query results

1341
8
Jump to solution
10-22-2020 05:19 AM
MichaelLev
Occasional Contributor III

Dear Robert Scheitlin, GISP‌,

I'm developing Query/Filter custom widget forWAB (Develper Edtion) 2.17, Launchpad Theme, on 3D Scenes (ArcGIS API for javascript 4.16).

How to set the 3D scene to zoom to the extent of the features array returned from a query on a feature layer? It could be array of points, lines or polygons. And how do I "play" with the zoom level?

I have not succeeded to find clear documentation/code example about how to do it.

1 Solution
8 Replies
MichaelLev
Occasional Contributor III

Dear Robert, thank you! You really saved my day!

I'll appreciate it if you please tell me why in my next code, though I try to search by extent, points that were outside of map extent are indeed not included in the results array, but are NOT hidden from the scene? I want to show on screen only points that were in the scene extent when I ran the query...

I'm attaching screenshot of my code.

my code

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Michael,

   Because you are setting the layer definition query to the where clause (which is correct but does not take into account the geometry extent). If you want the layers defintion query to take both the where clause and geometry into account then you have to  do something completely different. a layers definition query can not use geometries so you will have do get the Object IDs of all the query results and use that for the layers definition query (i.e. "ObjectId IN(" + oidArray.join(',') + ")". So you eith have to do another query for ids.

https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryObj... 

or

you need to loop through the results and make an array of ObjectIds from the results.

MichaelLev
Occasional Contributor III

Dear Robert, I appreciate your expertize and thank you very much for your most valueable help!

I want to validate that I my understanding is correct:

In order to hide on scene all features that do not appear in the results due to geometry,

I have no other way but to use layer definition expression,

and since layer definitionexpression does not respond to geometry conditions,

I have to bypass this drawback by giving the defintion expression a query which uses ObjectIds.

Am I correct?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Correct.

MichaelLev
Occasional Contributor III

Dear Robert - Excellent! It works! Thank you!

but in the queried feature layer table, the field name of the ObjectID is not "objectid" but, in my case - "fid".

  1. Is it safe to always refer to the name of ObjectID field as "fid"?
  2. Is it possible to do a simple query in order to get the name of the ObjectID field?
  3. If I query for distinct values of all field names, is ObjectId always the first field? - Should I use this way to know the name of the ObjectId field?

I checked and the 3rd option works well for me. Am I doing it right or is there a simpler way?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus
  1. No, not at all. You can get the layer object id field using the layers objectIdField property https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#objectId... 
  2. Answered in Question 1
  3. Answered in Question 1

All stuff you can find in the documentation.

MichaelLev
Occasional Contributor III

Dear Robert, you're awesome! Thank you!

0 Kudos