Click or drag to resize
Code Example - PictureMarkerSymbol

Demonstrates the using a SimpleRenderer with options for SimpleMarkerSymbol, PictureMarkerSymbol, and TextMarkerSymbol.

Code Example
Picture Marker Symbol

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="PictureMarkerSymbol.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="600" Width="800"
    xmlns:esri="http://schemas.esri.com/arcgis/runtime/2013">

    <Grid>

        <StackPanel Orientation="Vertical">
            <StackPanel Orientation="Vertical">

                <!-- TextBlock to provide the instructions on how to use the sample code. It will be 
                populated with instructions in the code-behind when the application loads. -->
                <TextBlock Height="58" HorizontalAlignment="Left" Name="TextBlock1" VerticalAlignment="Top" 
                           Width="770" TextWrapping="Wrap"  Margin="10,2,0,0" />

            </StackPanel>
            <StackPanel Orientation="Horizontal">

                <!-- A MapView Control to display various GIS layers. -->
                <esri:MapView x:Name="MapView1" Width="643" Height="480" VerticalAlignment="Top" Margin="2,2,2,2" >

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

                        <!-- Add a backdrop ArcGISTiledMapServiceLayer. -->
                        <esri:ArcGISTiledMapServiceLayer ID="World_Light_Gray_Base" 
                              ServiceUri="http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer"/>

                        <!-- 
                        Add a FeatureLayer. Set the ServiceFeatureTable ServiceUri to public ArcGIS Server web service. Set 
                        the Where clause to restrict the data coming back to just the capital cities of each state.
                        -->
                        <esri:FeatureLayer ID="Cities" >
                            <esri:FeatureLayer.FeatureTable>
                                <esri:ServiceFeatureTable 
                                    ServiceUri="http://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0" 
                                    Where="capital='Y'"/>
                            </esri:FeatureLayer.FeatureTable>
                        </esri:FeatureLayer>
                    </esri:Map>
                </esri:MapView>

                <StackPanel Orientation="Vertical">

                    <!-- Button to render the FeatureLayer using a PictureMarkerSymbol via code-behind. -->
                    <Button Content="PictureMarkerSymbol" 
                        x:Name="Button1" Click="Button1_Click" Width="144" HorizontalAlignment="Left"/>

                    <!-- Button to render the FeatureLayer using a SimpleMarkerSymbol via code-behind. -->
                    <Button Content="SimpleMarkerSymbol" 
                        x:Name="Button2" Click="Button2_Click" Width="144" HorizontalAlignment="Left"/>

                    <!-- Button to render the FeatureLayer using a TextSymbol via code-behind. -->
                    <Button Content="TextSymbol" 
                        x:Name="Button3" Click="Button3_Click" Width="144" HorizontalAlignment="Left"/>

                    <!-- Button to reset the rendering of the FeatureLayer back to its web service defined state. -->
                    <Button Content="DefaultRenderer" 
                        x:Name="Button4" Click="Button4_Click" Width="144" HorizontalAlignment="Left"/>

                </StackPanel>

            </StackPanel>
        </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 "PictureMarkerSymbol.MainWindow" to be just "MainWindow".

namespace PictureMarkerSymbol
{
    public partial class MainWindow : System.Windows.Window
    {
        public MainWindow()
        {
            InitializeComponent();

            // Add instructions on how to use the sample. 
            TextBlock1.Text = "When the application loads a FeatureLayer with it's default web service defined symbology" + 
                " will display. Click the various buttons to see using different types of SimpleRenderer options. The " + 
                " last button resets the drawing of the symbology back to the web service defined symbology.";

            // Zoom to a specified target area in the in the Map.
            Esri.ArcGISRuntime.Geometry.Envelope myEnvelope = new Esri.ArcGISRuntime.Geometry.Envelope(-14458738, 2168553, -6679169, 6937637);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myEnvelope);
        }

        private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            // Create a Uri that points to an image on a web server.
            // NOTE: there are hundreds of available images from Esri. Look in the Library Reference documentation for the 'Static Images' document 
            // in the Fundamental section for the actual image and the URL on the http://staticarcgis.com web server.
            System.Uri myPictureUri = new System.Uri("http://static.arcgis.com/images/Symbols/Transportation/SkullandCrossbones.png");

            // Create a new PictureMarkerSymbol based on the static image and set a few properties.
            Esri.ArcGISRuntime.Symbology.PictureMarkerSymbol myPictureMarkerSymbol = new Esri.ArcGISRuntime.Symbology.PictureMarkerSymbol();
            myPictureMarkerSymbol.SetSourceAsync(myPictureUri);
            myPictureMarkerSymbol.Angle = 30;
            myPictureMarkerSymbol.Height = 30;
            myPictureMarkerSymbol.Width = 30;

