Apply unique values with alternate symbols

View inMAUIWPFWinUIView on GitHub

Apply a unique value with alternate symbols at different scales.

Apply unique values with alternate symbols sample

Use case

When a layer is symbolized with unique value symbology, you can specify the visible scale range for each unique value. This is an effective strategy to limit the amount of detailed data at smaller scales without having to make multiple versions of the layer, each with a unique definition query.

Once scale ranges are applied to unique values, you can further refine the appearance of features within those scale ranges by establishing alternate symbols to different parts of the symbol class scale range.

How to use the sample

Zoom in and out of the map to see alternate symbols at each scale. The symbology changes according to the following scale ranges: 0-5000, 5000-10000, 10000-20000. To go back to the initial viewpoint, press "Reset Viewpoint".

How it works

  1. Create a FeatureLayer using the service url and add it to the map's list of operational layers.

  2. Create two alternate symbols (a blue square and a yellow diamond) to be used as alternate symbols. To create an alternate symbol:

    a. Create a symbol using SimpleMarkerSymbol.

    b. Convert the simple marker symbol to a MultilayerSymbol using SimpleMarkerSymbol.ToMultilayerSymbol().

    c. Set the valid scale range through reference properties on the multilayer point symbols blue square and yellow diamond by calling MultilayerSymbol.ReferenceProperties = new SymbolReferenceProperties(double minScale, double maxScale);.

  3. Create a third multilayer symbol to be used to create a UniqueValue class.

  4. Create a unique value using the red triangle from step 3 and the list of alternate symbols from step 2.

  5. Create a UniqueValueRenderer and add the unique value from step 4 to it.

  6. Create a purple diamond simple marker and convert it to a multilayer symbol to be used as the default symbol.

  7. Set the DefaultSymbol property on the unique value renderer to the purple diamond from step 6.

  8. Add "req_type" to the field names on the unique value renderer.

  9. Set the unique value renderer as the renderer for the feature layer.

Relevant API

  • MultilayerSymbol
  • SimpleMarkerSymbol
  • SymbolReferenceProperties
  • UniqueValue
  • UniqueValueRenderer

About the data

The San Francisco 311 incidents layer in this sample displays point features related to crime incidents such as grafitti and tree damage that have been reported by city residents.

Tags

alternate symbols, scale based rendering, symbology, unique value, unique value renderer

Sample Code

UniqueValuesAlternateSymbols.xaml.csUniqueValuesAlternateSymbols.xaml.csUniqueValuesAlternateSymbols.xaml
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2022 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;

namespace ArcGIS.WinUI.Samples.UniqueValuesAlternateSymbols
{
    [ArcGIS.Samples.Shared.Attributes.Sample(
        name: "Apply unique values with alternate symbols",
        category: "Symbology",
        description: "Apply a unique value with alternate symbols at different scales.",
        instructions: "Zoom in and out of the map to see alternate symbols at each scale. The symbology changes according to the following scale ranges: 0-5000, 5000-10000, 10000-20000. To go back to the initial viewpoint, press \"Reset Viewpoint\".",
        tags: new[] { "alternate symbols", "scale based rendering", "symbology", "unique value", "unique value renderer" })]
    public partial class UniqueValuesAlternateSymbols
    {
        private Viewpoint _initialViewpoint = new Viewpoint(new MapPoint(-13631205.660131, 4546829.846004, SpatialReferences.WebMercator), 25000);

        public UniqueValuesAlternateSymbols()
        {
            InitializeComponent();
            Initialize();
        }

        private void Initialize()
        {
            // Create a feature layer using the feature table.
            var featureTable = new ServiceFeatureTable(new Uri("https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/0"));
            var featureLayer = new FeatureLayer(featureTable);

            // Create a symbol for a specific scale range.
            MultilayerPointSymbol triangleMultilayerSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Triangle, System.Drawing.Color.Red, 30).ToMultilayerSymbol();
            triangleMultilayerSymbol.ReferenceProperties = new SymbolReferenceProperties(minScale: 5000, maxScale: 0);

            // Create alternate symbols for use at different scale ranges.
            MultilayerPointSymbol blueAlternateSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Square, System.Drawing.Color.Blue, 30).ToMultilayerSymbol();
            blueAlternateSymbol.ReferenceProperties = new SymbolReferenceProperties(minScale: 10000, maxScale: 5000);

            MultilayerPointSymbol yellowAlternateSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, System.Drawing.Color.Yellow, 30).ToMultilayerSymbol();
            yellowAlternateSymbol.ReferenceProperties = new SymbolReferenceProperties(minScale: 20000, maxScale: 10000);

            var alternateSymbols = new List<Symbol> { blueAlternateSymbol, yellowAlternateSymbol };

            // Create a unique value with the triangle symbol and the alternate symbols.
            var uniqueValue = new UniqueValue("unique value", "unique values based on request type", triangleMultilayerSymbol, "Damaged Property", alternateSymbols);

            // Create a unique value renderer.
            var uniqueValueRenderer = new UniqueValueRenderer();
            uniqueValueRenderer.UniqueValues.Add(uniqueValue);
            uniqueValueRenderer.FieldNames.Add("req_type");

            // Set a default symbol for the unique value renderer. This will be use for features that aren't "Damaged Property" or when out of range of the UniqueValue symbols.
            uniqueValueRenderer.DefaultSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Diamond, System.Drawing.Color.Purple, 15).ToMultilayerSymbol();

            // Set the unique value renderer on the feature layer.
            featureLayer.Renderer = uniqueValueRenderer;

            // Create the map.
            MyMapView.Map = new Map(BasemapStyle.ArcGISTopographic) { InitialViewpoint = _initialViewpoint };
            MyMapView.Map.OperationalLayers.Add(featureLayer);
        }

        private void ResetViewpointClick(object sender, RoutedEventArgs e)
        {
            MyMapView.SetViewpointAsync(_initialViewpoint, TimeSpan.FromSeconds(5));
        }
    }

    public class ScaleToTextConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            if (double.IsNaN((double)value)) return "Scale:";
            return $"Scale: 1:{System.Convert.ToInt32(value)}";
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.