Table of Contents

Source Code AndroidEditionSample DrawEditFeatures.zip

MainActivity.cs

 using Android.App;  
 using Android.OS;  
 using Android.Views;  
 using Android.Widget;  
 using System;  
 using System.Collections.Generic;  
 using ThinkGeo.MapSuite.AndroidEdition;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace DrawEditFeatures  
 {  
     [Activity(Label = "Draw Edit", MainLauncher = true, Icon = "@drawable/icon")]  
     public class MainActivity : Activity  
     {  
         private int contentHeight;  
         private MapView androidMap;  
         private ImageButton editButton;  
         private ImageButton lineButton;  
         private ImageButton pointButton;  
         private ImageButton clearButton;  
         private ImageButton cursorButton;  
         private ImageButton circleButton;  
         private ImageButton polygonButton;  
         private ImageButton ellipseButton;  
         private ImageButton rectangleButton;  
         private ImageButton drawButton;  
         private LinearLayout trackLinearLayout;  
 
         protected override void OnCreate(Bundle bundle)  
         {  
             base.OnCreate(bundle);  
             SetContentView(Resource.Layout.Main);  
 
             WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay();  
 
             androidMap = FindViewById<MapView>(Resource.Id.androidmap);  
             androidMap.MapUnit = GeographyUnit.DecimalDegree;  
             androidMap.CurrentExtent = new RectangleShape(-180.0, 83.0, 180.0, -90.0);  
             androidMap.Overlays.Add(worldOverlay);  
 
             cursorButton = GetButton(Resource.Drawable.Cursor, TrackButtonClick);  
             drawButton = GetButton(Resource.Drawable.Draw, TrackButtonClick);  
             pointButton = GetButton(Resource.Drawable.Point, TrackButtonClick);  
             lineButton = GetButton(Resource.Drawable.Line, TrackButtonClick);  
             rectangleButton = GetButton(Resource.Drawable.Rectangle, TrackButtonClick);  
             circleButton = GetButton(Resource.Drawable.Circle, TrackButtonClick);  
             polygonButton = GetButton(Resource.Drawable.Polygon, TrackButtonClick);  
             ellipseButton = GetButton(Resource.Drawable.Ellipse, TrackButtonClick);  
             editButton = GetButton(Resource.Drawable.Edit, TrackButtonClick);  
             clearButton = GetButton(Resource.Drawable.Clear, TrackButtonClick);  
 
             trackLinearLayout = new LinearLayout(this);  
             trackLinearLayout.Orientation = Orientation.Horizontal;  
             trackLinearLayout.Visibility = ViewStates.Gone;  
             trackLinearLayout.AddView(pointButton);  
             trackLinearLayout.AddView(lineButton);  
             trackLinearLayout.AddView(rectangleButton);  
             trackLinearLayout.AddView(polygonButton);  
             trackLinearLayout.AddView(ellipseButton);  
 
             LinearLayout toolsLinearLayout = new LinearLayout(this);  
             toolsLinearLayout.AddView(cursorButton);  
             toolsLinearLayout.AddView(drawButton);  
             toolsLinearLayout.AddView(trackLinearLayout);  
             toolsLinearLayout.AddView(editButton);  
             toolsLinearLayout.AddView(clearButton);  
 
             InitializeInstruction(toolsLinearLayout);  
         }  
 
         private ImageButton GetButton(int imageResId, EventHandler handler)  
         {  
             ImageButton button = new ImageButton(this);  
             button.Id = imageResId;  
             button.SetImageResource(imageResId);  
             button.Click += handler;  
             button.SetBackgroundResource(Resource.Drawable.buttonbackground);  
             return button;  
         }  
 
         private IEnumerable<ImageButton> GetButtons()  
         {  
             yield return editButton;  
             yield return lineButton;  
             yield return pointButton;  
             yield return clearButton;  
             yield return cursorButton;  
             yield return circleButton;  
             yield return polygonButton;  
             yield return ellipseButton;  
             yield return rectangleButton;  
             yield return drawButton;  
         }  
 
         private void TrackButtonClick(object sender, EventArgs e)  
         {  
             ImageButton button = (ImageButton)sender;  
             foreach (ImageButton tempButton in GetButtons())  
             {  
                 tempButton.SetBackgroundResource(Resource.Drawable.buttonbackground);  
             }  
             button.SetBackgroundResource(Resource.Drawable.buttonselectedbackground);  
 
             switch (button.Id)  
             {  
                 case Resource.Drawable.Cursor:  
                     foreach (var item in androidMap.EditOverlay.EditShapesLayer.InternalFeatures)  
                     {  
                         if (!androidMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Contains(item))  
                         {  
                             androidMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Add(item);  
                         }  
                     }  
 
                     androidMap.TrackOverlay.TrackMode = TrackMode.None;  
                     androidMap.EditOverlay.EditShapesLayer.InternalFeatures.Clear();  
                     androidMap.EditOverlay.ClearAllControlPoints();  
                     trackLinearLayout.Visibility = ViewStates.Gone;  
                     drawButton.Visibility = ViewStates.Visible;  
                     editButton.Visibility = ViewStates.Visible;  
                     clearButton.Visibility = ViewStates.Visible;  
                     androidMap.Refresh();  
                     break;  
 
                 case Resource.Drawable.Clear:  
                     androidMap.EditOverlay.ClearAllControlPoints();  
                     androidMap.EditOverlay.EditShapesLayer.Open();  
                     androidMap.EditOverlay.EditShapesLayer.Clear();  
                     androidMap.TrackOverlay.TrackShapeLayer.Open();  
                     androidMap.TrackOverlay.TrackShapeLayer.Clear();  
                     androidMap.Refresh();  
                     break;  
 
                 case Resource.Drawable.Point:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Point;  
                     break;  
 
                 case Resource.Drawable.Line:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Line;  
                     break;  
 
                 case Resource.Drawable.Rectangle:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Rectangle;  
                     break;  
 
                 case Resource.Drawable.Polygon:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Polygon;  
                     break;  
 
                 case Resource.Drawable.Circle:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Circle;  
                     break;  
 
                 case Resource.Drawable.Ellipse:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Ellipse;  
                     break;  
 
                 case Resource.Drawable.Edit:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.None;  
                     foreach (Feature feature in androidMap.TrackOverlay.TrackShapeLayer.InternalFeatures)  
                     {  
                         androidMap.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);  
                     }  
                     androidMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();  
                     androidMap.EditOverlay.CalculateAllControlPoints();  
                     androidMap.Refresh();  
                     break;  
 
                 case Resource.Drawable.Draw:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.Point;  
                     trackLinearLayout.Visibility = ViewStates.Visible;  
                     drawButton.Visibility = ViewStates.Gone;  
                     editButton.Visibility = ViewStates.Gone;  
                     clearButton.Visibility = ViewStates.Gone;  
                     pointButton.SetBackgroundResource(Resource.Drawable.buttonselectedbackground);  
                     break;  
 
                 default:  
                     androidMap.TrackOverlay.TrackMode = TrackMode.None;  
                     break;  
             }  
         }  
 
         public void InitializeInstruction(params View[] contentViews)  
         {  
             contentHeight = 0;  
             ViewGroup containerView = FindViewById<RelativeLayout>(Resource.Id.MainLayout);  
 
             LayoutInflater inflater = LayoutInflater.From(this);  
             View instructionLayoutView = inflater.Inflate(Resource.Layout.Instruction, containerView);  
 
             TextView instructionTextView = instructionLayoutView.FindViewById<TextView>(Resource.Id.instructionTextView);  
             TextView descriptionTextView = instructionLayoutView.FindViewById<TextView>(Resource.Id.descriptionTextView);  
             descriptionTextView.Text = "Draw and Edit Shapes.";  
 
             LinearLayout instructionLayout = instructionLayoutView.FindViewById<LinearLayout>(Resource.Id.instructionLinearLayout);  
             LinearLayout contentLayout = instructionLayoutView.FindViewById<LinearLayout>(Resource.Id.contentLinearLayout);  
 
             RelativeLayout headerRelativeLayout = instructionLayoutView.FindViewById<RelativeLayout>(Resource.Id.headerRelativeLayout);  
 
             if (contentViews != null)  
             {  
                 foreach (View view in contentViews)  
                 {  
                     contentLayout.AddView(view);  
                 }  
             }  
 
             headerRelativeLayout.Click += (sender, e) =>  
             {  
                 contentHeight = contentHeight == 0 ? instructionLayout.Height - instructionTextView.Height : -contentHeight;  
                 instructionLayout.Layout(instructionLayout.Left, instructionLayout.Top + contentHeight, instructionLayout.Right, instructionLayout.Bottom);  
             };  
         }  
     }  
 }  
 
 
 

