﻿using Esri.ArcGISRuntime.ArcGISServices;
using Esri.ArcGISRuntime.Layers;
using Windows.UI.Xaml.Controls;

namespace ArcGISRuntime.Samples.Phone.Samples
{
	/// <summary>
	/// This sample demonstrates applying raster functions to an image service layer.
	/// </summary>
	/// <title>Image Service Raster Functions</title>
	/// <category>Dynamic Service Layers</category>
	public sealed partial class ImageServiceRasterFunctions : Page
    {
		public ImageServiceRasterFunctions()
		{
			this.InitializeComponent();
		}

		private void RasterFunctionsComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			ArcGISImageServiceLayer imageLayer = MyMapView.Map.Layers["ImageLayer"] as ArcGISImageServiceLayer;
			var rasterFunction = (sender as ComboBox).SelectedItem as RasterFunctionInfo;
			if (rasterFunction != null)
			{
				RenderingRule renderingRule = new RenderingRule() { RasterFunctionName = rasterFunction.FunctionName };
				imageLayer.RenderingRule = renderingRule;
			}
		}

		private void MyMapView_LayerLoaded(object sender, Esri.ArcGISRuntime.Controls.LayerLoadedEventArgs e)
		{
			if (e.Layer.ID == "ImageLayer")
			{
				ArcGISImageServiceLayer imageLayer = e.Layer as ArcGISImageServiceLayer;
				if (e.LoadError == null)
				{
					RasterFunctionsComboBox.ItemsSource = imageLayer.ServiceInfo.RasterFunctionInfos;
					RasterFunctionsComboBox.SelectedIndex = 0;
				}
			}
		}
    }
}
