User Tools

Site Tools


source_code_xamarinformseditionsample_analyzevisual.zip

Source Code XamarinFormsEditionSample AnalyzeVisual.zip

App.cs

 using System;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class App : Application  
     {  
         private MasterDetailPage mainPage;  
 
         public App()  
         {  
             InitializeStyles();  
 
             mainPage = new MasterDetailPage();  
             mainPage.IsGestureEnabled = false;  
             mainPage.Title = "Analyze Visual";  
 
             SampleListPage sampleListPage = new SampleListPage();  
             sampleListPage.SelectedSampleChanged += SampleListViewModel_SelectedSampleChanged;  
 
             sampleListPage.SelectedSample = sampleListPage.Samples[0];  
             mainPage.Master = sampleListPage;  
             MainPage = mainPage;  
 
         }  
 
         private void SampleListViewModel_SelectedSampleChanged(object sender, EventArgs e)  
         {  
             ContentPage contentPage = null;  
             SampleListPage sampleListViewModel = (SampleListPage)sender;  
             BaseSampleView newSample = (BaseSampleView)Activator.CreateInstance(sampleListViewModel.SelectedSample.SampleType);  
 
             if (mainPage.Detail == null)  
             {  
                 mainPage.Detail = new NavigationPage(new ContentPage());  
             }  
 
             NavigationPage navigationPage = (NavigationPage)mainPage.Detail;  
             contentPage = (ContentPage)navigationPage.CurrentPage;  
 
             BaseSampleView oldSample = contentPage.Content as BaseSampleView;  
             if (oldSample != null && !newSample.Equals(contentPage.Content))  
             {  
                 oldSample.Dispose();  
             }  
 
             contentPage.Title = sampleListViewModel.SelectedSample.Name;  
             contentPage.Content = newSample;  
             contentPage.ToolbarItems.Clear();  
             if (newSample.SampleToolbarItem != null) contentPage.ToolbarItems.Add(newSample.SampleToolbarItem);  
 
             mainPage.IsPresented = false;  
         }  
 
         private void InitializeStyles()  
         {  
             Application.Current.Resources = new ResourceDictionary();  
 
             Style headerStyle = new Style(typeof(ContentView));  
             headerStyle.Setters.Add(new Setter { Property = ContentView.PaddingProperty, Value = new Thickness(5, Device.OnPlatform(38, 5, 0), 5, 0) });  
             Application.Current.Resources.Add("ListHeaderStyle", headerStyle);  
 
             Style settingsContainerStyle = new Style(typeof(Grid));  
             settingsContainerStyle.Setters.Add(new Setter { Property = Grid.BackgroundColorProperty, Value = Color.FromHex("#efefef") });  
             settingsContainerStyle.Setters.Add(new Setter { Property = Grid.PaddingProperty, Value = new Thickness(0, 5, 0, 5) });  
             Application.Current.Resources.Add("SettingsContainerStyle", settingsContainerStyle);  
 
             Style settingsContentStyle = new Style(typeof(Grid));  
             settingsContentStyle.Setters.Add(new Setter { Property = Grid.BackgroundColorProperty, Value = Color.White });  
             settingsContentStyle.Setters.Add(new Setter { Property = Grid.PaddingProperty, Value = new Thickness(5) });  
             Application.Current.Resources.Add("SettingsContentStyle", settingsContentStyle);  
 
             Style settingsApplyButtonContainerStyle = new Style(typeof(ContentView));  
             settingsApplyButtonContainerStyle.Setters.Add(new Setter { Property = ContentView.PaddingProperty, Value = new Thickness(5, 20, 5, 5) });  
             Application.Current.Resources.Add("SettingsApplyButtonContainerStyle", settingsApplyButtonContainerStyle);  
 
             Style settingsListLabelStyle = new Style(typeof(Label));  
             settingsListLabelStyle.Setters.Add(new Setter { Property = Label.TextColorProperty, Value = Color.Black });  
             Application.Current.Resources.Add("SettingsListLabelStyle", settingsListLabelStyle);  
 
             Style settingsTitleStyle = new Style(typeof(Label));  
             settingsTitleStyle.Setters.Add(new Setter { Property = Label.TextColorProperty, Value = Color.Black });  
             settingsTitleStyle.Setters.Add(new Setter { Property = Label.FontSizeProperty, Value = 21 });  
             settingsTitleStyle.Setters.Add(new Setter { Property = Label.FontAttributesProperty, Value = FontAttributes.Bold });  
             Application.Current.Resources.Add("SettingsTitleStyle", settingsTitleStyle);  
 
             Style sampleApplyButtonStyle = new Style(typeof(Button));  
             sampleApplyButtonStyle.Setters.Add(new Setter { Property = Button.BackgroundColorProperty, Value = Color.FromHex("#e0e0e0") });  
             sampleApplyButtonStyle.Setters.Add(new Setter { Property = Button.TextColorProperty, Value = Color.FromHex("#000000") });  
             sampleApplyButtonStyle.Setters.Add(new Setter { Property = Button.TextProperty, Value = "Apply" });  
             Application.Current.Resources.Add("SampleApplyButtonStyle", sampleApplyButtonStyle);  
 
             Style settingsTitleContainerStyle = new Style(typeof(Grid));  
             settingsTitleContainerStyle.Setters.Add(new Setter { Property = Grid.PaddingProperty, Value = new Thickness(5) });  
             Application.Current.Resources.Add("SettingsListLineStyle", settingsTitleContainerStyle);  
         }  
     }  
 }  
 
 

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("AnalyzeVisual")]  
 [assembly: AssemblyDescription("")]  
 [assembly:|AssemblyConfiguration("")]  
 [assembly: AssemblyCompany("")]  
 [assembly:|AssemblyProduct("AnalyzeVisual")]  
 [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")]  
 
 

SampleListPage.xaml.cs

 
 using System;  
 using System.Collections.ObjectModel;  
 using System.Diagnostics;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public partial class SampleListPage : ContentPage  
     {  
         private SampleItem selectedSample;  
         private ObservableCollection<SampleItem> samples;  
         private Command openHelpUriCommand;  
 
         public event EventHandler SelectedSampleChanged;  
 
         public SampleListPage()  
         {  
             InitializeComponent();  
 
             samples = new ObservableCollection<SampleItem>();  
             samples.Add(new SampleItem("Cluster Style", "clusterstyle", typeof(ClusterPointStyleSample)));  
             samples.Add(new SampleItem("Custom Style", "customstyle", typeof(CustomStyleSample)));  
             samples.Add(new SampleItem("Filter Style", "filterstyle", typeof(FilterStyleSample)));  
             samples.Add(new SampleItem("Class Break Style", "classbreak", typeof(ClassBreakStyleSample)));  
             samples.Add(new SampleItem("Dot Density Style", "dotdensity", typeof(DotDensityStyleSample)));  
             samples.Add(new SampleItem("Isoline Line Style", "isoline", typeof(IsolineStyleSample)));  
             samples.Add(new SampleItem("Heat Style", "heatmap", typeof(HeatStyleSample)));  
             samples.Add(new SampleItem("Icon Style", "iconstyle", typeof(IconStyleSample)));  
 
             BindingContext = this;  
         }  
 
         public SampleItem SelectedSample  
         {  
             get  
             {  
                 return selectedSample;  
             }  
             set  
             {  
                 if (selectedSample != value)  
                 {  
                     selectedSample = value;  
                     OnPropertyChanged("SelectedSample");  
                     OnSelectedSampleChanged();  
                 }  
             }  
         }  
 
         public ObservableCollection<SampleItem> Samples  
         {  
             get { return samples; }  
         }  
 
         public Command OpenHelpUriCommand  
         {  
             get  
             {  
                 openHelpUriCommand = openHelpUriCommand ?? new Command(() => Device.OpenUri(new Uri("http://www.thinkgeo.com")));  
                 return openHelpUriCommand;  
             }  
         }  
 
         protected virtual void OnSelectedSampleChanged()  
         {  
             EventHandler handler = SelectedSampleChanged;  
             if (handler != null)  
             {  
                 handler(this, new EventArgs());  
             }  
         }  
     }  
 }  
 
 

