Skip To Content ArcGIS for Developers Sign In Dashboard

ArcGIS Runtime SDK for .NET

Dictionary renderer with feature layer

This code sample is available for these platforms:
View Sample on GitHub

Convert features into graphics to show them with mil2525d symbols.

screenshot

Use case

A dictionary renderer uses a style file along with a rule engine to display advanced symbology. This is useful for displaying features using precise military symbology.

How it works

  1. Create a Geodatabase using Geodatabase(geodatabasePath).
  2. Load the geodatabase asynchronously using Geodatabase.LoadAsync().
  3. Instantiate a SymbolDicitonary using SymbolDictionary(specificationType).
    • specificationType will be the mil2525d.stylx file.
  4. Load the symbol dictionary asynchronously using DictionarySymbol.LoadAsync().
  5. Wait for geodatabase to completely load.
  6. Cycle through each GeodatabaseFeatureTable from the geodatabase using Geodatabase.GeodatabaseFeatureTables.
  7. Create a FeatureLayer from each table within the geodatabase using FeatureLayer(GeodatabaseFeatureTable).
  8. Load the feature layer asynchronously with FeatureLayer.LoadAsync().
  9. Wait for each layer to load.
  10. After the last layer has loaded, then create a new Envelope from a union of the extents of all layers.
    • Set the envelope to be the Viewpoint of the map view using MapView.SetViewpoint(new Viewpoint(Envelope)).
  11. Add the feature layer to map using Map.OperationalLayers.Add(FeatureLayer).
  12. Create DictionaryRenderer(SymbolDictionary) and attach to the feature layer.

Relevant API

  • DictionaryRenderer
  • SymbolDictionary

Offline data

This sample downloads the following items from ArcGIS Online automatically:

  • mil2525d.stylx - A stylx file for use with ArcGIS Runtime 100.0 - 100.4 to build custom applications that incorporate the MIL-STD-2525D symbol dictionary.
  • militaryoverlay.geodatabase.zip - This is a mobile geodatabase created from the Military Overlay template for use in ArcGIS Runtime samples

Tags

DictionaryRenderer, DictionarySymbolStyle, military, symbol

Sample Code

<UserControl 
    x:Class="ArcGISRuntime.UWP.Samples.FeatureLayerDictionaryRenderer.FeatureLayerDictionaryRenderer"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:esri="using:Esri.ArcGISRuntime"
    xmlns:esriUI="using:Esri.ArcGISRuntime.UI.Controls" 
    mc:Ignorable="d" 
    d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <esriUI:MapView x:Name="MyMapView" />
    </Grid>
</UserControl>
// Copyright 2017 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 System;
using Windows.UI.Popups;
using ArcGISRuntime.Samples.Managers;
using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using Esri.ArcGISRuntime.Symbology;

namespace ArcGISRuntime.UWP.Samples.FeatureLayerDictionaryRenderer
{
    [ArcGISRuntime.Samples.Shared.Attributes.Sample(
        "Feature layer dictionary renderer",
        "Layers",
        "Demonstrates how to apply a dictionary renderer to a feature layer and display mil2525d graphics. The dictionary renderer creates these graphics using a mil2525d style file and the attributes attached to each feature within the geodatabase.",
        "",
        "Military", "Symbology", "Military symbology")]
	[ArcGISRuntime.Samples.Shared.Attributes.OfflineData("c78b149a1d52414682c86a5feeb13d30", "e0d41b4b409a49a5a7ba11939d8535dc")]
    public partial class FeatureLayerDictionaryRenderer
    {
        public FeatureLayerDictionaryRenderer()
        {
            InitializeComponent();

            // Setup the control references and execute initialization
            Initialize();
        }

        private async void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Provide Map to the MapView
            MyMapView.Map = myMap;
            
            // Get the path to the geodatabase
            string geodbFilePath = GetGeodatabasePath();

            // Load the geodatabase from local storage
            Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);

            // Get the path to the symbol dictionary
            string symbolFilepath = GetStyleDictionaryPath();

            try
            {
                // Load the symbol dictionary from local storage
                DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.CreateFromFileAsync(symbolFilepath);

                // Add geodatabase features to the map, using the defined symbology
                foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
                {
                    // Load the table
                    await table.LoadAsync();

                    // Create the feature layer from the table
                    FeatureLayer myLayer = new FeatureLayer(table);

                    // Load the layer
                    await myLayer.LoadAsync();

                    // Create a Dictionary Renderer using the DictionarySymbolStyle
                    DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);

                    // Apply the dictionary renderer to the layer
                    myLayer.Renderer = dictRenderer;

                    // Add the layer to the map
                    myMap.OperationalLayers.Add(myLayer);
                }
                    
                // Create geometry for the center of the map
                MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));

                // Set the map's viewpoint to highlight the desired content
                MyMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555));
            }
            catch (Exception e)
            {
                await new MessageDialog(e.ToString(), "Error").ShowAsync();
            }
        }

        // Get the file path for the style dictionary
        private static string GetStyleDictionaryPath()
        {
            return DataManager.GetDataFolder("c78b149a1d52414682c86a5feeb13d30", "mil2525d.stylx");
        }

        // Get the file path for the geodatabase
        private static string GetGeodatabasePath()
        {
            return DataManager.GetDataFolder("e0d41b4b409a49a5a7ba11939d8535dc", "militaryoverlay.geodatabase");
        }
    }
}