Click or drag to resize
Code Example - PictureFillSymbol

Demonstrates the using a SimpleRenderer with options for PictureFillSymbol.

Code Example
Picture Fill 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="PictureFillSymbol.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. 
                        -->
                        <esri:FeatureLayer ID="States" >
                            <esri:FeatureLayer.FeatureTable>
                                <esri:ServiceFeatureTable 
                                    ServiceUri="https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/USA_States_Generalized/FeatureServer/0" />
                            </esri:FeatureLayer.FeatureTable>
                        </esri:FeatureLayer>

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

                <StackPanel Orientation="Vertical">

                    <!-- Add some controls so the user can adjust the size (With and Height) of the PictureFillSymbol. -->
                    <Label x:Name="Size" Content="Size (Width/Height):"/>
                    <Slider x:Name="SliderSize" Minimum="10" Maximum="100"  ValueChanged="SliderSize_ValueChanged"  Value="50">
                        <Slider.ToolTip >
                            <ToolTip Content="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget.Value}" />
                        </Slider.ToolTip>
                    </Slider>

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

namespace PictureFillSymbol
{
    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 will display using a SimpleRenderer based upon a " + 
                              "PictureFillSymbol. Adjust the Slider to make the PictureFillSymbol images larger/smaller.";

            // 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 SliderSize_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<double> 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/SafetyHealth/esriCrimeMarker_46.png ");

            // Create a new PictureFillSymbol based on the static image.
            Esri.ArcGISRuntime.Symbology.PictureFillSymbol myPictureFillSymbol = new Esri.ArcGISRuntime.Symbology.PictureFillSymbol();
            myPictureFillSymbol.SetSourceAsync(myPictureUri);

            // Create a new SimpleLineSymbol that will be used to show the outline of the various features in the FeatureLayer. If you do not 
            // specify a PictureFillSymbol.Outline you would not be able to see the State boundaries.
            Esri.ArcGISRuntime.Symbology.SimpleLineSymbol mySimpleLineSymbol = new Esri.ArcGISRuntime.Symbology.SimpleLineSymbol();
            mySimpleLineSymbol.Color = System.Windows.Media.Colors.Red;
            myPictureFillSymbol.Outline = mySimpleLineSymbol;

            // Apply the same PictureFillSymbol .Height and .Width values from what the user chose by adjusting the Slider.
            myPictureFillSymbol.Height = System.Convert.ToInt32(SliderSize.Value);
            myPictureFillSymbol.Width = System.Convert.ToInt32(SliderSize.Value);

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

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

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

    }
}