BaseSampleView.cs

 using System;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public abstract class BaseSampleView : ContentView, IDisposable  
     {  
         private MapView mapView;  
 
         protected BaseSampleView()  
         {  
             mapView = new MapView();  
             mapView.MapUnit = GeographyUnit.DecimalDegree;  
             mapView.CurrentExtent = new RectangleShape(-30, 10, 10, -10);  
             mapView.BackgroundColor = Color.FromRgb(244, 242, 238);  
             Content = new Grid { Children = { mapView } };  
 
             WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay();  
             worldOverlay.Projection = WorldMapKitProjection.DecimalDegrees;  
             mapView.Overlays.Add("WMK", worldOverlay);  
             LoadMap();  
         }  
 
         public MapView MapView  
         {  
             get { return mapView; }  
         }  
 
         public virtual ToolbarItem SampleToolbarItem  
         {  
             get { return null; }  
         }  
 
         protected abstract void LoadMap();  
 
         ~BaseSampleView()  
         {  
             Dispose(false);  
         }  
 
         public void Dispose()  
         {  
             Dispose(true);  
             GC.SuppressFinalize(this);  
         }  
 
         protected virtual void Dispose(bool disposing)  
         {  
             if (disposing)  
             {  
                 mapView.Dispose();  
             }  
         }  
     }  
 }  
 
 

SampleItem.cs

 using System;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class SampleItem  
     {  
         private string name;  
         private ImageSource icon;  
         private Type sampleType;  
 
         public SampleItem(string name, string iconPathFilename, Type sampleType)  
         {  
             this.name = name;  
             this.sampleType = sampleType;  
             this.icon = new FileImageSource() { File = iconPathFilename };  
         }  
 
         public string Name  
         {  
             get { return name; }  
             set { name = value; }  
         }  
 
         public ImageSource Icon  
         {  
             get { return icon; }  
             set { icon = value; }  
         }  
 
         public Type SampleType  
         {  
             get { return sampleType; }  
             set { sampleType = value; }  
         }  
     }  
 }  
 
 

ClassBreakChartView.cs

 using ThinkGeo.MapSuite.Core;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class ClassBreakChartView : ContentView  
     {  
         public ClassBreakChartView(ClassBreakStyle style)  
         {  
             Padding = new Thickness(10, 0, 0, 10);  
 
             Grid grid = new Grid();  
             grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });  
             grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(3) });  
             grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });  
 
             for (int i = 0; i < style.ClassBreaks.Count; i++)  
             {  
                 ClassBreak item = style.ClassBreaks[i];  
                 grid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });  
 
                 BoxView boxView = new BoxView();  
                 GeoColor color = item.DefaultAreaStyle.FillSolidBrush.Color;  
                 boxView.Color = Color.FromRgba(color.RedComponent, color.GreenComponent, color.BlueComponent, color.AlphaComponent);  
                 boxView.WidthRequest = 80;  
                 boxView.HeightRequest = 25;  
 
                 Label valueLabel = new Label();  
                 valueLabel.TextColor = Color.Black;  
                 valueLabel.FontSize = 18;  
                 valueLabel.VerticalOptions = LayoutOptions.Center;  
                 valueLabel.Text = item.Value.ToString();  
 
                 grid.Children.Add(boxView, 0, i);  
                 grid.Children.Add(valueLabel, 2, i);  
             }  
 
             Frame frame = new Frame();  
             frame.Padding = new Thickness(8);  
             frame.BackgroundColor = Color.White;  
             frame.Content = grid;  
 
             this.Content = frame;  
         }  
     }  
 }  
 
 

ClassBreakStyleSample.cs

 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class ClassBreakStyleSample : BaseSampleView  
     {  
         private ClassBreakStyle classBreakStyle;  
 
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-128.455625, 88.474096875, -65.174375, -9.084496875);  
 
             ShapeFileFeatureLayer usLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("usStatesCensus2010.shp"));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(usLayer);  
             MapView.Overlays.Add(layerOverlay);  
 
             classBreakStyle = GetClassBreakStyle();  
             usLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle);  
             usLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             ClassBreakChartView chartView = new ClassBreakChartView(classBreakStyle);  
             chartView.HorizontalOptions = LayoutOptions.Start;  
             chartView.VerticalOptions = LayoutOptions.End;  
 
             Grid mainGrid = (Grid)Content;  
             mainGrid.Children.Add(chartView);  
         }  
 
 
         private static ClassBreakStyle GetClassBreakStyle()  
         {  
             double[] classBreakValues = { 0, 814180.0, 1328361.0, 2059179.0, 2967297.0, 4339367.0, 5303925.0, 6392017.0, 8791894.0 };  
 
             GeoColor outlineColor = GeoColor.FromHtml("#f05133");  
             GeoColor fromColor = GeoColor.FromArgb(255, 116, 160, 255);  
             GeoColor toColor = GeoColor.FromArgb(255, 220, 52, 56);  
             Collection<GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(fromColor, toColor, 10, ColorWheelDirection.CounterClockwise);  
             ClassBreakStyle style = new ClassBreakStyle("Population", BreakValueInclusion.IncludeValue);  
             for (int i = 0; i < classBreakValues.Length; i++)  
             {  
                 style.ClassBreaks.Add(new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(200, familyColors[i]), outlineColor, 1)));  
             }  
 
             return style;  
         }  
     }  
 }  
 
 

