How do we ignore the auto-zoom in CreateLayer

07-24-2022 01:36 PM
Occasional Contributor III

In updating my code to the Pro 3.0 SDK I see that there is now a new way to add a FeatureClass to the map. So I went through and refactored my code block to this:


//add the feature class to the map
var lyrParams = new FeatureLayerCreationParams(grdFeatClass) { MapMemberPosition = MapMemberPosition.AddToTop };
var featLayer = LayerFactory.Instance.CreateLayer<FeatureLayer>(lyrParams, mv.Map);


Works great but I also noticed that it ALWAYS zooms in to the layer. I have custom zooming logic that is basically NoZoom or ZoomWithPadding. I would like to just have the CreateLayer not do any zooming at all and let me apply it -OR- not apply it.

Anyway of doing this?


2 Replies
by Esri Regular Contributor
Esri Regular Contributor

I couldn't find an easy way to do this.  We did reach out to the Dev team to see if we overlooked something here, but in the meantime the following snippet resets the extent to the extent before adding the new feature layer:

QueuedTask.Run(() =>
  var map = MapView.Active.Map;
  var flyrCreateParam = new FeatureLayerCreationParams(new Uri(@"C:\Data\Admin\AdminData.gdb\USA\cities"))
    Name = "World Cities",
    IsVisible = true
  var cameraBefore = MapView.Active.Camera;
  var featureLayer = LayerFactory.Instance.CreateLayer<FeatureLayer>(
    flyrCreateParam, map);
  if (cameraBefore != null)

Needless to say, this is just a work-around, once we hear back from the Dev team, I will let you know if there's a better way to accomplish your workflow.

0 Kudos
Occasional Contributor III

@Wolf thanks! I looked through the API and Samples and couldn't find a way to ignore zoom. But thanks for the code snippet as it will work for now. I was thinking about the same thing...basically take a snapshot of the extent, CreateLayer, then zoom back to saved extent.

0 Kudos