Automatically zoom out when no filtered features available in current extent

2528
7
10-06-2015 08:14 AM
TracySchloss
Frequent Contributor

I have a featureLayer with a couple of dropdowns that define a filterExpression on the layer.  These are types of medical providers and for some specialty areas there aren't many specialists across the whole state.

I have a grid tied to the map, which lists out the features in the current map extent. Once a user has zoomed in, if they then change their filter to a specialty that isn't very common, there are no features displayed on the map, and the provider grid has a message that suggests they zoom out or change their filter to see some results.

I'd like to help the user out more than this, by having the map automatically zoom out until there is at least one filtered features shown. I can't figure out how to do this without iteratively zooming out, checking if there are features yet, zooming out again, etc.

Is there a less clunky process?  If that's the own solution, does anyone have a code snippet to share?

0 Kudos
7 Replies
thejuskambi
Occasional Contributor III

Dont have a code snippet, logically you could calculate the zoom extent required. below are the steps, let me know if it makes sense.

  1. query all the points/features with the required speciality
  2. Find the nearest Feature to the center of current extent
  3. get the delta x & delta y between center of current extent and the feature/point
  4. Calculate the extent width and height where it is 2x delta values + some buffer distance.
KenBuja
MVP Esteemed Contributor

Instead of actually zooming out, you could get the present extent of the map and use the expand method to get a geometry that you could use in a query of the FeatureLayer. if that doesn't result in any features selected, then expand it again until you do. Then you set the map extent to that geometry.

You'd have to put a limit on when to break that iteration in case there aren't any features in the entire dataset.

0 Kudos
SteveCole
Frequent Contributor

How about some sort of closest facility GP task based on your current (empty) map extent? Once you get the next closest feature, pan the map to it's map extent.

0 Kudos
TracySchloss
Frequent Contributor

It is true there are some menu choices for new categories.  It's possible the user could zoom out many times, eventually getting the whole state and never have any providers in that category.   That's not a very user friendly experience.  I find it frustrating and I wrote it!

I'm hesitant to use the GP tools, since this data set has 49K records in it.  Some of my filtered features still have thousands of potential returns.  I guess I should try it and see what kind of performance I get. 

TracySchloss
Frequent Contributor

UPDATE:  FindClosestFacilityTask isn't a practical solution for this application.  Although it doesn't specifically say so, it requires an AGOL login and consumes credits.  I don't have a GP task available in my local environment.

0 Kudos
SteveCole
Frequent Contributor

Bummer. You could always use some trigonometry and calculate the distance between two lat/long points to determine the closest facility to the current map extent but, like you said, 48k features is too many for this approach.

0 Kudos
TracySchloss
Frequent Contributor

I had a similar project with just a couple hundred points and for that, it worked to calculate point to point distances and then sort my list of facilities from closest to farthest.  The performance wasn't bad for that number of features.  If I get some code worked out that has some sort of loop to zoom out and keep checking until there are features in the extent, I'll post it here. 

0 Kudos