ClassBreakClusterPointStyle.cs

 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Globalization;  
 using System.Linq;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class ClassBreakClusterPointStyle : Style  
     {  
         private Dictionary<int, PointStyle> classBreakPoint;  
         private int cellSize = 100;  
         private TextStyle textSytle = new TextStyle();  
 
         public ClassBreakClusterPointStyle()  
             : base()  
         {  
             classBreakPoint = new Dictionary<int, PointStyle>();  
         }  
 
         public Dictionary<int, PointStyle> ClassBreakPoint  
         {  
             get { return classBreakPoint; }  
         }  
 
         public TextStyle TextStyle  
         {  
             get { return textSytle; }  
             set { textSytle = value; }  
         }  
 
         public int CellSize  
         {  
             get { return cellSize; }  
             set { cellSize = value; }  
         }  
 
         protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             double scale = ExtentHelper.GetScale(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);  
             MapSuiteTileMatrix mapSuiteTileMatrix = new MapSuiteTileMatrix(scale, cellSize, cellSize, canvas.MapUnit);  
             IEnumerable<TileMatrixCell> tileMatricCells = mapSuiteTileMatrix.GetContainedCells(canvas.CurrentWorldExtent);  
             Dictionary<string, string> unusedFeatures = new Dictionary<string, string>();  
 
             foreach (Feature feature in features)  
             {  
                 if (feature.GetWellKnownType() != WellKnownType.Point && feature.GetWellKnownType() != WellKnownType.Multipoint)  
                 {  
                     continue;  
                 }  
                 unusedFeatures.Add(feature.Id, feature.Id);  
             }  
 
             foreach (TileMatrixCell cell in tileMatricCells)  
             {  
                 int featureCount = 0;  
                 MultipointShape tempMultiPointShape = new MultipointShape();  
                 foreach (Feature feature in features)  
                 {  
                     // Make sure the feature has not been used in another cluster  
                     if (unusedFeatures.ContainsKey(feature.Id))  
                     {  
                         // Check if the cell contains the feature  
                         if (cell.BoundingBox.Contains(feature.GetBoundingBox()))  
                         {  
                             featureCount++;  
                             unusedFeatures.Remove(feature.Id);  
                             if (feature.GetWellKnownType() == WellKnownType.Multipoint)  
                             {  
                                 MultipointShape multipointShape = feature.GetShape() as MultipointShape;  
                                 foreach (var item in multipointShape.Points)  
                                 {  
                                     tempMultiPointShape.Points.Add(item);  
                                 }  
                             }  
                             else  
                             {  
                                 tempMultiPointShape.Points.Add(feature.GetShape() as PointShape);  
                             }  
                         }  
                     }  
                 }  
                 if (featureCount > 0)  
                 {  
                     // Add the feature count to the new feature we created.  The feature will be placed  
                     // at the center of gravity of all the clustered features of the cell we created.  
                     Dictionary<string, string> featureValues = new Dictionary<string, string>();  
                     featureValues.Add("FeatureCount", featureCount.ToString(CultureInfo.InvariantCulture));  
 
                     bool isMatch = false;  
                     Feature[] resultFeatures = new Feature[] { new Feature(tempMultiPointShape.GetCenterPoint(), featureValues) };  
                     for (int i = 0; i < classBreakPoint.Count - 1; i++)  
                     {  
                         var startItem = classBreakPoint.ElementAt(i);  
                         var endItem = classBreakPoint.ElementAt(i + 1);  
                         if (featureCount >= startItem.Key && featureCount < endItem.Key)  
                         {  
                             //Draw the point shape  
                             startItem.Value.Draw(resultFeatures, canvas, labelsInThisLayer, labelsInAllLayers);  
                             isMatch = true;  
                             break;  
                         }  
                     }  
                     if (!isMatch && featureCount >= classBreakPoint.LastOrDefault().Key)  
                     {  
                         classBreakPoint.LastOrDefault().Value.Draw(resultFeatures, canvas, labelsInThisLayer, labelsInAllLayers);  
                     }  
 
                     if (featureCount != 1)  
                     {  
                         // Draw the text style to show how many feaures are consolidated in the cluster  
                         textSytle.Draw(resultFeatures, canvas, labelsInThisLayer, labelsInAllLayers);  
                     }  
                 }  
             }  
         }  
     }  
 }  
 

ClusterPointStyleSample.cs

 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 
 namespace AnalyzeVisual  
 {  
     public class ClusterPointStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-128.455625, 88.474096875, -65.174375, -9.084496875);  
 
             ShapeFileFeatureLayer clusterPointStyleFeatureLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("usEarthquake.shp"));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(clusterPointStyleFeatureLayer);  
             MapView.Overlays.Add(layerOverlay);  
 
             clusterPointStyleFeatureLayer.DrawingMarginPercentage = 100;  
             clusterPointStyleFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();  
             clusterPointStyleFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(GetClusterPointStyle());  
             clusterPointStyleFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
 
         private static ClassBreakClusterPointStyle GetClusterPointStyle()  
         {  
             ClassBreakClusterPointStyle clusterPointStyle = new ClassBreakClusterPointStyle();  
             clusterPointStyle.CellSize = 65;  
 
             PointStyle pointStyle1 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 222, 226, 153)), new GeoPen(GeoColor.FromArgb(100, 222, 226, 153), 5), 8);  
             clusterPointStyle.ClassBreakPoint.Add(1, pointStyle1);  
 
             PointStyle pointStyle2 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 222, 226, 153)), new GeoPen(GeoColor.FromArgb(100, 222, 226, 153), 8), 15);  
             clusterPointStyle.ClassBreakPoint.Add(2, pointStyle2);  
 
             PointStyle pointStyle3 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 255, 183, 76)), new GeoPen(GeoColor.FromArgb(100, 255, 183, 76), 10), 25);  
             clusterPointStyle.ClassBreakPoint.Add(50, pointStyle3);  
 
             PointStyle pointStyle4 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 243, 193, 26)), new GeoPen(GeoColor.FromArgb(100, 243, 193, 26), 15), 35);  
             clusterPointStyle.ClassBreakPoint.Add(150, pointStyle4);  
 
             PointStyle pointStyle5 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 245, 7, 10)), new GeoPen(GeoColor.FromArgb(100, 245, 7, 10), 15), 40);  
             clusterPointStyle.ClassBreakPoint.Add(350, pointStyle5);  
 
             PointStyle pointStyle6 = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(250, 245, 7, 10)), new GeoPen(GeoColor.FromArgb(100, 245, 7, 10), 20), 50);  
             clusterPointStyle.ClassBreakPoint.Add(500, pointStyle6);  
 
             clusterPointStyle.TextStyle = TextStyles.CreateSimpleTextStyle("FeatureCount", "Arail", 10, DrawingFontStyles.Regular, GeoColor.SimpleColors.Black);  
             clusterPointStyle.TextStyle.PointPlacement = PointPlacement.Center;  
             return clusterPointStyle;  
         }  
     }  
 }  
 
 

CustomGeoImageLineStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Linq;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class CustomGeoImageLineStyle : LineStyle  
     {  
         private Collection<GeoImage> geoImages;  
         private int spacing;  
         private LineStyle lineStyle;  
         private SymbolSide side;  
 
         public CustomGeoImageLineStyle(LineStyle lineStyle, GeoImage geoImage, int spacing, SymbolSide side)  
             : this(lineStyle, new Collection<GeoImage> { geoImage }, spacing, side)  
         { }  
 
         public CustomGeoImageLineStyle(LineStyle lineStyle, IEnumerable<GeoImage> geoImages, int spacing, SymbolSide side)  
         {  
             this.side = side;  
             this.spacing = spacing;  
             this.lineStyle = lineStyle;  
             this.geoImages = new Collection<GeoImage>();  
             foreach (var geoImage in geoImages)  
             {  
                 this.geoImages.Add(geoImage);  
             }  
         }  
 
         protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             PointStyle[] pointStyles = geoImages.Select(geoImage => { return new PointStyle(geoImage) { DrawingLevel = DrawingLevel.LevelThree }; }).ToArray();  
             foreach (Feature feature in features)  
             {  
                 LineShape lineShape = (LineShape)feature.GetShape();  
                 lineStyle.Draw(new BaseShape[] { lineShape }, canvas, labelsInThisLayer, labelsInAllLayers);  
 
                 int index = 0;  
                 double totalDist = 0;  
                 for (int i = 0; i < lineShape.Vertices.Count - 1; i++)  
                 {  
                     PointShape pointShape1 = new PointShape(lineShape.Vertices[i]);  
                     PointShape pointShape2 = new PointShape(lineShape.Vertices[i|+ 1]);  
 
                     LineShape tempLineShape = new LineShape();  
                     tempLineShape.Vertices.Add(lineShape.Vertices[i]);  
                     tempLineShape.Vertices.Add(lineShape.Vertices[i|+ 1]);  
 
                     double angle = GetAngleFromTwoVertices(lineShape.Vertices[i], lineShape.Vertices[i|+ 1]);  
 
                     //Left side  
                     if (side == SymbolSide.Left)  
                     {  
                         if (angle >= 270) { angle = angle - 180; }  
                     }  
                     //Right side  
                     else  
                     {  
                         if (angle <= 90) { angle = angle + 180; }  
                     }  
                     //pointStyle.RotationAngle = (float)angle;  
                     foreach (var pointStyle in pointStyles) pointStyle.RotationAngle = (float)angle;  
                     float screenDist = ExtentHelper.GetScreenDistanceBetweenTwoWorldPoints(canvas.CurrentWorldExtent, pointShape1,  
                                                                                         pointShape2, canvas.Width, canvas.Height);  
                     double currentDist = Math.Round(pointShape1.GetDistanceTo(pointShape2, canvas.MapUnit, DistanceUnit.Meter), 2);  
                     double worldInterval = (currentDist * spacing) / screenDist;  
 
                     while (totalDist <= currentDist)  
                     {  
                         PointStyle pointStyle = pointStyles[index|% pointStyles.Length];  
                         PointShape tempPointShape = tempLineShape.GetPointOnALine(StartingPoint.FirstPoint, totalDist, canvas.MapUnit, DistanceUnit.Meter);  
                         pointStyle.Draw(new BaseShape[] { tempPointShape }, canvas, labelsInThisLayer, labelsInAllLayers);  
                         totalDist = totalDist + worldInterval;  
                         index++;  
                     }  
 
                     totalDist = totalDist - currentDist;  
                 }  
             }  
         }  
 
         private double GetAngleFromTwoVertices(Vertex b, Vertex c)  
         {  
             double alpha = 0;  
             double tangentAlpha = (c.Y - b.Y) / (c.X - b.X);  
             double Peta = Math.Atan(tangentAlpha);  
 
             if (c.X > b.X)  
             {  
                 alpha = 90 + (Peta * (180 / Math.PI));  
             }  
             else if (c.X < b.X)  
             {  
                 alpha = 270 + (Peta * (180 / Math.PI));  
             }  
             else  
             {  
                 if (c.Y > b.Y) alpha = 0;  
                 if (c.Y < b.Y) alpha = 180;  
             }  
 
             double offset;  
             if (b.X > c.X)  
             { offset = 90; }  
             else { offset = -90; }  
 
             return alpha + offset;  
         }  
 
         public enum SymbolSide  
         {  
             Right = 0,  
             Left = 1  
         }  
     }  
 }  
 

CustomStyleSample.cs

 using System;  
 using System.Collections.ObjectModel;  
 using System.Globalization;  
 using System.Linq;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class CustomStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             IPlatformService service = DependencyService.Get<IPlatformService>();  
 
             MapView.MapUnit = GeographyUnit.Meter;  
             MapView.CurrentExtent = new RectangleShape(-13886070, 6660597, -8906057, 3382985);  
 
             WorldMapKitOverlay worldOverlay = (WorldMapKitOverlay)MapView.Overlays["WMK"];  
             worldOverlay.Projection = WorldMapKitProjection.SphericalMercator;  
 
             LineStyle lineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(255, 50, 0, 249), 4, false);  
 
             //Cold Front  
             CustomGeoImageLineStyle coldFrontLineStyle = GetCustomLineStyle(lineStyle, 19, CustomGeoImageLineStyle.SymbolSide.Right,  
                 SampleHelper.GetDataPath(@"CustomStyles/offset_circle_red_bl.png"), SampleHelper.GetDataPath(@"CustomStyles/offset_triangle_blue_revert.png"));  
 
             InMemoryFeatureLayer inMemoryFeatureLayerColdFront = new InMemoryFeatureLayer();  
             inMemoryFeatureLayerColdFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(coldFrontLineStyle);  
             inMemoryFeatureLayerColdFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             inMemoryFeatureLayerColdFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/ColdFront2.txt"))));  
             inMemoryFeatureLayerColdFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/ColdFront3.txt"))));  
 
             //Warm Front  
             InMemoryFeatureLayer inMemoryFeatureLayerWarmFront = new InMemoryFeatureLayer();  
             CustomGeoImageLineStyle warmFrontLineStyle = new CustomGeoImageLineStyle(lineStyle, new GeoImage(SampleHelper.GetDataPath(@"CustomStyles/offset_circle_blue.png")),  
                                                                                                     30, CustomGeoImageLineStyle.SymbolSide.Right);  
             inMemoryFeatureLayerWarmFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(warmFrontLineStyle);  
             inMemoryFeatureLayerWarmFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/WarmFront5.txt"))));  
             inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/WarmFront6.txt"))));  
             inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/WarmFront7.txt"))));  
             inMemoryFeatureLayerWarmFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/WarmFront8.txt"))));  
 
             //Occluded Front  
             InMemoryFeatureLayer inMemoryFeatureLayerOccludedFront = new InMemoryFeatureLayer();  
             CustomGeoImageLineStyle occludedFrontLineStyle = GetCustomLineStyle(lineStyle, 45, CustomGeoImageLineStyle.SymbolSide.Right,  
                 SampleHelper.GetDataPath(@"CustomStyles/offset_triangle_and_circle_blue.png"), SampleHelper.GetDataPath(@"CustomStyles/offset_triangle_and_circle_red.png"));  
             inMemoryFeatureLayerOccludedFront.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(occludedFrontLineStyle);  
             inMemoryFeatureLayerOccludedFront.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/OccludedFront9.txt"))));  
             inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/OccludedFront10.txt"))));  
             inMemoryFeatureLayerOccludedFront.InternalFeatures.Add(new Feature(service.ReadAllText(SampleHelper.GetDataPath(@"CustomStyles/OccludedFront11.txt"))));  
 
             PressureValueStyle pressureValueStyle = new PressureValueStyle();  
             pressureValueStyle.ColumnName = "Pressure";  
 
             InMemoryFeatureLayer pressureFeatureLayer = new InMemoryFeatureLayer();  
             pressureFeatureLayer.Open();  
             pressureFeatureLayer.Columns.Add(new FeatureSourceColumn("Pressure"));  
             pressureFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(pressureValueStyle);  
             pressureFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             pressureFeatureLayer.InternalFeatures.Add(new Feature(MapView.CurrentExtent.GetCenterPoint()));  
 
             Random random = new Random();  
             string[] pressures = { "H", "L" };  
             for (int i = 0; i < 20; i++)  
             {  
                 Feature pressurePoint = new Feature(random.Next(-13886070, -8906057), random.Next(3382985, 6660597));  
                 pressurePoint.ColumnValues["Pressure"] = pressures[random.Next(0,|2)];  
                 pressureFeatureLayer.InternalFeatures.Add(pressurePoint);  
             }  
 
             WindPointStyle windStyle1 = new WindPointStyle("TEXT", "LEVEL", "ANGLE", GeoColor.FromHtml("#0AF8F8"));  
             WindPointStyle windStyle2 = new WindPointStyle("TEXT", "LEVEL", "ANGLE", GeoColor.FromHtml("#0FF5B0"));  
             WindPointStyle windStyle3 = new WindPointStyle("TEXT", "LEVEL", "ANGLE", GeoColor.FromHtml("#F7F70D"));  
             WindPointStyle windStyle4 = new WindPointStyle("TEXT", "LEVEL", "ANGLE", GeoColor.FromHtml("#FBE306"));  
 
             ClassBreakStyle windClassBreakStyle = new ClassBreakStyle();  
             windClassBreakStyle.ColumnName = "TEXT";  
             windClassBreakStyle.ClassBreaks.Add(new ClassBreak(10, new Collection<ThinkGeo.MapSuite.Core.Style> { windStyle1 }));  
             windClassBreakStyle.ClassBreaks.Add(new ClassBreak(20, new Collection<ThinkGeo.MapSuite.Core.Style> { windStyle2 }));  
             windClassBreakStyle.ClassBreaks.Add(new ClassBreak(30, new Collection<ThinkGeo.MapSuite.Core.Style> { windStyle3 }));  
             windClassBreakStyle.ClassBreaks.Add(new ClassBreak(40, new Collection<ThinkGeo.MapSuite.Core.Style> { windStyle4 }));  
 
             InMemoryFeatureLayer windFeatureLayer = new InMemoryFeatureLayer();  
             windFeatureLayer.Open();  
             windFeatureLayer.Columns.Add(new FeatureSourceColumn("TEXT"));  
             windFeatureLayer.Columns.Add(new FeatureSourceColumn("ANGLE"));  
             windFeatureLayer.Columns.Add(new FeatureSourceColumn("LEVEL"));  
             windFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(windClassBreakStyle);  
             windFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             for (int i = 0; i < 20; i++)  
             {  
                 Feature windFeature = new Feature(random.Next(-13886070, -8906057), random.Next(3382985, 6660597));  
                 windFeature.ColumnValues["TEXT"] = random.Next(10, 40).ToString(CultureInfo.InvariantCulture);  
                 windFeature.ColumnValues["ANGLE"] = random.Next(0, 360).ToString(CultureInfo.InvariantCulture);  
                 windFeature.ColumnValues["LEVEL"] = random.Next(0, 5).ToString(CultureInfo.InvariantCulture);  
                 windFeatureLayer.InternalFeatures.Add(windFeature);  
             }  
 
             LayerOverlay dynamicOverlay = new LayerOverlay();  
             dynamicOverlay.Layers.Add(inMemoryFeatureLayerColdFront);  
             dynamicOverlay.Layers.Add(inMemoryFeatureLayerWarmFront);  
             dynamicOverlay.Layers.Add(inMemoryFeatureLayerOccludedFront);  
             dynamicOverlay.Layers.Add(pressureFeatureLayer);  
             dynamicOverlay.Layers.Add(windFeatureLayer);  
             MapView.Overlays.Add(dynamicOverlay);  
         }  
 
         private static CustomGeoImageLineStyle GetCustomLineStyle(LineStyle lineStyle, int space, CustomGeoImageLineStyle.SymbolSide symbolSide, params string[] imagePaths)  
         {  
             return new CustomGeoImageLineStyle(lineStyle, imagePaths.Select(p => new GeoImage(p)), space, symbolSide);  
         }  
     }  
 }  
 
 

PressureValueStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class PressureValueStyle : ValueStyle  
     {  
         public PressureValueStyle()  
         {  
             SquareTextPointStyle highPressurePointStyle = new SquareTextPointStyle();  
             highPressurePointStyle.Text = "H";  
             highPressurePointStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 39, 39, 245));  
 
             SquareTextPointStyle lowPressurePointStyle = new SquareTextPointStyle();  
             lowPressurePointStyle.Text = "L";  
             lowPressurePointStyle.SymbolSolidBrush = new GeoSolidBrush(GeoColor.StandardColors.Red);  
 
             ValueItems.Add(new ValueItem("L", lowPressurePointStyle));  
             ValueItems.Add(new ValueItem("H", highPressurePointStyle));  
         }  
 
         private class SquareTextPointStyle : PointStyle  
         {  
             private string text;  
             private GeoFont font;  
             private GeoSolidBrush textBrush;  
 
             public SquareTextPointStyle()  
             {  
                 SymbolSize = 30;  
                 PointType = PointType.Symbol;  
                 font = new GeoFont("Verdana", 14);  
                 SymbolType = PointSymbolType.Square;  
                 textBrush = new GeoSolidBrush(GeoColor.StandardColors.White);  
                 SymbolPen = new GeoPen(GeoColor.StandardColors.White, 1);  
             }  
 
             public string Text  
             {  
                 set { text = value; }  
             }  
 
             protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
             {  
                 double resolution = Math.Max(canvas.CurrentWorldExtent.Width / canvas.Width, canvas.CurrentWorldExtent.Height / canvas.Height);  
                 foreach (Feature feature in features)  
                 {  
                     PointShape pointShape = feature.GetShape() as PointShape;  
                     if (pointShape != null)  
                     {  
                         float screenOffsetX = (float)((pointShape.X - canvas.CurrentWorldExtent.UpperLeftPoint.X) / resolution);  
                         float screenOffsetY = (float)((canvas.CurrentWorldExtent.UpperLeftPoint.Y - pointShape.Y) / resolution);  
                         canvas.DrawTextWithScreenCoordinate(text, font, textBrush, screenOffsetX, screenOffsetY, DrawingLevel.LabelLevel);  
                     }  
                 }  
             }  
         }  
     }  
 }  
 

