Zoom on feature layer problem

869
2
05-16-2014 06:37 AM
RyanSmith1
New Contributor III
Hi, i have the following code to zoom to an extent depending on the the query result. The zoom works certain times on firefox but
doesn't work on chrome.
What could be the problem?

Thanks


            featureLayer.selectFeatures(query, esri.layers.FeatureLayer.SELECTION_NEW, function (features) {
                    var extent = features[0].geometry.getExtent().expand(1.25);
                    map.setExtent(extent, true);
                }
0 Kudos
2 Replies
TracySchloss
Frequent Contributor
I occasionally have problems with both selecting and querying and I always think it relates to the callback function executing before the selection is really complete.  Network connectivity, the type and number of features you're selecting can impact whether the selection happens 'instantly' or not.  Points seem to be OK, but when I had a project where I was selecting lines with lots of vertices, there was often a problem.

When I have this happen, adding selection-complete listener to your featureLayer and then execute the selection without the callback function takes care of this problem.  The syntax changes up a bit.  Instead of getting to feature like "results[0]" you have to use "results.features[0]".

     myLayer.on('selection-complete', selectFeatureHandler);
myLayer.selectFeatures(query); 

function selectFeatureHandler (results) {
 var feature = results.features[0];
 map.setExtent(feature.geometry.getExtent().expand(1.25));
}
0 Kudos
RyanSmith1
New Contributor III
I occasionally have problems with both selecting and querying and I always think it relates to the callback function executing before the selection is really complete.  Network connectivity, the type and number of features you're selecting can impact whether the selection happens 'instantly' or not.  Points seem to be OK, but when I had a project where I was selecting lines with lots of vertices, there was often a problem.

When I have this happen, adding selection-complete listener to your featureLayer and then execute the selection without the callback function takes care of this problem.  The syntax changes up a bit.  Instead of getting to feature like "results[0]" you have to use "results.features[0]".

     myLayer.on('selection-complete', selectFeatureHandler);
myLayer.selectFeatures(query); 

function selectFeatureHandler (results) {
 var feature = results.features[0];
 map.setExtent(feature.geometry.getExtent().expand(1.25));
}



Hi Tracy, thanks for this.
It really has improved processing time of the zoom and seems to be working on firefox but still no luck on chrome.
Not sure why this is happening.
0 Kudos