FeatureLayer Update and FullExtent

1665
4
06-04-2010 02:37 PM
CurtThue
New Contributor III
I would like to do something similar to this

myFeatureLayer.Where = "a=b"
myFeatureLayer.Update()
myMap.ZoomTo(myFeatureLayer.FullExtent)

However, after calling the Update method, the FullExtent is null.

Thanks for any help/ideas.
0 Kudos
4 Replies
dotMorten_esri
Esri Notable Contributor
Update is a asyncronous method. In other words you have to give the server a chance to send a response back.
Instead wait for the myFeatureLayer.UpdateCompleted event to fire before you do the zoom.
0 Kudos
CurtThue
New Contributor III
Update is a asyncronous method. In other words you have to give the server a chance to send a response back. 
Instead wait for the myFeatureLayer.UpdateCompleted event to fire before you do the zoom.


Morten

I added a handler for UpdateCompleted. It works as expected the first time, however the event also fires when the map is panned, zoomed, etc. The API docs define the event as "fires after an explicit call to Update() or after the layer has initialized and features was returned from the feature layer service." I am not sure why it fires when the extent is changed.

My code:

private void QueryButton_Click2(object sender, RoutedEventArgs e)
{
string searchCriteria = string.Empty;
FeatureLayer projFeatureLayer = MyMap.Layers["ProjectPoints1"] as FeatureLayer;

projFeatureLayer.UpdateCompleted += new System.EventHandler(projFeatureLayer_UpdateCompleted);
projFeatureLayer.UpdateFailed += new System.EventHandler<ESRI.ArcGIS.Client.Tasks.TaskFailedEventArgs>(projFeatureLayer_UpdateFailed);

searchCriteria = QueryTextBox.Text;

projFeatureLayer.Where = searchCriteria;
projFeatureLayer.Update();
}


void projFeatureLayer_UpdateCompleted(object sender, System.EventArgs e)
{

FeatureLayer projFeatureLayer = (FeatureLayer)sender;

if (projFeatureLayer.FullExtent != null)
{

double projectXMin = projFeatureLayer.FullExtent.XMin;
double projectXMax = projFeatureLayer.FullExtent.XMax;
double projectYMin = projFeatureLayer.FullExtent.YMin;
double projectYMax = projFeatureLayer.FullExtent.YMax;
double coordOffset = .01;

//Envelope cannot be a single point?
if (projectXMin == projectXMax && projectYMin == projectYMax)
{
projectXMax = projectXMax + coordOffset;
projectXMin = projectXMin - coordOffset;
}

Envelope projectEnvelope = new Envelope(projectXMin, projectYMin, projectXMax, projectYMax);
MyMap.ZoomTo(projectEnvelope);
}
}




Any help is appreciated!
0 Kudos
dotMorten_esri
Esri Notable Contributor
I'm guessing you have OnDemand mode enabled?
The doc should mention that this also triggers an update.
0 Kudos
CurtThue
New Contributor III
I'm guessing you have OnDemand mode enabled?
The doc should mention that this also triggers an update.


Thanks, it now works as expected. I assumed that specifying a WHERE value on the FeatureLayer would take it out of OnDemand (my interpretation of the API docs).
0 Kudos