WindPointStyle.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class WindPointStyle : Style  
     {  
         private string textColumn;  
         private string angleColumn;  
         private string windLevelColumn;  
         private GeoFont font;  
         private GeoBrush textBrush;  
         private GeoSolidBrush fillBrush;  
         private GeoSolidBrush blackBrush;  
         private float directionLineLength1;  
         private float directionLineLength2;  
         private GeoPen outlinePen;  
         private GeoPen innerlinePen;  
 
         public WindPointStyle()  
             : this(string.Empty, string.Empty, string.Empty, GeoColor.StandardColors.Orange)  
         { }  
 
         public WindPointStyle(string textColumn, string levelColumn, string angleColumn, GeoColor fillColor)  
         {  
             directionLineLength1 = 40;  
             directionLineLength2 = 10;  
             blackBrush = new GeoSolidBrush(GeoColor.SimpleColors.Black);  
             font = new GeoFont("Verdana", 14);  
             textBrush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
             fillBrush = new GeoSolidBrush(fillColor);  
             outlinePen = new GeoPen(GeoColor.StandardColors.Black, 4);  
             innerlinePen = new GeoPen(fillBrush, 2);  
             windLevelColumn = levelColumn;  
 
             this.textColumn = textColumn;  
             this.angleColumn = angleColumn;  
         }  
 
         protected override Collection<string> GetRequiredColumnNamesCore()  
         {  
             return new Collection<string> { textColumn, angleColumn, windLevelColumn };  
         }  
 
         protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             double resolution = Math.Max(canvas.CurrentWorldExtent.Width / canvas.Width, canvas.CurrentWorldExtent.Height / canvas.Height);  
             foreach (var feature in features)  
             {  
                 PointShape pointShape = feature.GetShape() as PointShape;  
                 if (pointShape != null)  
                 {  
                     float screenOffsetX = (float)((pointShape.X - canvas.CurrentWorldExtent.UpperLeftPoint.X) / resolution);  
                     float screenOffsetY = (float)((canvas.CurrentWorldExtent.UpperLeftPoint.Y - pointShape.Y) / resolution);  
                     string angle = feature.ColumnValues[angleColumn];  
                     string level = feature.ColumnValues[windLevelColumn];  
                     int windLevel = int.Parse(level);  
 
                     ScreenPointF[] directionLine = null;  
                     ScreenPointF[] levelLine1 = null;  
                     ScreenPointF[] levelLine2 = null;  
 
                     if (!string.IsNullOrEmpty(angle))  
                     {  
                         double radian1 = double.Parse(angle) * Math.PI / 180;  
                         float x1 = (float)(directionLineLength1 * Math.Cos(radian1));  
                         float y1 = (float)(directionLineLength1 * Math.Sin(radian1));  
 
                         double radian2 = (double.Parse(angle) - 90) * Math.PI / 180;  
                         float x2 = (float)(directionLineLength2 * Math.Cos(radian2));  
                         float y2 = (float)(directionLineLength2 * Math.Sin(radian2));  
 
                         float x3 = (float)((directionLineLength1 - 8) * Math.Cos(radian1));  
                         float y3 = (float)((directionLineLength1 - 8) * Math.Sin(radian1));  
 
                         float x4 = (float)(directionLineLength2 * Math.Cos(radian2));  
                         float y4 = (float)(directionLineLength2 * Math.Sin(radian2));  
 
                         if (windLevel >= 1)  
                         {  
                             directionLine = new ScreenPointF[2];  
                             directionLine[0] = new ScreenPointF(screenOffsetX, screenOffsetY);  
                             directionLine[1] = new ScreenPointF(screenOffsetX + x1, screenOffsetY + y1);  
                         }  
 
                         if (windLevel >= 2)  
                         {  
                             levelLine1 = new ScreenPointF[2];  
                             levelLine1[0] = new ScreenPointF(screenOffsetX + x1, screenOffsetY + y1);  
                             levelLine1[1] = new ScreenPointF(screenOffsetX + x1 + x2, screenOffsetY + y1 + y2);  
                         }  
 
                         if (windLevel >= 3)  
                         {  
                             levelLine2 = new ScreenPointF[2];  
                             levelLine2[0] = new ScreenPointF(screenOffsetX + x3, screenOffsetY + y3);  
                             levelLine2[1] = new ScreenPointF(screenOffsetX + x3 + x4, screenOffsetY + y3 + y4);  
                         }  
                     }  
 
                     // draw back  
                     canvas.DrawEllipse(feature, 26, 26, blackBrush, DrawingLevel.LevelOne);  
                     if (directionLine != null)  
                     {  
                         canvas.DrawLine(directionLine, outlinePen, DrawingLevel.LevelOne, 0, 0);  
                     }  
 
                     if (levelLine1 != null)  
                     {  
                         canvas.DrawLine(levelLine1, outlinePen, DrawingLevel.LevelOne, 0, 0);  
                     }  
 
                     if (levelLine2 != null)  
                     {  
                         canvas.DrawLine(levelLine2, outlinePen, DrawingLevel.LevelOne, 0, 0);  
                     }  
 
                     //draw fore  
                     canvas.DrawEllipse(feature, 24, 24, fillBrush, DrawingLevel.LevelTwo);  
                     if (directionLine != null)  
                     {  
                         canvas.DrawLine(directionLine, innerlinePen, DrawingLevel.LevelTwo, 0, 0);  
                     }  
 
                     if (levelLine1 != null)  
                     {  
                         canvas.DrawLine(levelLine1, innerlinePen, DrawingLevel.LevelTwo, 0, 0);  
                     }  
 
                     if (levelLine2 != null)  
                     {  
                         canvas.DrawLine(levelLine2, innerlinePen, DrawingLevel.LevelTwo, 0, 0);  
                     }  
 
                     string text = feature.ColumnValues[textColumn];  
                     if (!string.IsNullOrEmpty(text))  
                     {  
                         canvas.DrawTextWithScreenCoordinate(text, font, textBrush, screenOffsetX, screenOffsetY, DrawingLevel.LabelLevel);  
                     }  
                 }  
             }  
         }  
     }  
 }  
 

DotDensityStyleSample.cs

 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 
 namespace AnalyzeVisual  
 {  
     public class DotDensityStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-128.455625, 88.474096875, -65.174375, -9.084496875);  
 
             ShapeFileFeatureLayer usLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("usStatesCensus2010.shp"));  
             usLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new AreaStyle(new GeoPen(new GeoSolidBrush(GeoColor.SimpleColors.Black))));  
 
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add("USStatus", usLayer);  
             MapView.Overlays.Add("LayerOverlay", layerOverlay);  
 
             double pointToValueRatio = 0.0000094778167166538189;  
             PointStyle pointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Black, 7);  
             DotDensityStyle dotDensityStyle = new DotDensityStyle("Population", pointToValueRatio, pointStyle);  
             dotDensityStyle.CustomPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromHtml("#a57431"), 5);  
 
             usLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(dotDensityStyle);  
             usLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
     }  
 }  
 
 

FilterConditionValues.cs

 using System;  
 using System.Collections.Generic;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class FilterConditionValues : Dictionary<SimpleFilterConditionType, Tuple<string, string>>  
     {  
         public FilterConditionValues()  
         {  
             Add(SimpleFilterConditionType.Equal, "STATE_NAME", "Texas");  
             Add(SimpleFilterConditionType.Contains, "STATE_NAME", "T");  
             Add(SimpleFilterConditionType.StartsWith, "STATE_NAME", "T");  
             Add(SimpleFilterConditionType.EndsWith, "STATE_NAME", "a");  
             Add(SimpleFilterConditionType.DoesNotEqual, "STATE_NAME", "Texas");  
             Add(SimpleFilterConditionType.DoesNotContain, "STATE_NAME", "Te");  
             Add(SimpleFilterConditionType.GreaterThan, "POP1990", "1100000");  
             Add(SimpleFilterConditionType.GreaterThanOrEqualTo, "POP1990", "1003464");  
             Add(SimpleFilterConditionType.LessThan, "POP1990", "1003464");  
             Add(SimpleFilterConditionType.LessThanOrEqualTo, "POP1990", "1003464");  
             Add(SimpleFilterConditionType.IsEmpty, "STATE_NAME", string.Empty);  
             Add(SimpleFilterConditionType.IsNotEmpty, "STATE_NAME", string.Empty);  
         }  
 
         public void Add(SimpleFilterConditionType conditionType, string columnName, string matchValue)  
         {  
             Add(conditionType, new Tuple<string, string>(columnName, matchValue));  
         }  
     }  
 }  
 
 

