FeatureCollectionTable Unique Value Renderer

778
3
Jump to solution
03-21-2019 08:20 AM
ApurvaGoyal1
New Contributor

Hello,

In my mobile app, I am creating a new featureCollectionLayer by copying the selected features from a feature layer to a FeatureCollectionTable as follows-

 private async Task CreateNewFeatureCollection(FeatureQueryResult features, Renderer renderer)
        {
            // Create the schema for the table

            var fields = features.First().FeatureTable.Fields;

            // Instantiate FeatureCollectionTables with schema and geometry type
            FeatureCollectionTable featureCollectionTable = new FeatureCollectionTable(fields, features.GeometryType, SpatialReferences.WebMercator);

            // Set rendering for each table
            featureCollectionTable.Renderer = renderer;

            foreach (Feature feature in features)
            {
                //Debug.WriteLine(feature.GetAttributeValue("SURTYPE").ToString());
                Feature newFeature = featureCollectionTable.CreateFeature(feature.Attributes, feature.Geometry);
                await featureCollectionTable.AddFeatureAsync(newFeature);
            }


            FeatureCollection featuresCollection = new FeatureCollection();
            featuresCollection.Tables.Add(featureCollectionTable);

            // Create a FeatureCollectionLayer 
            FeatureCollectionLayer collectionLayer = new FeatureCollectionLayer(featuresCollection);

            // When the layer loads, zoom the map centered on the feature collection
            await collectionLayer.LoadAsync();

            // Add the layer to the Map's Operational Layers collection
            if(features.GeometryType == GeometryType.Point)
                Map.OperationalLayers.Add(collectionLayer);
            else
            {
                if (Map.OperationalLayers.Count > 1)
                    Map.OperationalLayers.Insert(1, collectionLayer);
                else
                    Map.OperationalLayers.Add(collectionLayer);
            }



        }

I use a unique value renderer for featureCollectionTable as follows-

     public Renderer GetTrailsQueryRenderer()
        {

            UniqueValueRenderer renderer = new UniqueValueRenderer();

            renderer.FieldNames.Add("SURTYPE");

            SimpleLineSymbol hardLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, System.Drawing.Color.FromArgb(255, 51, 204), 2);
            SimpleLineSymbol softLineSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Dash, System.Drawing.Color.FromArgb(255, 51, 204), 2);

            // Add values to the renderer: define the label, description, symbol, and attribute value for each
            renderer.UniqueValues.Add(
                new UniqueValue(" ", "Hard Surface", hardLineSymbol, "HardSurface"));
            renderer.UniqueValues.Add(
                new UniqueValue(" ", "Soft Surface", softLineSymbol, "SoftSurface"));


            // Set the default region fill symbol (transparent with no outline) for regions not explicitly defined in the renderer
            renderer.DefaultSymbol = hardLineSymbol;
            return renderer;
        }

However the renderer doesn't work for unique values and only shows the hardLineSymbol because it has been set as the default symbol as well. I have checked the attributes of features and they look good its the renderer it seems that is not changing shapes for unique values.

Thanks

Apurva

0 Kudos
1 Solution

Accepted Solutions
Nicholas-Furness
Esri Regular Contributor

When you create your Feature Collection Layer from your Feature Collection, you will see a number of subLayers (a FeatureCollection can have many FeatureCollectionTables, so when you create the FCL from a FC, it actually creates one layer per geometry-enabled table).

So, even if you just have the one table, you should set the renderer on the Feature Layer found in FeatureCollectionLayer.Layers and not on the FeatureCollectionLayer itself.

Or simpler still, set it on the table before you add it to the FeatureCollection (which is actually what your CreateNewFeatureCollection() function does). The FeatureLayer in the Layers collection will then derive its renderer from that upon instantiation.

View solution in original post

3 Replies
Nicholas-Furness
Esri Regular Contributor

When you create your Feature Collection Layer from your Feature Collection, you will see a number of subLayers (a FeatureCollection can have many FeatureCollectionTables, so when you create the FCL from a FC, it actually creates one layer per geometry-enabled table).

So, even if you just have the one table, you should set the renderer on the Feature Layer found in FeatureCollectionLayer.Layers and not on the FeatureCollectionLayer itself.

Or simpler still, set it on the table before you add it to the FeatureCollection (which is actually what your CreateNewFeatureCollection() function does). The FeatureLayer in the Layers collection will then derive its renderer from that upon instantiation.

ApurvaGoyal1
New Contributor

Thank you so much! This resolved my issue.

0 Kudos
MaximilianGlas
Esri Contributor

I had the same error pattern once. The reason was that I forgot to save the relevant value in the attribute in the feature.

feature.Attributes["SURTYPE"] = "SoftSurface";‍‍

If this is not the case for you:

Have you tried to use a more different symbol? Maybe you could not see a difference between dashed or solid for a point size of 2? I would try a different color ...

0 Kudos