Select to view content in your preferred language

Zoom to Feature extremely slow

1203
6
Jump to solution
11-28-2012 06:36 AM
RobertBorowski
Emerging Contributor
Hi All,
I am using the following code snippet straight from the javascript API examples and it appears to be working. However, it takes up to 10 seconds to complete the redraw (map.setExtent) by which time the user has given up and assumes it did not work. The feature layer I am using has about 60,000 polygons in it. Any ideas on how I can make this work and speed things up? Perhaps a different method than below?

      function zoomRow(id){
        statesLayer.clearSelection();
        var query = new esri.tasks.Query();
        query.objectIds = [id];
        statesLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features){
          //zoom to the selected feature
          var stateExtent = features[0].geometry.getExtent().expand(5.0);
          map.setExtent(stateExtent);
        });
      }
0 Kudos
1 Solution

Accepted Solutions
JeffPace
MVP Alum
Thanks for the insight Jeff. I do have scale dependencies set, but I should have mentioned that the map display is the whole point. The intention here is to do exactly what the ESRI States code sample does: Zoom in to a particular extent around the polygon (expand(5.0)) and highlight it on the map. Finding the extent of a queried polygon and then just resetting the map extent seemed to be the easiest way to do this. Maybe I am missing something here.


Understood.   My guess is that it is the selection process that is the most time consuming.

Can you try a querytask instead of a selection? Since you will be receiving one geometry back, you can get its extent and do your calculation.

View solution in original post

0 Kudos
6 Replies
JeffPace
MVP Alum
Hi All,
I am using the following code snippet straight from the javascript API examples and it appears to be working. However, it takes up to 10 seconds to complete the redraw (map.setExtent) by which time the user has given up and assumes it did not work. The feature layer I am using has about 60,000 polygons in it. Any ideas on how I can make this work and speed things up? Perhaps a different method than below?

      function zoomRow(id){
        statesLayer.clearSelection();
        var query = new esri.tasks.Query();
        query.objectIds = [id];
        statesLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW,function(features){
          //zoom to the selected feature
          var stateExtent = features[0].geometry.getExtent().expand(5.0);
          map.setExtent(stateExtent);
        });
      }


That exceeds the recommended limits for graphics.  Remember a Feature Layer is a graphic with added functionality, rendering that much each time is excessive. 

Can you either filter or generalize ?
0 Kudos
RobertBorowski
Emerging Contributor
The layer is parcel polygons. The user could be searching for any one of them, so they can't really be filtered to a smaller set. Just curious, what is the recommended limit? I see the ESRI example only is using the 50 states.
0 Kudos
JeffPace
MVP Alum
Our parcel layer is 200k+.  Anything other that a tiled service was unacceptable performance.

Just because you are querying a service does not mean you have to display it.  In fact, it doesnt even need to be added to the map.

First thing i would do would be put big scale dependencies on display.
0 Kudos
RobertBorowski
Emerging Contributor
Our parcel layer is 200k+.  Anything other that a tiled service was unacceptable performance.

Just because you are querying a service does not mean you have to display it.  In fact, it doesnt even need to be added to the map.

First thing i would do would be put big scale dependencies on display.


Thanks for the insight Jeff. I do have scale dependencies set, but I should have mentioned that the map display is the whole point. The intention here is to do exactly what the ESRI States code sample does: Zoom in to a particular extent around the polygon (expand(5.0)) and highlight it on the map. Finding the extent of a queried polygon and then just resetting the map extent seemed to be the easiest way to do this. Maybe I am missing something here.
0 Kudos
JeffPace
MVP Alum
Thanks for the insight Jeff. I do have scale dependencies set, but I should have mentioned that the map display is the whole point. The intention here is to do exactly what the ESRI States code sample does: Zoom in to a particular extent around the polygon (expand(5.0)) and highlight it on the map. Finding the extent of a queried polygon and then just resetting the map extent seemed to be the easiest way to do this. Maybe I am missing something here.


Understood.   My guess is that it is the selection process that is the most time consuming.

Can you try a querytask instead of a selection? Since you will be receiving one geometry back, you can get its extent and do your calculation.
0 Kudos
RobertBorowski
Emerging Contributor
Spot-on Jeff. I reconfigured it without the selectFeatures and just focused on the query... Then added the feature highlight as a graphic after the fact. Works great now!
0 Kudos