FilterStyleSample.cs

 using System;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class FilterStyleSample : BaseSampleView  
     {  
         private FilterStyle filterStyle;  
         private FilterStyleSettingsPage settingsPage;  
         private ToolbarItem sampleToolbarItem;  
 
         protected override void LoadMap()  
         {  
             settingsPage = new FilterStyleSettingsPage();  
             settingsPage.ApplyingSettings += settingsPage_ApplyingSettings;  
 
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-128.455625, 88.474096875, -65.174375, -9.084496875);  
 
             ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("states.shp"));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(statesLayer);  
             MapView.Overlays.Add("LayerOverlay", layerOverlay);  
 
             filterStyle = new FilterStyle();  
             SimpleFilterCondition newCondition = new SimpleFilterCondition("STATE_NAME", SimpleFilterConditionType.Equal, "Texas");  
             filterStyle.Conditions.Add(newCondition);  
 
             GeoColor fillColor = GeoColor.FromArgb(130, GeoColor.FromHtml("#ffb74c"));  
             GeoColor outlineColor = GeoColor.FromHtml("#333333");  
             filterStyle.Styles.Add(AreaStyles.CreateSimpleAreaStyle(fillColor, outlineColor));  
             statesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(filterStyle);  
             statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
 
         public override ToolbarItem SampleToolbarItem  
         {  
             get  
             {  
                 return sampleToolbarItem ?? (sampleToolbarItem = new ToolbarItem("Settings", "settings40", () => Navigation.PushAsync(settingsPage)));  
             }  
         }  
 
         protected override void Dispose(bool disposing)  
         {  
             base.Dispose(disposing);  
 
             if (disposing) settingsPage.ApplyingSettings -= settingsPage_ApplyingSettings;  
         }  
 
         private void settingsPage_ApplyingSettings(object sender, EventArgs e)  
         {  
             filterStyle.Conditions.Clear();  
             SimpleFilterCondition newCondition = new SimpleFilterCondition(settingsPage.ColumnName, settingsPage.SelectedConditionType, settingsPage.SettingsValue);  
             filterStyle.Conditions.Add(newCondition);  
             MapView.Overlays["LayerOverlay"].Refresh();  
         }  
     }  
 }  
 
 

FilterStyleSettingsPage.xaml.cs

 using System;  
 using ThinkGeo.MapSuite.Core;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public partial class FilterStyleSettingsPage : ContentPage  
     {  
         public event EventHandler ApplyingSettings;  
 
         private SimpleFilterConditionType selectedConditionType;  
         private FilterConditionValues defaultValues;  
 
         public FilterStyleSettingsPage()  
         {  
             InitializeComponent();  
 
             defaultValues = new FilterConditionValues();  
             conditionPicker.Title = "Condition";  
             foreach (var item in defaultValues)  
             {  
                 conditionPicker.Items.Add(item.Key.ToString());  
             }  
 
             ToolbarItems.Add(new ToolbarItem("Exit", "quit", async () =>  
             {  
                 await Navigation.PopAsync(true);  
             }));  
 
             conditionPicker.SelectedIndexChanged += ConditionPicker_SelectedIndexChanged;  
             conditionPicker.SelectedIndex = 0;  
 
             applyButton.Clicked += ApplyButton_Clicked;  
         }  
 
         private void ConditionPicker_SelectedIndexChanged(object sender, EventArgs e)  
         {  
             selectedConditionType = (SimpleFilterConditionType)Enum.Parse(typeof(SimpleFilterConditionType), conditionPicker.Items[conditionPicker.SelectedIndex]);  
             columnLabel.Text = defaultValues[selectedConditionType].Item1;  
             valueEntry.Text = defaultValues[selectedConditionType].Item2;  
         }  
 
         public string ColumnName  
         {  
             get { return columnLabel.Text; }  
         }  
 
         public string SettingsValue  
         {  
             get { return valueEntry.Text; }  
         }  
 
         public SimpleFilterConditionType SelectedConditionType  
         {  
             get { return selectedConditionType; }  
         }  
 
         private void ApplyButton_Clicked(object sender, EventArgs e)  
         {  
             Navigation.PopAsync(true);  
             OnApplyingSettings();  
         }  
 
         private void OnApplyingSettings()  
         {  
             EventHandler handler = ApplyingSettings;  
 
             if (handler != null)  
             {  
                 handler(this, new EventArgs());  
             }  
         }  
     }  
 }  
 
 

HeatStyleSample.cs

 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 
 namespace AnalyzeVisual  
 {  
     public class HeatStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-124.097208477811, 48.9471097666172, -110.242106301448, 28.7359794668483);  
 
             ShapeFileFeatureLayer usEarthquakeLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("usEarthquake_Simplified.shp"));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(usEarthquakeLayer);  
             MapView.Overlays.Add(layerOverlay);  
 
             usEarthquakeLayer.DrawingMarginPercentage = 100;  
             usEarthquakeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();  
             usEarthquakeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new HeatStyle(10, 150, "MAGNITUDE", 0, 12, 100, DistanceUnit.Kilometer));  
             usEarthquakeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
     }  
 }  
 
 