AssemblyInfo.cs

 using System.Reflection;  
 using System.Runtime.CompilerServices;  
 using System.Runtime.InteropServices;  
 using Android.App;  
 
 // General Information about an assembly is controlled through the following  
 // set of attributes. Change these attribute values to modify the information  
 // associated with an assembly.  
 [assembly: AssemblyTitle("DrawEditFeatures")]  
 [assembly: AssemblyDescription("")]  
 [assembly: AssemblyConfiguration("")]  
 [assembly: AssemblyCompany("")]  
 [assembly: AssemblyProduct("DrawEditFeatures")]  
 [assembly: AssemblyCopyright("Copyright ©  2014")]  
 [assembly: AssemblyTrademark("")]  
 [assembly: AssemblyCulture("")]  
 [assembly: ComVisible(false)]  
 
 // Version information for an assembly consists of the following four values:  
 //  
 //      Major Version  
 //      Minor Version  
 //      Build Number  
 //      Revision  
 //  
 // You can specify all the values or you can default the Build and Revision Numbers  
 // by using the '*' as shown below:  
 // [assembly: AssemblyVersion("1.0.*")]  
 [assembly: AssemblyVersion("1.0.0.0")]  
 [assembly: AssemblyFileVersion("1.0.0.0")]  
 
 

