using System; using System.Windows; using System.Windows.Media.Imaging; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Symbols; using ESRI.ArcGIS.Client.Toolkit.DataSources; using OpenEarth.DataViewer.BwnFunctionsReference; using OpenEarth.DataViewer.Helpers; namespace OpenEarth.DataViewer.Windows { /// /// Interaction logic for Map.xaml /// public partial class Map { private LayerWrapper wrapper; private Draw drawObject; private Symbol activeSymbol; private Graphic graphic; public Map() { InitializeComponent(); InitializeDrawing(); } private void InitializeDrawing() { drawObject = new Draw(MainMap) { LineSymbol = LayoutRoot.Resources["DrawLineSymbol"] as LineSymbol, FillSymbol = LayoutRoot.Resources["DrawFillSymbol"] as FillSymbol }; drawObject.DrawComplete += DrawObjectDrawComplete; } public void LoadLayer(LayerWrapper layerWrapper) { if (wrapper != null) { MainMap.Layers.Remove(layerWrapper.Layer); } wrapper = layerWrapper; MainMap.Layers.Add(layerWrapper.Layer); } private void DrawingToolbarItemClicked(object sender, ESRI.ArcGIS.Client.Toolkit.SelectedToolbarItemArgs e) { switch (e.Index) { case 0: // Point drawObject.DrawMode = DrawMode.Point; activeSymbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol; break; case 1: // Polyline drawObject.DrawMode = DrawMode.Polyline; activeSymbol = LayoutRoot.Resources["DefaultLineSymbol"] as Symbol; break; case 2: // Polygon drawObject.DrawMode = DrawMode.Polygon; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; case 3: // Rectangle drawObject.DrawMode = DrawMode.Rectangle; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; case 4: // Freehand drawObject.DrawMode = DrawMode.Freehand; activeSymbol = LayoutRoot.Resources["DefaultLineSymbol"] as Symbol; break; case 5: // Arrow drawObject.DrawMode = DrawMode.Arrow; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; case 6: // Triangle drawObject.DrawMode = DrawMode.Triangle; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; case 7: // Circle drawObject.DrawMode = DrawMode.Circle; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; case 8: // Ellipse drawObject.DrawMode = DrawMode.Ellipse; activeSymbol = LayoutRoot.Resources["DefaultFillSymbol"] as Symbol; break; default: // Clear Graphics drawObject.DrawMode = DrawMode.None; GraphicsLayer graphicsLayer = MainMap.Layers["DrawingLayer"] as GraphicsLayer; if (graphicsLayer != null) graphicsLayer.ClearGraphics(); break; } drawObject.IsEnabled = (drawObject.DrawMode != DrawMode.None); } private void DrawingToolbarIndexChanged(object sender, ESRI.ArcGIS.Client.Toolkit.SelectedToolbarItemArgs e) { StatusTextBlock.Text = e.Item.Text; } private void DrawObjectDrawComplete(object sender, DrawEventArgs args) { GraphicsLayer graphicsLayer = MainMap.Layers["DrawingLayer"] as GraphicsLayer; if (graphicsLayer != null) { // comment the following line to allow multiple polygons graphic = null; graphicsLayer.Graphics.Clear(); graphic = new Graphic { Geometry = args.Geometry, Symbol = activeSymbol, }; graphicsLayer.Graphics.Add(graphic); } } private void ButtonInterpolateClick(object sender, RoutedEventArgs e) { if (graphic != null) { PrepareShowImage(); try { using (BwnFunctionsWrapperSoapClient client = new BwnFunctionsWrapperSoapClient()) { if (wrapper != null && !string.IsNullOrEmpty(wrapper.Source) && !string.IsNullOrEmpty(wrapper.Variable)) { string result = client.InterpolateToLine( wrapper.Source, wrapper.Variable, graphic.Geometry.Extent.GetCenter().Y, graphic.Geometry.Extent.GetCenter().X, graphic.Geometry.Extent.YMax, graphic.Geometry.Extent.XMax); ShowImage(new Uri("http://viewer.openearth.nl/bwnmatlab/" + result)); } } } catch (Exception ex) { Logger.Log("OpenEarth.Dataviewer", ex); #if DEBUG throw; #endif } } } private void ButtonActionResultCloseClick(object sender, RoutedEventArgs e) { HideImage(); } private void PrepareShowImage() { imageActionResultOverlay.Visibility = Visibility.Visible; ActionResult.Visibility = Visibility.Visible; } private void ShowImage(Uri uri) { imageActionResultOverlay.Visibility = Visibility.Hidden; imageActionResult.Visibility = Visibility.Visible; imageActionResult.Source = new BitmapImage(uri); } private void HideImage() { ActionResult.Visibility = Visibility.Hidden; imageActionResult.Visibility = Visibility.Hidden; imageActionResult.Source = null; } } }