Select to view content in your preferred language

WPF map with feature service layer. Bring feature to top of drawing list.

1138
4
05-12-2023 12:43 PM
Labels (2)
ChrisCrowe
Emerging Contributor

I have a WPF application and it has a simple feature service along with a Unique values renderer.

Some of my features have the same polygon shape or they may overlay other features and I would like to bring a specific feature to the top of the drawing order so it will be visible.

I am using my FeatureLayer.FeatureTable.QueryFeaturesAsync(queryParams) to get the actual feature I want. 

But I do not know how to change the drawing order of the feature so that it will be on top.

This is my basic code to find the feature and select it. 

var featureResult = await this.ProjectLayer.FeatureTable!.QueryFeaturesAsync(queryParams);
if (featureResult.FirstOrDefault() != null)
{
     this.ProjectLayer.SelectFeature(featureResult.FirstOrDefault()!);

}

But how do I change the drawing order?

 

 

Tags (2)
0 Kudos
4 Replies
PreetiMaske
Esri Regular Contributor

Currently there is no way to change the drawing order of the features. We have the enhancement logged in our system internally but it has not been prioritized for any recent release. I would be interested in understanding your workflow or use case to change the drawing order to help us better prioritize the issue.

 

0 Kudos
ChrisCrowe
Emerging Contributor
Hi

I have managed to move my features to separate layers and I can then change
the order of the layers to simulate the drawing list order.

Basically we have a Map which shows a polygon of an area for each row in a
grid. When the user selects a different container in the grid we just want
its data to be placed on top so the user can see the data. We won't have
more than 20-30 items ever in the grid.

We originally had a unique value renderer but we dropped that and created a
simple renderer based on details in the fields as well.

chris


0 Kudos
dotMorten_esri
Esri Notable Contributor

You could use the select feature to highlight it - I do believe that also brings it up to ensure the highlight is visible. Of course that implies getting the feature highlighted as well, which you may or may not be interested in, but it would ensure the user can see the data.

0 Kudos
ChrisCrowe1
Emerging Contributor

Screenshot 2023-05-19 102818.png

This map has two features.    The circle is behind the rectangle.

Screenshot 2023-05-19 102602.png

Selecting the circle does not bring it forward but it does show the highlight. If the circle was fully behind the rectangle then it would not be visible, only the border is visible when selected.

My code in c#

            Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.ApiKey = "YOUR KEY";

            // Create a new unique value renderer.
            UniqueValueRenderer regionRenderer = new UniqueValueRenderer();

            // Add the "SUB_REGION" field to the renderer.
            regionRenderer.FieldNames.Add("Color");

            // Define a line symbol to use for the region fill symbols.
            SimpleLineSymbol stateOutlineSymbol = new SimpleLineSymbol(
                SimpleLineSymbolStyle.Solid, System.Drawing.Color.White, 0.7);

            // Define distinct fill symbols for a few regions (use the same outline symbol).
            SimpleFillSymbol redFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.FromArgb(128, System.Drawing.Color.Blue), stateOutlineSymbol);
            SimpleFillSymbol greenFillSymbol = new SimpleFillSymbol(
                SimpleFillSymbolStyle.Solid, System.Drawing.Color.FromArgb(128, System.Drawing.Color.LawnGreen), stateOutlineSymbol);

            // Add values to the renderer: define the label, description, symbol, and attribute value for each.
            regionRenderer.UniqueValues.Add(new UniqueValue("Red", "Red", redFillSymbol, "Red"));
            regionRenderer.UniqueValues.Add(new UniqueValue("Green", "Green", greenFillSymbol, "Green"));

            // Set the default region fill symbol for regions not explicitly defined in the renderer.
            regionRenderer.DefaultSymbol = new SimpleFillSymbol(SimpleFillSymbolStyle.Cross, System.Drawing.Color.Gray, null);
            regionRenderer.DefaultLabel = "Other";


            // Create new Map with basemap.
            Map myMap = new Map(BasemapStyle.ArcGISTopographic);

            // Create URL to the census feature service.
            Uri serviceUri = new Uri(
                "https://services7.arcgis.com/MhdOcDlgweSdpoZT/arcgis/rest/services/overlayedfeartures/FeatureServer/0");

            // Create service feature table.
            ServiceFeatureTable featureTable = new ServiceFeatureTable(serviceUri);

            // Create a query to get all features in the table
            QueryParameters queryParams = new QueryParameters
            {
                //WhereClause = $"Color = 'Red'"
               WhereClause = "1=1"
            };

            // Query the table to get all features
            FeatureQueryResult featureResult = featureTable.QueryFeaturesAsync(queryParams, QueryFeatureFields.LoadAll).Result;

            // Create a new feature collection table from the result features
            FeatureCollectionTable collectTable = new FeatureCollectionTable(featureResult);
            // Create a feature collection and add the table
            FeatureCollection featCollection = new FeatureCollection();
            featCollection.Tables.Add(collectTable);

            // Create a layer to display the feature collection, add it to the map's operational layers
            FeatureCollectionLayer featureCollectionLayer = new FeatureCollectionLayer(featCollection);            

            // Apply the unique value renderer to the states layer.
            collectTable.Renderer = regionRenderer;

            myMap.OperationalLayers.Add(featureCollectionLayer);


            // Assign the map to the MapView.
            MyMapView.Map = myMap;

            MyMapView.SetViewpointCenterAsync(-43.5231591, 172.6139359, 50000);

            featureCollectionLayer.LoadAsync();
            featureCollectionLayer.Layers.First().SelectFeature(collectTable.First());

 

Chris

 

0 Kudos