Select to view content in your preferred language

Add two layers to MapView control from same feature class

263
2
Jump to solution
05-27-2024 02:57 PM
SusanPaplanus
New Contributor II

I need to display upto 3 separate views of feature class that is located inside of a mobile geodatabase on a MapView.   The feature class/dataset needs to be displayed on three separate layers, which each layer will be using a different field that is symbolized (in this case to show fire, vegetation, and drought conditions).   I can add the first layer using:

featureLayer = new Esri.ArcGISRuntime.Mapping.FeatureLayer(Workspace.GetGeodatabaseFeatureTable(ActualFeatureClassName)

I create a classbreaks renderer, and then add the layer to the map :

Dispatcher.Invoke(() => MainMapView.Map.OperationalLayers.Add(myLayer));

and it adds ok. 

When I try to create a new second layer using the same command, I get an error, "Object is already owned: Already Owned".  

So the user may create one, two, or three layers (but it could be more in the future).  Is there any way to handle the case where we need to have more than one layer to be displayed off of the same feature dataset/feature class.

Susan

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You need to create new layer from scratch. I have modified ArcGIS Maps SDK sample to work without Already Owner fail. Code below:

            #region FeatureLayer

            // Get the full path for the mobile geodatabase.
            string geodatabasePath = DataManager.GetDataFolder("e12b54ea799f4606a2712157cf9f6e41", "ContingentValuesBirdNests.geodatabase");

            // Load the geodatabase.
            Geodatabase geodatabase = await Geodatabase.OpenAsync(geodatabasePath);

            // Load the Geodatabase, GeodatabaseFeatureTable and the ContingentValuesDefinition.
            // Get the 'BirdNests' geodatabase feature table from the mobile geodatabase.
            _geodatabaseFeatureTable = geodatabase.GetGeodatabaseFeatureTable("BirdNests");

            // Asynchronously load the 'BirdNests' geodatabase feature table.
            await _geodatabaseFeatureTable.LoadAsync();

            // Asynchronously load the contingent values definition.
            await _geodatabaseFeatureTable.ContingentValuesDefinition.LoadAsync();

            // Create a FeatureLayer based on the GeoDatabaseFeatureTable.
            FeatureLayer nestLayer = new FeatureLayer(_geodatabaseFeatureTable);

            // Add the FeatureLayer to the OperationalLayers.
            MyMapView.Map.OperationalLayers.Add(nestLayer);

            try
            {
                Geodatabase geodatabase1 = await Geodatabase.OpenAsync(geodatabasePath);
                var table = geodatabase1.GetGeodatabaseFeatureTable("BirdNests");

                // Create a FeatureLayer based on the GeoDatabaseFeatureTable.
                FeatureLayer nestLayer1 = new FeatureLayer(table);

                // Add the FeatureLayer to the OperationalLayers.
                MyMapView.Map.OperationalLayers.Add(nestLayer1);
            }
            catch (Exception ex)
            {

                throw;
            }

            #endregion FeatureLayer

View solution in original post

2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You need to create new layer from scratch. I have modified ArcGIS Maps SDK sample to work without Already Owner fail. Code below:

            #region FeatureLayer

            // Get the full path for the mobile geodatabase.
            string geodatabasePath = DataManager.GetDataFolder("e12b54ea799f4606a2712157cf9f6e41", "ContingentValuesBirdNests.geodatabase");

            // Load the geodatabase.
            Geodatabase geodatabase = await Geodatabase.OpenAsync(geodatabasePath);

            // Load the Geodatabase, GeodatabaseFeatureTable and the ContingentValuesDefinition.
            // Get the 'BirdNests' geodatabase feature table from the mobile geodatabase.
            _geodatabaseFeatureTable = geodatabase.GetGeodatabaseFeatureTable("BirdNests");

            // Asynchronously load the 'BirdNests' geodatabase feature table.
            await _geodatabaseFeatureTable.LoadAsync();

            // Asynchronously load the contingent values definition.
            await _geodatabaseFeatureTable.ContingentValuesDefinition.LoadAsync();

            // Create a FeatureLayer based on the GeoDatabaseFeatureTable.
            FeatureLayer nestLayer = new FeatureLayer(_geodatabaseFeatureTable);

            // Add the FeatureLayer to the OperationalLayers.
            MyMapView.Map.OperationalLayers.Add(nestLayer);

            try
            {
                Geodatabase geodatabase1 = await Geodatabase.OpenAsync(geodatabasePath);
                var table = geodatabase1.GetGeodatabaseFeatureTable("BirdNests");

                // Create a FeatureLayer based on the GeoDatabaseFeatureTable.
                FeatureLayer nestLayer1 = new FeatureLayer(table);

                // Add the FeatureLayer to the OperationalLayers.
                MyMapView.Map.OperationalLayers.Add(nestLayer1);
            }
            catch (Exception ex)
            {

                throw;
            }

            #endregion FeatureLayer
SusanPaplanus
New Contributor II

Thank you very much for your assistance.  I was able to modify this example to get exactly what I wanted.   I really appreciate your help.


Susan

0 Kudos