Click or drag to resize
Code Example - ArcGISImageServiceLayerWindow

Shows creating an ArcGIS Image Service Layer and applying rendering rules.

Code Example
ArcGISImage Service Layer Window

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="ArcGISImageServiceLayerWindow.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"
        Height="600" Width="800"
        Tag="ArcGISImageServiceLayerWindow" >

    <Grid>

        <!-- Add a MapView Control. Set the WrapAround mode to true and give it a name that can be
            referenced in the code-behind.-->
        <esri:MapView x:Name="MapView1" WrapAround="True">

            <!-- Add a Map,  -->
            <esri:Map  x:Name="MyMap">

                <!-- Add a BingLayer as a backdrop. -->
                <!-- IMPORTANT: You will need to obtain a Bing Key from Microsoft at: https://www.bingmapsportal.com/ -->
                <esri:BingLayer Key="ENTER_YOUR_BING_KEY_TOKEN_HERE"  
                                MapStyle="AerialWithLabels"/>

                <!-- Add an ArcGISDynamicMapServiceLayer. -->
                <esri:ArcGISImageServiceLayer ID="CaliforniaDEM"
                    ServiceUri="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Earthquakes/CaliforniaDEM/ImageServer" />
            </esri:Map>
        </esri:MapView>

        <!-- Add some controls so that user can apply different renderings to the ArcGISDynamicMapServiceLayer. -->
        <StackPanel Width="250" HorizontalAlignment="Right" VerticalAlignment="Top" Background="Black"
                    Orientation="Vertical">

            <!-- When the user clicks this button the ArcGISImageServiceLayer is re-rendered using 
            an Aspect RenderingRule. -->
            <Button Margin="3" Content="Apply Aspect Rule" Click="OnApplyRenderingRuleClicked"/>

            <!-- When the user clicks this button the ArcGISImageServiceLayer is re-rendered using 
            one of the ComboBox choices of: Random, NDVI, Elevation, or Gray RenderingRule. -->
            <StackPanel Orientation="Horizontal">
                <Button Margin="3" Content="Make Colormap" Click="OnMakeColorMapClicked"/>
                <ComboBox x:Name="RasterParamCombo">
                    <ComboBoxItem Content="Random"/>
                    <ComboBoxItem Content="NDVI"/>
                    <ComboBoxItem Content="Elevation"/>
                    <ComboBoxItem Content="Gray"/>
                </ComboBox>
            </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 "ArcGISImageServiceLayerWindow.MainWindow" to be just "MainWindow".

// NOTE: This sample shows creating an ArcGIS Image Service Layer and applying rendering rules.
// 
// TIP: The Map will open at the extent of the world. Double click on the map with your mouse (or
// use your mouse scroll wheel) to zoom into the area of California before clicking the various
// buttons for a better viewing effect of re-rendering the ArcGISImageServiceLayer.

namespace ArcGISImageServiceLayerWindow
{
    public partial class MainWindow : System.Windows.Window
    {

        public MainWindow()
        {
            InitializeComponent();

            // Set the initial choice of the ComboBox to be the first one.
            RasterParamCombo.SelectedIndex = 0;

            // Set the initial Map extent using the InitialViewpoint Property.
            Esri.ArcGISRuntime.Geometry.Geometry myGeometry = new Esri.ArcGISRuntime.Geometry.Envelope(-13923729, 3677901, -11419040, 5329344, Esri.ArcGISRuntime.Geometry.SpatialReferences.WebMercator);
            MapView1.Map.InitialViewpoint = new Esri.ArcGISRuntime.Controls.Viewpoint(myGeometry);        
        }

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

            // The user clicked the Button to apply the Aspect RenderingRule to the ArcGISImageServiceLayer.

            try
            {

                // Get the LayerCollection from the Map Control.
                Esri.ArcGISRuntime.Layers.LayerCollection myLayerCollection = MapView1.Map.Layers;

                // Get the ArcGISDynamicMapServiceLayer from the LayerCollection by it's ID String value.
                Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer myArcGISImageServiceLayer = null;
                myArcGISImageServiceLayer = myLayerCollection["CaliforniaDEM"] as Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer;

                // Define a new RenderingRule.
                Esri.ArcGISRuntime.Layers.RenderingRule myRenderingRule = new Esri.ArcGISRuntime.Layers.RenderingRule();

                // Define the 'Aspect' RenderingRule function.
                myRenderingRule.RasterFunctionName = "Aspect";

                // Apply the new 'Aspect' RenderingRule to the ArcGISImageServiceLayer.
                myArcGISImageServiceLayer.RenderingRule = myRenderingRule;

            }
            catch (System.Exception ex)
            {
                // We have a problem. Notify the user.
                System.Windows.MessageBox.Show(ex.ToString());
            }

        }

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

            // The user clicked the button to apply any number of RenderingRule functions to the 
            // ArcGISImageServiceLayer based upon the options specified in the ComboBox. They are:
            // "Random", "NDVI", "Elevation", and "Gray".

            try
            {

                // Get the LayerCollection from the Map Control.
                Esri.ArcGISRuntime.Layers.LayerCollection myLayerCollection = MapView1.Map.Layers;

                // Get the ArcGISDynamicMapServiceLayer from the LayerCollection by it's ID String value.
                Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer myArcGISImageServiceLayer = null;
                myArcGISImageServiceLayer = myLayerCollection["CaliforniaDEM"] as Esri.ArcGISRuntime.Layers.ArcGISImageServiceLayer;

                // Define a new RenderingRule.
                Esri.ArcGISRuntime.Layers.RenderingRule myRenderingRule = new Esri.ArcGISRuntime.Layers.RenderingRule();

                // Note: The .RasterFunctonName must use the text string 'Colormap'.

                myRenderingRule.RasterFunctionName = "Colormap";

                // Note: the .VariableName must use the text string 'Raster'.
                myRenderingRule.VariableName = "Raster";

                // Define a Dictionary object with String/Object pairs. The Strings that are used for the keys as 
                // Dictionary entries will need to have exact text strings depending on what raster function is being used.
                System.Collections.Generic.Dictionary<string, object> rasterParams = new System.Collections.Generic.Dictionary<string, object>();

                // Example #1: Create a random set of colors for the color map.
                // Note: The a key of 'ColormapName' takes the string 'Random'.
                rasterParams.Add("ColormapName", RasterParamCombo.SelectionBoxItem.ToString());

                // Add the rasterParms Dictionary as the RenderingRule's RasterFunctionArguments.
                myRenderingRule.RasterFunctionArguments = rasterParams;

                // Apply the user defined myRenderingRule to the ArcGISImageServiceLayer's .RenderingRule
                myArcGISImageServiceLayer.RenderingRule = myRenderingRule;

            }
            catch (System.Exception ex)
            {
                // We have a problem. Notify the user.
                System.Windows.MessageBox.Show(ex.ToString());
            }

        }


    }
}