IconStyleSample.cs

 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 
 namespace AnalyzeVisual  
 {  
     public class IconStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.DecimalDegree;  
             MapView.CurrentExtent = new RectangleShape(-96.8924, 33.3525, -96.6453, 32.9714);  
 
             ShapeFileFeatureLayer iconStyleFeatureLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("Vehicles.shp"));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             layerOverlay.Layers.Add(iconStyleFeatureLayer);  
             MapView.Overlays.Add(layerOverlay);  
 
             iconStyleFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(GetIconStyle(SampleHelper.GetDataPath(@"Images/")));  
             iconStyleFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         }  
 
         private static ValueStyle GetIconStyle(string imagePath)  
         {  
             ValueStyle valueStyle = new ValueStyle();  
             valueStyle.ColumnName = "TYPE";  
 
             GeoFont font = new GeoFont("Arial", 9);  
             GeoSolidBrush brush = new GeoSolidBrush(GeoColor.StandardColors.Black);  
 
             valueStyle.ValueItems.Add(new ValueItem("1", new IconStyle(imagePath + "vehicle1.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("2", new IconStyle(imagePath + "vehicle2.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("3", new IconStyle(imagePath + "vehicle3.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("4", new IconStyle(imagePath + "vehicle4.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("5", new IconStyle(imagePath + "vehicle5.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("6", new IconStyle(imagePath + "vehicle6.png", "Type", font, brush)));  
             valueStyle.ValueItems.Add(new ValueItem("7", new IconStyle(imagePath + "vehicle7.png", "Type", font, brush)));  
 
             return valueStyle;  
         }  
     }  
 }  
 
 

EarthquakeIsoLineFeatureLayer.cs

 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Globalization;  
 using System.Linq;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace AnalyzeVisual  
 {  
     public class EarthquakeIsoLineFeatureLayer : FeatureLayer  
     {  
         private DynamicIsoLineLayer isoLineLayer;  
         private ClassBreakStyle levelClassBreakStyle;  
 
         public EarthquakeIsoLineFeatureLayer()  
             : this(null)  
         { }  
 
         public EarthquakeIsoLineFeatureLayer(ShapeFileFeatureSource featureSource)  
         {  
             FeatureSource = featureSource;  
         }  
 
         public new FeatureSource FeatureSource  
         {  
             get { return base.FeatureSource; }  
             set  
             {  
                 base.FeatureSource = value;  
                 Initialize();  
             }  
         }  
 
         public Collection<double> IsoLineLevels  
         {  
             get { return isoLineLayer.IsoLineLevels; }  
         }  
 
         public ClassBreakStyle LevelClassBreakStyle  
         {  
             get { return levelClassBreakStyle; }  
         }  
 
         protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)  
         {  
             isoLineLayer.Draw(canvas, labelsInAllLayers);  
         }  
 
         private void Initialize()  
         {  
             Collection<GeoColor> levelAreaColors = new Collection<GeoColor>();  
             levelAreaColors.Add(GeoColor.FromHtml("#FFFFBE"));  
             levelAreaColors.Add(GeoColor.FromHtml("#FDFF9E"));  
             levelAreaColors.Add(GeoColor.FromHtml("#FDFF37"));  
             levelAreaColors.Add(GeoColor.FromHtml("#FDDA04"));  
             levelAreaColors.Add(GeoColor.FromHtml("#FFA701"));  
             levelAreaColors.Add(GeoColor.FromHtml("#FF6F02"));  
             levelAreaColors.Add(GeoColor.FromHtml("#EC0000"));  
             levelAreaColors.Add(GeoColor.FromHtml("#B90000"));  
             levelAreaColors.Add(GeoColor.FromHtml("#850100"));  
             levelAreaColors.Add(GeoColor.FromHtml("#620001"));  
             levelAreaColors.Add(GeoColor.FromHtml("#450005"));  
             levelAreaColors.Add(GeoColor.FromHtml("#2B0804"));  
 
             FeatureSource.Open();  
 
             Dictionary<PointShape, double> dataPoints = GetDataPoints();  
             GridInterpolationModel interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue);  
             isoLineLayer = new DynamicIsoLineLayer(dataPoints, GetClassBreakValues(dataPoints.Values, 12), interpolationModel, IsoLineType.ClosedLinesAsPolygons);  
 
             isoLineLayer.CellWidthInPixel = 32;  
             isoLineLayer.CellHeightInPixel = 32;  
             levelClassBreakStyle = new ClassBreakStyle(isoLineLayer.DataValueColumnName);  
             levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[0])))));  
             for (int i = 0; i < IsoLineLevels.Count - 1; i++)  
             {  
                 if (!levelClassBreakStyle.ClassBreaks.Any(c => c.Value == IsoLineLevels[i|+ 1]))  
                 {  
                     levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(IsoLineLevels[i|+ 1], new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[i|+ 1])))));  
                 }  
             }  
             isoLineLayer.CustomStyles.Add(levelClassBreakStyle);  
 
             TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);  
             textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);  
             textStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;  
             textStyle.SplineType = SplineType.StandardSplining;  
             textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;  
             textStyle.TextLineSegmentRatio = 9999999;  
             textStyle.FittingLineInScreen = true;  
             textStyle.SuppressPartialLabels = true;  
             textStyle.NumericFormat = "{0:0.00}";  
             isoLineLayer.CustomStyles.Add(textStyle);  
         }  
 
         private Dictionary<PointShape, double> GetDataPoints()  
         {  
             return (from feature in FeatureSource.GetAllFeatures(GetReturningColumns())  
                     where double.Parse(feature.ColumnValues["MAGNITUDE"]) > 0  
                     select new PointShape  
                     {  
                         X = double.Parse(feature.ColumnValues["LONGITUDE"], CultureInfo.InvariantCulture),  
                         Y = double.Parse(feature.ColumnValues["LATITIUDE"], CultureInfo.InvariantCulture),  
                         Z = double.Parse(feature.ColumnValues["MAGNITUDE"], CultureInfo.InvariantCulture)  
                     }).ToDictionary(point => point, point => point.Z);  
         }  
 
         private static IEnumerable<double> GetClassBreakValues(IEnumerable<double> values, int count)  
         {  
             Collection<double> result = new Collection<double>();  
             double[] sortedValues = values.OrderBy(v => v).ToArray();  
             int classCount = sortedValues.Length / count;  
             for (int i = 1; i < count; i++)  
             {  
                 result.Add(sortedValues[i|* classCount]);  
             }  
 
             return result;  
         }  
 
         private static IEnumerable<string> GetReturningColumns()  
         {  
             //LONGITUDE  
             yield return "LONGITUDE";  
             //LATITIUDE  
             yield return "LATITIUDE";  
             //MAGNITUDE  
             yield return "MAGNITUDE";  
         }  
     }  
 }  
 

IsolineStyleSample.cs

 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.FormsEdition;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public class IsolineStyleSample : BaseSampleView  
     {  
         protected override void LoadMap()  
         {  
             MapView.MapUnit = GeographyUnit.Meter;  
             MapView.CurrentExtent = new RectangleShape(-15116491.8671313, 8720801.79162702, -11021545.2583953, 2603975.29482756);  
 
             WorldMapKitOverlay worldOverlay = (WorldMapKitOverlay)MapView.Overlays["WMK"];  
             worldOverlay.Projection = WorldMapKitProjection.SphericalMercator;  
 
             EarthquakeIsoLineFeatureLayer usEarthquakeIsoLayer = new EarthquakeIsoLineFeatureLayer(new ShapeFileFeatureSource(SampleHelper.GetDataPath("usEarthquake_Simplified.shp")));  
             LayerOverlay layerOverlay = new LayerOverlay();  
             DependencyService.Get<IPlatformService>().ChangeOverlayTileSize(layerOverlay, 512, 512);  
             layerOverlay.Layers.Add(usEarthquakeIsoLayer);  
             MapView.Overlays.Add(layerOverlay);  
         }  
     }  
 }  
 
 

SampleHelper.cs

 using System.IO;  
 using Xamarin.Forms;  
 
 namespace AnalyzeVisual  
 {  
     public static class SampleHelper  
     {  
         public static readonly string AssetsDataDictionary = Device.OnPlatform("AppData", "AppData", string.Empty);  
         public static readonly string SampleDataDictionary = Device.OnPlatform(string.Empty, @"mnt/sdcard/MapSuiteSampleData/AnalyzingVisualization", string.Empty);  
 
         public static string GetDataPath(string fileName)  
         {  
             string result = string.IsNullOrEmpty(SampleDataDictionary) ? Path.Combine(AssetsDataDictionary, fileName)  
                 : Path.Combine(SampleDataDictionary, AssetsDataDictionary, fileName);  
             return result;  
         }  
     }  
 }  
 
 

IPlatformService.cs

 namespace AnalyzeVisual  
 {  
     public interface IPlatformService  
     {  
         string ReadAllText(string fileName);  
 
         void ChangeOverlayTileSize(object tileOverlay, double width, double height);  
     }  
 }  
 
 
source_code_xamarinformseditionsample_analyzevisual.zip.txt · Last modified: 2015/09/14 02:08 by admin