Hi Narelle,
Thank you for the response and explanation. I tried the code you provided and do see that the AutoZoomOnEmpty property works as expected when it's a single data source (i.e., feature class or table).
Unfortunately, since the workaround references the underlying feature class, bypassing all the capabilities that a layer file provides (e.g., symbology, definition queries, etc.), it creates/adds the layer as it would from a feature class/table with random symbology, the name of the feature class as seen in the GDB and definition queries removed (attachments), defeating the purpose of using a layer file.
Please consider lyrx files being supported with the AutoZoomOnEmpty property. Adding a lyrx file when there are already other layers in the Table of Contents besides the basemap works wonderfully. It's just the edge case when the created/added layer is the very first one where the behavior isn't awesome. The other properties one could possibly set on a layer file directly behave nicely - it's just AutoZoomOnEmpty of those that I've tried that does not. For instance,
Uri uri = new(layerPath);
LayerCreationParams lyrParams = new(uri)
{
IsVisible = false,
MapMemberIndex = tocIndex,
MapMemberPosition = MapMemberPosition.Index,
AutoZoomOnEmptyMap = false // won't work this way
};
LayerFactory.Instance.CreateLayer<Layer>(lyrParams, MapView.Active.Map);
Attachment Description:
- Example_of_various_lyrx_referencing_same_feature_class.png
A view of the table of contents where lyrx files were added as layer files. Those 3 refer to the 3 with the checkboxes being checked getting to be re-added.
Uri uri = new(layerPath);
LayerFactory.Instance.CreateLayer(uri, MapView.Active.Map, index: tocIndex);
2. Checked_layers_added_after_new_code.png
The AutoZoomOnEmpty property works when referencing the layer's underlying feature class. However, when they are added, adding them to the map bypasses the layer file completely so symbology, layer naming and definition queries are lost.
LayerDocument layerdoc = new(layerPath);
CIMLayerDocument cimLayerDoc = layerdoc.GetCIMLayerDocument();
CIMDefinition[] layerDefs = cimLayerDoc.LayerDefinitions;
CIMDefinition layerDef = layerDefs[0];
CIMDataConnection? dataConnection = (layerDef as CIMFeatureLayer)?.FeatureTable.DataConnection;
LayerCreationParams lyrParams = new(dataConnection)
{
MapMemberIndex = tocIndex,
MapMemberPosition = MapMemberPosition.Index,
AutoZoomOnEmptyMap = false
};
LayerFactory.Instance.CreateLayer<Layer>(lyrParams, MapView.Active.Map);