Restrict geographical area in which features on a layer can be accessed

570
4
Jump to solution
12-08-2021 07:17 AM
jbarrmetro
New Contributor II

I need to be able to restrict what features on a layer a user can see based on their geographical location.

Here's the scenario: this is for contractor management for my company. A contractor needs to be restricted to a geographical area, most often a state (but sometimes it will be a polygon drawn from another layer) and only see features from the map's feature layers within that geographical area. So if they're restricted to Ohio, they need to not be able to see features in Indiana, Kentucky, etc. 

Is there any way to set a layer to only display features within a certain geometry? 

0 Kudos
1 Solution

Accepted Solutions
Noah-Sager
Esri Regular Contributor

Hi @jbarrmetro, for this, you should be able to use a query with the FeatureLayer against the geometry of interest.

If it's a hosted FeatureLayer, you can use the queryExtent() method on the FeatureLayer:

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

If it's not, you can use the executeQueryJSON() method:

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html#executeQueryJSON

 

View solution in original post

0 Kudos
4 Replies
Noah-Sager
Esri Regular Contributor

Hi @jbarrmetro, for this, you should be able to use a query with the FeatureLayer against the geometry of interest.

If it's a hosted FeatureLayer, you can use the queryExtent() method on the FeatureLayer:

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

If it's not, you can use the executeQueryJSON() method:

https://developers.arcgis.com/javascript/latest/api-reference/esri-rest-query.html#executeQueryJSON

 

0 Kudos
jbarrmetro
New Contributor II

@Noah-Sager let me see if I'm understanding a possible path forward here based on your reply:

  1. Create a feature layer from the feature service URL (we have our own hosted server)
  2. Create a geometry for the query based on relevant information about the user (i.e. the area they have permission to view)
  3. Query against the feature layer using the queryExtent method and the constructed geometry (use "intersects" for the spatial relationship, probably?)
  4. Use the results of that query to construct a new (client-side?) feature layer
  5. Attach that layer to the map

Does that make sense? Sound feasible?

Noah-Sager
Esri Regular Contributor

Bingo, that makes sense to me and sounds feasible.

0 Kudos
jbarrmetro
New Contributor II

@Noah-Sager ok, thanks! Any suggestions on what to do if I run out of room on the 2000 feature limit for a query (as seems entirely possible when querying a whole state)? How do I re-query in a way that doesn't just get duplicate results from the first query?

0 Kudos