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

1033
4
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
4 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
GKmieliauskas
Esri 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
LesleyBross1
New Contributor III

I had a similar problem with the setCamera and isVisible methods when I was changing these properties on a large number of layers. The map frame display did not reliably update. Breaking out the calls into separate QueuedTask.Run blocks seemed to fix the issue, although it seems less efficient.

0 Kudos