Resource.Designer.cs

 #pragma warning disable 1591  
 //------------------------------------------------------------------------------  
 // <auto-generated>  
 //     This code was generated by a tool.  
 //     Runtime Version:4.0.30319.0  
 //  
 //     Changes to this file may cause incorrect behavior and will be lost if  
 //     the code is regenerated.  
 // </auto-generated>  
 //------------------------------------------------------------------------------  
 
 [assembly: global::Android.Runtime.ResourceDesignerAttribute("DrawEditFeatures.Resource", IsApplication=true)]  
 
 namespace DrawEditFeatures  
 {  
 
 
 	[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks", "1.0.0.0")]  
 	public partial class Resource  
 	{  
 
 		static Resource()  
 		{  
 			global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 		}  
 
 		public static void UpdateIdValues()  
 		{  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_default256x256 = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_default256x256;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_default512x512 = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_default512x512;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_globe;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe_Pressed = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_globe_Pressed;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_Minus;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus_Pressed = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_Minus_Pressed;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_noImageTile = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_noImageTile;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_Plus;  
 			global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus_Pressed = global::DrawEditFeatures.Resource.Drawable.icon_mapsuite_Plus_Pressed;  
 		}  
 
 		public partial class Attribute  
 		{  
 
 			static Attribute()  
 			{  
 				global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 			}  
 
 			private Attribute()  
 			{  
 			}  
 		}  
 
 		public partial class Drawable  
 		{  
 
 			// aapt resource value: 0x7f020000  
 			public const int buttonbackground = 2130837504;  
 
 			// aapt resource value: 0x7f020001  
 			public const int buttonselectedbackground = 2130837505;  
 
 			// aapt resource value: 0x7f020002  
 			public const int Circle = 2130837506;  
 
 			// aapt resource value: 0x7f020003  
 			public const int Clear = 2130837507;  
 
 			// aapt resource value: 0x7f020004  
 			public const int Cursor = 2130837508;  
 
 			// aapt resource value: 0x7f020005  
 			public const int Draw = 2130837509;  
 
 			// aapt resource value: 0x7f020006  
 			public const int Edit = 2130837510;  
 
 			// aapt resource value: 0x7f020007  
 			public const int Ellipse = 2130837511;  
 
 			// aapt resource value: 0x7f020008  
 			public const int Icon = 2130837512;  
 
 			// aapt resource value: 0x7f020009  
 			public const int icon_mapsuite_default256x256 = 2130837513;  
 
 			// aapt resource value: 0x7f02000a  
 			public const int icon_mapsuite_default512x512 = 2130837514;  
 
 			// aapt resource value: 0x7f02000b  
 			public const int icon_mapsuite_globe = 2130837515;  
 
 			// aapt resource value: 0x7f02000c  
 			public const int icon_mapsuite_globe_Pressed = 2130837516;  
 
 			// aapt resource value: 0x7f02000d  
 			public const int icon_mapsuite_Minus = 2130837517;  
 
 			// aapt resource value: 0x7f02000e  
 			public const int icon_mapsuite_Minus_Pressed = 2130837518;  
 
 			// aapt resource value: 0x7f02000f  
 			public const int icon_mapsuite_noImageTile = 2130837519;  
 
 			// aapt resource value: 0x7f020010  
 			public const int icon_mapsuite_Plus = 2130837520;  
 
 			// aapt resource value: 0x7f020011  
 			public const int icon_mapsuite_Plus_Pressed = 2130837521;  
 
 			// aapt resource value: 0x7f020012  
 			public const int Line = 2130837522;  
 
 			// aapt resource value: 0x7f020013  
 			public const int Point = 2130837523;  
 
 			// aapt resource value: 0x7f020014  
 			public const int Polygon = 2130837524;  
 
 			// aapt resource value: 0x7f020015  
 			public const int Rectangle = 2130837525;  
 
 			static Drawable()  
 			{  
 				global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 			}  
 
 			private Drawable()  
 			{  
 			}  
 		}  
 
 		public partial class Id  
 		{  
 
 			// aapt resource value: 0x7f050006  
 			public const int MainLayout = 2131034118;  
 
 			// aapt resource value: 0x7f050007  
 			public const int androidmap = 2131034119;  
 
 			// aapt resource value: 0x7f050004  
 			public const int contentLinearLayout = 2131034116;  
 
 			// aapt resource value: 0x7f050003  
 			public const int contentRelativeLayout = 2131034115;  
 
 			// aapt resource value: 0x7f050005  
 			public const int descriptionTextView = 2131034117;  
 
 			// aapt resource value: 0x7f050001  
 			public const int headerRelativeLayout = 2131034113;  
 
 			// aapt resource value: 0x7f050000  
 			public const int instructionLinearLayout = 2131034112;  
 
 			// aapt resource value: 0x7f050002  
 			public const int instructionTextView = 2131034114;  
 
 			static Id()  
 			{  
 				global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 			}  
 
 			private Id()  
 			{  
 			}  
 		}  
 
 		public partial class Layout  
 		{  
 
 			// aapt resource value: 0x7f030000  
 			public const int Instruction = 2130903040;  
 
 			// aapt resource value: 0x7f030001  
 			public const int Main = 2130903041;  
 
 			static Layout()  
 			{  
 				global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 			}  
 
 			private Layout()  
 			{  
 			}  
 		}  
 
 		public partial class String  
 		{  
 
 			// aapt resource value: 0x7f040001  
 			public const int ApplicationName = 2130968577;  
 
 			// aapt resource value: 0x7f040000  
 			public const int Hello = 2130968576;  
 
 			static String()  
 			{  
 				global::Android.Runtime.ResourceIdManager.UpdateIdValues();  
 			}  
 
 			private String()  
 			{  
 			}  
 		}  
 	}  
 }  
 #pragma warning restore 1591