            // Create a new SimpleRenderer and apply the PictureMarkerSymbol as the .Symbol property.
            Esri.ArcGISRuntime.Symbology.SimpleRenderer mySimpleRenderer = new Esri.ArcGISRuntime.Symbology.SimpleRenderer();
            mySimpleRenderer.Symbol = myPictureMarkerSymbol;

            // Get the FeatureLayer from the LayerCollection in the Map.
            Esri.ArcGISRuntime.Layers.FeatureLayer myFeatureLayer = (Esri.ArcGISRuntime.Layers.FeatureLayer)MapView1.Map.Layers["Cities"];

            // Set the FeatureLayer.Renderer to the SimpleRenderer. This will cause a refresh of the map.
            myFeatureLayer.Renderer = mySimpleRenderer;

        }

        private void Button2_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            // Create a new SimpleMarkerSymbol and set a few properties. NOTE: If no properties are set by default it will be a red circle.
            Esri.ArcGISRuntime.Symbology.SimpleMarkerSymbol mySimpleMarkerSymbol = new Esri.ArcGISRuntime.Symbology.SimpleMarkerSymbol();
            mySimpleMarkerSymbol.Color = System.Windows.Media.Colors.Black;
            mySimpleMarkerSymbol.Size = 10;
            mySimpleMarkerSymbol.Style = Esri.ArcGISRuntime.Symbology.SimpleMarkerStyle.Diamond;

            // Create a new SimpleRenderer and apply the SimpleMarkerSymbol as the .Symbol property.
            Esri.ArcGISRuntime.Symbology.SimpleRenderer mySimpleRenderer = new Esri.ArcGISRuntime.Symbology.SimpleRenderer();
            mySimpleRenderer.Symbol = mySimpleMarkerSymbol;

            // Get the FeatureLayer from the LayerCollection in the Map.
            Esri.ArcGISRuntime.Layers.FeatureLayer myFeatureLayer = (Esri.ArcGISRuntime.Layers.FeatureLayer)MapView1.Map.Layers["Cities"];

            // Set the FeatureLayer.Renderer to the SimpleRenderer. This will cause a refresh of the map.
            myFeatureLayer.Renderer = mySimpleRenderer;

        }

        private void Button3_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            // Create a new SymbolFont and set a few properties.
            Esri.ArcGISRuntime.Symbology.SymbolFont mySymbolFont = new Esri.ArcGISRuntime.Symbology.SymbolFont();
            mySymbolFont.FontFamily = "Verdana";
            mySymbolFont.FontSize = 12;
            mySymbolFont.FontStyle = Esri.ArcGISRuntime.Symbology.SymbolFontStyle.Italic;
            mySymbolFont.FontWeight = Esri.ArcGISRuntime.Symbology.SymbolFontWeight.Bold;

            // Create a new TextSymbol and set a few properties. NOTE: If no properties are set by default it will be FontFamily=Arial, FontSize=10, Color=black
            Esri.ArcGISRuntime.Symbology.TextSymbol myTextSymbol = new Esri.ArcGISRuntime.Symbology.TextSymbol();
            myTextSymbol.Text = "GIS";
            myTextSymbol.Font = mySymbolFont;
            myTextSymbol.Color = System.Windows.Media.Colors.Green;

            // Create a new SimpleRenderer and apply the TextSymbol as the .Symbol property.
            Esri.ArcGISRuntime.Symbology.SimpleRenderer mySimpleRenderer = new Esri.ArcGISRuntime.Symbology.SimpleRenderer();
            mySimpleRenderer.Symbol = myTextSymbol;

            // Get the FeatureLayer from the LayerCollection in the Map.
            Esri.ArcGISRuntime.Layers.FeatureLayer myFeatureLayer = (Esri.ArcGISRuntime.Layers.FeatureLayer)MapView1.Map.Layers["Cities"];

            // Set the FeatureLayer.Renderer to the SimpleRenderer. This will cause a refresh of the map.
            myFeatureLayer.Renderer = mySimpleRenderer;

        }

        private void Button4_Click(object sender, System.Windows.RoutedEventArgs e)
        {

            // Get the FeatureLayer from the LayerCollection in the Map.
            Esri.ArcGISRuntime.Layers.FeatureLayer myFeatureLayer = (Esri.ArcGISRuntime.Layers.FeatureLayer)MapView1.Map.Layers["Cities"];

            // Set the FeatureLayer.Renderer to Nothing/null which will reset the rendering back to the web service default. This will cause a refresh of the map.
            myFeatureLayer.Renderer = null;

        }    


    }
}