MapView.Active.ZoomTo() does not work for a created layer in ArcGIS Pro SDK

610
3
02-10-2021 01:11 PM
Amadeus111
Occasional Contributor II

I generate a geometry from a current view extent and create a layer via LayerFactory. Then, I select features in the that intersects  with the created the geometry. 

AGP zoom out all the way the layer extent and does not zoom back into the geometry extent. It happens only right after creating the layer. Afterwards, it works fine when layer does not need to be created again. 

OguzSariyildiz_0-1612991167923.png

Here is the code 

QueuedTask.Run(() =>
{
   Envelope currentExtent = MapView.Active.Extent;
   Geometry currentExtGeo = currentExtent.Clone();
   var sq = new SpatialQueryFilter() { FilterGeometry = currentExtGeo, 
               SpatialRelationship = SpatialRelationship.Intersects };
                            

   CalledFlayer = LayerFactory.Instance.CreateLayer(CalledUri, 
                  MapView.Active.Map, 0, CalledFLayerName) as FeatureLayer;
   CalledFlayer.ClearSelection();
   CalledFlayer.SetVisibility(true);

   CalledFlayer.Select(sq);
   MapView.Active.ZoomTo(currentExtGeo);//Supposed go back into original 
                                        //extent here but no
     
});
0 Kudos
3 Replies
Amadeus111
Occasional Contributor II

interestingly it works when I create another QueuedTask and move ZoomTo in it 

QueuedTask.Run(() =>{...});
QueuedTask.Run(() =>
{
   MapView.Active.ZoomTo(currentExtGeo);
});
0 Kudos
GintautasKmieliauskas
Regular Contributor

Hi,

I have had the same situation but not with zoom. Esri stuff recommended to divide process inside QueuedTask.Run. I have a mind what it is a cache problem. Now if something does not work I try to divide one QueuedTask.Run to few if it possible.

Amadeus111
Occasional Contributor II

Good to know!

0 Kudos