Click or drag to resize
Code Example - GraphicsLayer_RenderingMode

Demonstrates setting the various GraphicsLayer.RenderingMode options and their effect on TextSymbols when the MapView is rotated.

Code Example
Graphics Layer Rendering Mode

This section contains selected code files from a Visual Studio project that emphasize specific ArcGIS Runtime SDK (Windows Desktop) features. For example: some code examples may accomplish the bulk of the work as a configuration property in the .xaml file and hence only the .xaml file will be shown in detail below. In other code examples, the .xaml is used to define the configuration of graphical elements for the application but the application logic is performed in the code behind, hence you may see both the .xaml and .cs/.vb files shown in detail below.

XAML
<Window x:Class="GraphicsLayer_RenderingMode.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013"
    Title="MainWindow" Height="600" Width="800">

    <Grid x:Name="LayoutRoot">

        <StackPanel Orientation="Vertical">

            <!-- TextBlock to hold the instructions on how to use the sample code. -->
            <TextBlock Height="74" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" Width="775" 
                   TextWrapping="Wrap" Margin="7,0,0,0" />

            <!-- Add buttons for the user to interact with. -->
            <StackPanel Orientation="Horizontal">
                <Button HorizontalAlignment="Left" VerticalAlignment="Top" Content="Rotate 90" Click="Rotate_Click" Margin="0,0,5,0" />
                <Button HorizontalAlignment="Left" VerticalAlignment="Top" Content="Reset" Click="Reset_Click" />
            </StackPanel>

            <!-- Add a MapView Control. -->
            <esri:MapView x:Name="MapView1" Background="White" HorizontalAlignment="Left" Height="464" Width="792">

                <!-- Add a Map. -->
                <esri:Map x:Name="Map1">

                    <!-- Add an ArcGISTiledMapServiceLayer. -->
                    <esri:ArcGISTiledMapServiceLayer ID="Basemap" ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"/>

                </esri:Map>
            </esri:MapView>

        </StackPanel>

    </Grid>

</Window>

SPECIAL NOTE: The XAML displayed above comes from a C# project. If you are a VB.NET developer, you will need to modify the text for the x:Class namespace from "GraphicsLayer_RenderingMode.MainWindow" to be just "MainWindow".

namespace GraphicsLayer_RenderingMode
{
    public partial class MainWindow : System.Windows.Window
    {
        // Declare two GraphicsLayers; one using the RenderingMode of Dynamic and the other using the RenderingMode of Static.
        private Esri.ArcGISRuntime.Layers.GraphicsLayer _GraphicsLayer_Dynamic;
        private Esri.ArcGISRuntime.Layers.GraphicsLayer _GraphicsLayer_Static;

        public MainWindow()
        {
            InitializeComponent();

            // Add instructions on how to use the sample. 
            TextBlock1.Text = "When the application loads a background ArcGISTiledMapServiceLayer and two GraphicsLayers will be added " + 
                "to the Map. One GraphicsLayer will have it's RenderingMode set to Dynamic, the other GraphicsLayer will have it's " + 
                "RenderingMode set to Static. A TextSymbol will be added to each GraphicsLayer. Click the 'Rotate 90' button to have the " + 
                "MapView rotate 90 degrees. Observe how the TextSymbols behave differently based on the GraphicsLayers.RenderingMode.";

            // Create the GraphicsLayer and set it's RenderingMode to be Dynamic. 
            _GraphicsLayer_Dynamic = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
            _GraphicsLayer_Dynamic.RenderingMode = Esri.ArcGISRuntime.Layers.GraphicsRenderingMode.Dynamic;

            // Create a new Graphic.
            Esri.ArcGISRuntime.Layers.Graphic myGraphic1 = new Esri.ArcGISRuntime.Layers.Graphic();

            // Create a new MapPoint and set the Graphic's Geometry to be the MapPoint.
            Esri.ArcGISRuntime.Geometry.MapPoint myMapPoint = new Esri.ArcGISRuntime.Geometry.MapPoint(-5000000, -1000000);
            myGraphic1.Geometry = myMapPoint;

            // Create a new TextSymbol and set the Graphic's Symbol to be the TextSymbol.
            Esri.ArcGISRuntime.Symbology.TextSymbol myTextSymbol = new Esri.ArcGISRuntime.Symbology.TextSymbol();
            myTextSymbol.Text = "DYNAMIC - rotates independent of Map.";
            myTextSymbol.Color = System.Windows.Media.Colors.Red;
            myTextSymbol.AngleAlignment = Esri.ArcGISRuntime.Symbology.MarkerAngleAlignment.Screen;
            myTextSymbol.Font = new Esri.ArcGISRuntime.Symbology.SymbolFont("Arial", 18);
            myGraphic1.Symbol = myTextSymbol;

            // Add the Graphic to the GraphicsLayer's GraphicCollection.
            _GraphicsLayer_Dynamic.Graphics.Add(myGraphic1);

            // Add the GraphicsLayer to the Map's LayerCollection. 
            MapView1.Map.Layers.Add(_GraphicsLayer_Dynamic);

            // ------------------------------------------------------------------------------------------------------

            // Create the GraphicsLayer and set it's RenderingMode to be Static. 
            _GraphicsLayer_Static = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
            _GraphicsLayer_Static.RenderingMode = Esri.ArcGISRuntime.Layers.GraphicsRenderingMode.Static;

            // Create a new Graphic.
            Esri.ArcGISRuntime.Layers.Graphic myGraphic2 = new Esri.ArcGISRuntime.Layers.Graphic();

            // Create a new MapPoint and set the Graphic's Geometry to be the MapPoint.
            Esri.ArcGISRuntime.Geometry.MapPoint myMapPoint2 = new Esri.ArcGISRuntime.Geometry.MapPoint(-5000000, -0);
            myGraphic2.Geometry = myMapPoint2;

            // Create a new TextSymbol and set the Graphic's Symbol to be the TextSymbol.
            Esri.ArcGISRuntime.Symbology.TextSymbol myTextSymbol2 = new Esri.ArcGISRuntime.Symbology.TextSymbol();
            myTextSymbol2.Text = "STATIC - stays same orientation as Map.";
            myTextSymbol2.Color = System.Windows.Media.Colors.Blue;
            myTextSymbol2.AngleAlignment = Esri.ArcGISRuntime.Symbology.MarkerAngleAlignment.Screen;
            myTextSymbol2.Font = new Esri.ArcGISRuntime.Symbology.SymbolFont("Arial", 18);
            myGraphic2.Symbol = myTextSymbol2;

            // Add the Graphic to the GraphicsLayer's GraphicCollection.
            _GraphicsLayer_Static.Graphics.Add(myGraphic2);

            // Add the GraphicsLayer to the Map's LayerCollection. 
            MapView1.Map.Layers.Add(_GraphicsLayer_Static);
        }

        private void Reset_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Reset the MapView's rotation back to it's default setting.
            MapView1.SetRotationAsync(0);
        }

        private void Rotate_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // Rotate the MapView by +90 degrees.
            MapView1.SetRotationAsync(MapView1.Rotation + 90);
        }

    }
}