====== Source Code XamarinFormsEditionSample DrawEditFeatures.zip ======
====App.cs====
using Xamarin.Forms;
namespace DrawEditFeatures
{
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new NavigationPage(new MainPage());
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
}
====MainPage.xaml.cs====
using System;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.FormsEdition;
using Xamarin.Forms;
namespace DrawEditFeatures
{
public partial class MainPage : ContentPage
{
private MapView mapView;
private DrawEditMode drawEditMode;
private string trackEditMode;
private Command trackButtonCommand;
public MainPage()
{
InitializeComponent();
BindingContext = this;
mapView = new MapView();
mapView.MapUnit = GeographyUnit.Meter;
mapView.BackgroundColor = Color.FromRgb(244, 242, 238);
mapView.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
mainGrid.Children.Insert(0, mapView);
// Base overlay.
WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay();
worldOverlay.Projection = WorldMapKitProjection.SphericalMercator;
mapView.Overlays.Add("WMK", worldOverlay);
}
public Command TrackButtonCommand
{
get
{
trackButtonCommand = (trackButtonCommand ?? new Command(TrackButtonClick));
return trackButtonCommand;
}
}
public DrawEditMode DrawEditMode
{
get { return drawEditMode; }
set
{
if (drawEditMode != value)
{
drawEditMode = value;
OnPropertyChanged();
}
}
}
private void TrackButtonClick(string buttonType)
{
switch (buttonType)
{
case "Pan":
DrawEditMode = DrawEditMode.Pan;
mapView.TrackOverlay.TrackMode = TrackMode.None;
break;
case "Draw":
ChangeTrackMode();
break;
case "Edit":
DrawEditMode = DrawEditMode.Edit;
mapView.TrackOverlay.TrackMode = TrackMode.None;
foreach (Feature feature in mapView.TrackOverlay.TrackShapeLayer.InternalFeatures)
{
mapView.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);
}
mapView.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
mapView.EditOverlay.CalculateAllControlPoints();
mapView.EditOverlay.Refresh();
mapView.TrackOverlay.Refresh();
break;
case "Clear":
DrawEditMode = DrawEditMode.Clear;
mapView.EditOverlay.ClearAllControlPoints();
mapView.EditOverlay.EditShapesLayer.Open();
mapView.EditOverlay.EditShapesLayer.Clear();
mapView.TrackOverlay.TrackShapeLayer.Open();
mapView.TrackOverlay.TrackShapeLayer.Clear();
mapView.EditOverlay.Refresh();
mapView.TrackOverlay.Refresh();
break;
default:
mapView.TrackOverlay.TrackMode = TrackMode.None;
break;
}
}
private async void ChangeTrackMode()
{
var action = await DisplayActionSheet("Select track mode", "Cancel", null, "Point", "Line", "Rectangle", "Circle", "Polygon");
if (action.Equals("Cancel", StringComparison.OrdinalIgnoreCase)) return;
mapView.TrackOverlay.TrackMode = (TrackMode)Enum.Parse(typeof(TrackMode), action);
DrawEditMode = (DrawEditMode)Enum.Parse(typeof(DrawEditMode), action);
}
}
}
====DrawEditMode.cs====
namespace DrawEditFeatures
{
public enum DrawEditMode
{
Pan = 0,
Point = 1,
Line = 2,
Rectangle = 3,
Circle = 4,
Polygon = 5,
Draw = 6,
Edit = 7,
Clear = 8
}
}
====DrawEditModeToColorConverter.cs====
using System;
using Xamarin.Forms;
namespace DrawEditFeatures
{
public class DrawEditModeToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string operationParameter = (string)parameter;
if (value is DrawEditMode)
{
DrawEditMode operationMode = (DrawEditMode)value;
switch (operationMode)
{
case DrawEditMode.Point:
case DrawEditMode.Line:
case DrawEditMode.Rectangle:
case DrawEditMode.Circle:
case DrawEditMode.Polygon:
operationMode = DrawEditMode.Draw;
break;
}
if (operationParameter.Equals(operationMode.ToString(), StringComparison.OrdinalIgnoreCase))
{
return Color.White;
}
else
{
return Color.Transparent;
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
====DrawEditModeToNameConverter.cs====
using System;
using Xamarin.Forms;
namespace DrawEditFeatures
{
public class DrawEditModeToNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
string result = string.Empty;
if (value is DrawEditMode)
{
DrawEditMode operationMode = (DrawEditMode)value;
switch (operationMode)
{
case DrawEditMode.Point:
case DrawEditMode.Line:
case DrawEditMode.Rectangle:
case DrawEditMode.Circle:
case DrawEditMode.Polygon:
result = string.Format("Draw/Edit - Track - {0}", operationMode);
break;
default:
result = string.Format("Draw/Edit - {0}", operationMode);
break;
}
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
====AssemblyInfo.cs====
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 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 © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
// 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")]