ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using Foundation; using UIKit; namespace MapSuiteEarthquakeStatistics { // The UIApplicationDelegate for the application. This class is responsible for launching the // User Interface of the application, as well as listening (and optionally responding) to // application events from iOS. [Register("AppDelegate")] public partial class AppDelegate : UIApplicationDelegate { // class-level declarations public override UIWindow Window { get; set; } // This method is invoked when the application is about to move from active to inactive state. // OpenGL applications should use this method to pause. public override void OnResignActivation(UIApplication application) { } // This method should be used to release shared resources and it should store the application state. // If your application supports background exection this method is called instead of WillTerminate // when the user quits. public override void DidEnterBackground(UIApplication application) { } // This method is called as part of the transiton from background to active state. public override void WillEnterForeground(UIApplication application) { } // This method is called when the application is about to terminate. Save data, if needed. public override void WillTerminate(UIApplication application) { } } }
using UIKit; namespace MapSuiteEarthquakeStatistics { public class Application { // This is the main entry point of the application. static void Main(string[] args) { // if you want to use a different Application Delegate class from "AppDelegate" // you can specify it here. UIApplication.Main(args, null, "AppDelegate"); } } }
using CoreGraphics; using Foundation; using UIKit; using System; using System.Collections.ObjectModel; using System.Drawing; using System.Globalization; using System.IO; using System.Linq; using System.Net; using System.Threading.Tasks; using System.Xml; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace MapSuiteEarthquakeStatistics { public partial class MainViewController : UIViewController { private MapView iOSMap; private UIActivityIndicatorView loadingView; private UINavigationController optionNavigationController; private UIPopoverController optionsPopover; private OptionsViewController optionsController; private BaseMapTypeController baseTypeTableViewController; public MainViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); InitializeMap(); InitializeComponent(); InitializeSetting(); } public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration) { base.WillAnimateRotation(toInterfaceOrientation, duration); double resolution = Math.Max(iOSMap.CurrentExtent.Width / iOSMap.Frame.Width, iOSMap.CurrentExtent.Height / iOSMap.Frame.Height); iOSMap.Frame = View.Frame; iOSMap.CurrentExtent = GetExtentRetainScale(iOSMap.CurrentExtent.GetCenterPoint(), resolution); iOSMap.Refresh(); } private void InitializeMap() { string targetDictionary = @"AppData/SampleData"; ManagedProj4Projection proj4 = Global.GetWgs84ToMercatorProjection(); string rootPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/CacheImages"; // WMK WorldMapKitOverlay wmkOverlay = new WorldMapKitOverlay(); wmkOverlay.Projection = WorldMapKitProjection.SphericalMercator; // OSM OpenStreetMapOverlay osmOverlay = new OpenStreetMapOverlay(); osmOverlay.TileCache = new FileBitmapTileCache(rootPath + "/OpenStreetMaps", "SphericalMercator"); osmOverlay.TileCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Meter; osmOverlay.TileCache.TileMatrix.BoundingBox = osmOverlay.GetBoundingBox(); osmOverlay.TileCache.ImageFormat = TileImageFormat.Jpeg; osmOverlay.IsVisible = false; // Bing - Aerial BingMapsOverlay bingMapsAerialOverlay = new BingMapsOverlay(); bingMapsAerialOverlay.MapStyle = BingMapsMapType.AerialWithLabels; bingMapsAerialOverlay.TileCache = new FileBitmapTileCache(rootPath + "/BingMaps", "AerialWithLabels"); bingMapsAerialOverlay.TileCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Meter; bingMapsAerialOverlay.TileCache.TileMatrix.BoundingBox = bingMapsAerialOverlay.GetBoundingBox(); bingMapsAerialOverlay.TileCache.ImageFormat = TileImageFormat.Jpeg; bingMapsAerialOverlay.IsVisible = false; // Bing - Road BingMapsOverlay bingMapsRoadOverlay = new BingMapsOverlay(); bingMapsRoadOverlay.MapStyle = BingMapsMapType.Road; bingMapsRoadOverlay.TileCache = new FileBitmapTileCache(rootPath + "/BingMaps", "Road"); bingMapsRoadOverlay.TileCache.TileMatrix.BoundingBoxUnit = GeographyUnit.Meter; bingMapsRoadOverlay.TileCache.TileMatrix.BoundingBox = bingMapsRoadOverlay.GetBoundingBox(); bingMapsRoadOverlay.TileCache.ImageFormat = TileImageFormat.Jpeg; bingMapsRoadOverlay.IsVisible = false; // Earthquake points ShapeFileFeatureLayer earthquakePointLayer = new ShapeFileFeatureLayer(Path.Combine(targetDictionary, "usEarthquake.shp")); earthquakePointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red, 5, GeoColor.SimpleColors.White, 1)); earthquakePointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; earthquakePointLayer.FeatureSource.Projection = proj4; ShapeFileFeatureSource earthquakeHeatFeatureSource = new ShapeFileFeatureSource(Path.Combine(targetDictionary, "usEarthquake_Simplified.shp")); earthquakeHeatFeatureSource.Projection = proj4; HeatLayer earthquakeHeatLayer = new HeatLayer(earthquakeHeatFeatureSource); earthquakeHeatLayer.HeatStyle = new HeatStyle(10, 75, DistanceUnit.Kilometer); earthquakeHeatLayer.HeatStyle.Alpha = 180; earthquakeHeatLayer.IsVisible = false; LayerOverlay highlightOverlay = new LayerOverlay(); highlightOverlay.Layers.Add("EarthquakePointLayer", earthquakePointLayer); highlightOverlay.Layers.Add("EarthquakeHeatLayer", earthquakeHeatLayer); // Highlighted points InMemoryFeatureLayer selectedMarkerLayer = new InMemoryFeatureLayer(); selectedMarkerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Orange, 8, GeoColor.SimpleColors.White, 2); selectedMarkerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; PointStyle highLightMarkerStyle = new PointStyle(); highLightMarkerStyle.CustomPointStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(50, GeoColor.SimpleColors.Blue), 20, GeoColor.SimpleColors.LightBlue, 1)); highLightMarkerStyle.CustomPointStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(255, 0, 122, 255), 10, GeoColor.SimpleColors.White, 2)); InMemoryFeatureLayer highlightMarkerLayer = new InMemoryFeatureLayer(); highlightMarkerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = highLightMarkerStyle; highlightMarkerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; highlightOverlay.Layers.Add("SelectMarkerLayer", selectedMarkerLayer); highlightOverlay.Layers.Add("HighlightMarkerLayer", highlightMarkerLayer); // Maps iOSMap = new MapView(View.Frame); iOSMap.MapUnit = GeographyUnit.Meter; iOSMap.ZoomLevelSet = new BingMapsZoomLevelSet(); iOSMap.CurrentExtent = new RectangleShape(-19062735.6816748, 9273256.52450252, -5746827.16371793, 2673516.56066139); iOSMap.BackgroundColor = new UIColor(233, 229, 220, 200); iOSMap.Overlays.Add(Global.OpenStreetMapOverlayKey, osmOverlay); iOSMap.Overlays.Add(Global.WorldMapKitOverlayKey, wmkOverlay); iOSMap.Overlays.Add(Global.BingMapsAerialOverlayKey, bingMapsAerialOverlay); iOSMap.Overlays.Add(Global.BingMapsRoadOverlayKey, bingMapsRoadOverlay); iOSMap.Overlays.Add(Global.HighLightOverlayKey, highlightOverlay); iOSMap.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear(); iOSMap.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(80, GeoColor.SimpleColors.LightGreen), 8); iOSMap.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.White, 3, true); iOSMap.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(80, GeoColor.SimpleColors.LightGreen), GeoColor.SimpleColors.White, 2); iOSMap.TrackOverlay.TrackEnded += TrackInteractiveOverlayOnTrackEnded; Global.MapView = iOSMap; View.Add(iOSMap); iOSMap.Refresh(); } private void InitializeComponent() { EarthquakeToolBar toolBar = EarthquakeToolBar.Instance; toolBar.ToolBarButtonClick += ToolbarButtonClick; operationToolbar.SetItems(toolBar.GetToolBarItems().ToArray(), true); operationToolbar.TintColor = UIColor.FromRGB(103, 103, 103); queryResultView.Hidden = true; queryResultView.Layer.Opacity = 0.85f; View.BringSubviewToFront(queryResultView); tbvQueryResult.Layer.Opacity = 0.85f; tbvQueryResult.Layer.BorderColor = UIColor.Gray.CGColor; tbvQueryResult.Layer.BorderWidth = 1; tbvQueryResult.Layer.ShadowColor = UIColor.Red.CGColor; alertViewShadow.Hidden = true; View.BringSubviewToFront(alertViewShadow); bingMapKeyAlertView.Hidden = true; bingMapKeyAlertView.Center = View.Center; View.BringSubviewToFront(bingMapKeyAlertView); View.BringSubviewToFront(operationToolbar); loadingView = new UIActivityIndicatorView(View.Frame); loadingView.Center = View.Center; loadingView.ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray; View.AddSubview(loadingView); View.BringSubviewToFront(loadingView); txtBingMapKey.ShouldReturn += textField => { textField.ResignFirstResponder(); return true; }; } private void InitializeSetting() { optionsController = (OptionsViewController)Global.FindViewController("OptionsViewController"); optionsController.QueryEarthquakeResult = QueryEarthquakeResult; optionsController.OptionRowClick = OptionRowClick; optionsController.PreferredContentSize = new SizeF(420, 410); optionNavigationController = new UINavigationController(optionsController); optionNavigationController.PreferredContentSize = new SizeF(420, 410); baseTypeTableViewController = new BaseMapTypeController(); baseTypeTableViewController.RowClick = (view, path) => { optionNavigationController.PopToRootViewController(true); DismissOptionController(); }; baseTypeTableViewController.DispalyBingMapKeyAlertView = ShowBingMapKeyAlertView; } private void ShowBingMapKeyAlertView() { alertViewShadow.Hidden = false; bingMapKeyAlertView.Hidden = false; DismissOptionController(); } private void TrackInteractiveOverlayOnTrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs args) { loadingView.StartAnimating(); Task.Factory.StartNew(() => { MultipolygonShape resultShape = PolygonShape.Union(iOSMap.TrackOverlay.TrackShapeLayer.InternalFeatures); ShapeFileFeatureLayer earthquakePointLayer = (ShapeFileFeatureLayer)Global.HighLightOverlay.Layers["EarthquakePointLayer"]; earthquakePointLayer.Open(); Collection<Feature> features = earthquakePointLayer.FeatureSource.GetFeaturesWithinDistanceOf(new Feature(resultShape), iOSMap.MapUnit, DistanceUnit.Meter, 0.0001, ReturningColumnsType.AllColumns); Global.QueriedFeatures.Clear(); foreach (Feature feature in features) { Global.QueriedFeatures.Add(feature); } Global.FilterSelectedEarthquakeFeatures(); InvokeOnMainThread(() => { Global.HighLightOverlay.Refresh(); loadingView.StopAnimating(); }); }); } private void ToolbarButtonClick(object sender, EventArgs e) { queryResultView.AnimatedHide(); UIBarButtonItem buttonItem = (UIBarButtonItem)sender; if (buttonItem != null) { switch (buttonItem.Title) { case EarthquakeConstant.Cursor: iOSMap.TrackOverlay.TrackMode = TrackMode.None; break; case EarthquakeConstant.Polygon: iOSMap.TrackOverlay.TrackMode = TrackMode.Polygon; break; case EarthquakeConstant.Rectangle: iOSMap.TrackOverlay.TrackMode = TrackMode.Rectangle; break; case EarthquakeConstant.Clear: iOSMap.TrackOverlay.TrackMode = TrackMode.None; ClearQueryResult(); iOSMap.Refresh(); break; case EarthquakeConstant.Search: iOSMap.TrackOverlay.TrackMode = TrackMode.None; RefreshQueryResultData(); break; case EarthquakeConstant.Options: iOSMap.TrackOverlay.TrackMode = TrackMode.None; ShowOptionsPopover(optionNavigationController); break; default: iOSMap.TrackOverlay.TrackMode = TrackMode.None; break; } RefreshToolbarItem(operationToolbar, buttonItem); } } private void ClearQueryResult() { Global.QueriedFeatures.Clear(); ((InMemoryFeatureLayer)Global.HighLightOverlay.Layers["SelectMarkerLayer"]).InternalFeatures.Clear(); ((InMemoryFeatureLayer)Global.HighLightOverlay.Layers["HighlightMarkerLayer"]).InternalFeatures.Clear(); Global.HighLightOverlay.Refresh(); iOSMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear(); iOSMap.TrackOverlay.Refresh(); tbvQueryResult.Source = null; tbvQueryResult.ReloadData(); } private void ShowOptionsPopover(UIViewController popoverContentController) { if (Global.UserInterfaceIdiomIsPhone) { optionsController.ModalPresentationStyle = UIModalPresentationStyle.CurrentContext; optionsController.ModalTransitionStyle = UIModalTransitionStyle.CrossDissolve; PresentViewController(optionsController, true, null); } else { if (optionsPopover == null) optionsPopover = new UIPopoverController(popoverContentController); optionsPopover.PresentFromRect(new CGRect(View.Frame.Width - 55, View.Frame.Height - 35, 50, 50), View, UIPopoverArrowDirection.Down, true); } } private void OptionRowClick(string itemName) { if (itemName.Equals("Base Map")) optionNavigationController.PushViewController(baseTypeTableViewController, true); else DismissOptionController(); } private void DismissOptionController() { if (Global.UserInterfaceIdiomIsPhone) optionsController.DismissViewController(true, null); else optionsPopover.Dismiss(true); } private void RefreshToolbarItem(UIToolbar toolbar, UIBarButtonItem buttonItem) { UIColor defaultColor = UIColor.FromRGB(103, 103, 103); UIColor highlightColor = UIColor.FromRGB(27, 119, 222); // Set all item color to default. foreach (var item in toolbar.Items) { item.TintColor = defaultColor; } if (buttonItem.Title.Equals(EarthquakeConstant.Rectangle) || buttonItem.Title.Equals(EarthquakeConstant.Polygon)) buttonItem.TintColor = highlightColor; } private void QueryEarthquakeResult() { if (Global.UserInterfaceIdiomIsPhone) optionsController.DismissViewController(true, null); else optionsPopover.Dismiss(true); RefreshQueryResultData(); } private void RefreshQueryResultData() { if (queryResultView.Hidden) queryResultView.AnimatedShow(); DataTableSource earthquakeSource; if (tbvQueryResult.Source == null) { earthquakeSource = new DataTableSource(); earthquakeSource.RowClick = EarthquakeRowClicked; } else { earthquakeSource = (DataTableSource)tbvQueryResult.Source; } earthquakeSource.Sections.Clear(); ManagedProj4Projection mercatorToWgs84Projection = Global.GetWgs84ToMercatorProjection(); mercatorToWgs84Projection.Open(); try { Global.FilterSelectedEarthquakeFeatures(); InMemoryFeatureLayer selectMarkerLayer = (InMemoryFeatureLayer)Global.HighLightOverlay.Layers["SelectMarkerLayer"]; GeoCollection<Feature> selectFeatures = selectMarkerLayer.InternalFeatures; SectionModel detailSection = new SectionModel("Queried Count: " + selectFeatures.Count); detailSection.HeaderHeight = 50; foreach (var feature in selectFeatures) { double longitude, latitude = 0; if (double.TryParse(feature.ColumnValues["LONGITUDE"], out longitude) && double.TryParse(feature.ColumnValues["LATITIUDE"], out latitude)) { PointShape point = new PointShape(longitude, latitude); point = (PointShape)mercatorToWgs84Projection.ConvertToInternalProjection(point); longitude = point.X; latitude = point.Y; } double year, depth, magnitude; double.TryParse(feature.ColumnValues["MAGNITUDE"], out magnitude); double.TryParse(feature.ColumnValues["DEPTH_KM"], out depth); double.TryParse(feature.ColumnValues["YEAR"], out year); EarthquakeRow result = new EarthquakeRow(); result.YearValue = year != -9999 ? year.ToString(CultureInfo.InvariantCulture) : "Unknown"; result.LocationValue = longitude.ToString("f2", CultureInfo.InvariantCulture); result.LatitudeValue = latitude.ToString("f2", CultureInfo.InvariantCulture); result.DepthValue = depth != -9999 ? depth.ToString(CultureInfo.InvariantCulture) : "Unknown"; result.MagnitudeValue = magnitude != -9999 ? magnitude.ToString(CultureInfo.InvariantCulture) : "Unknown"; result.LocationValue = feature.ColumnValues["LOCATION"]; detailSection.Rows.Add(new RowModel(result.ToString(), new UIImageView(UIImage.FromBundle("location")))); } earthquakeSource.Sections.Add(detailSection); tbvQueryResult.Source = earthquakeSource; tbvQueryResult.ReloadData(); } finally { mercatorToWgs84Projection.Close(); } } private void EarthquakeRowClicked(UITableView tableView, NSIndexPath indexPath) { InMemoryFeatureLayer selectMarkerLayer = (InMemoryFeatureLayer)Global.HighLightOverlay.Layers["SelectMarkerLayer"]; Feature queryFeature = selectMarkerLayer.InternalFeatures[indexPath.Row]; iOSMap.ZoomTo(queryFeature.GetBoundingBox().GetCenterPoint(), iOSMap.ZoomLevelSet.ZoomLevel15.Scale); } partial void btnCancel_TouchUpInside(UIButton sender) { alertViewShadow.Hidden = true; bingMapKeyAlertView.Hidden = true; txtBingMapKey.EndEditing(true); } partial void btnOk_TouchUpInside(UIButton sender) { btnOk.Enabled = false; btnCancel.Enabled = false; txtBingMapKey.EndEditing(true); string bingMapKey = txtBingMapKey.Text; Task.Factory.StartNew(() => { bool isValid = ValidateBingMapKey(bingMapKey, BingMapsMapType.Aerial); iOSMap.BeginInvokeOnMainThread(() => { if (isValid) { ((BingMapsOverlay)iOSMap.Overlays["BingMapsAerialOverlay"]).ApplicationId = bingMapKey; ((BingMapsOverlay)iOSMap.Overlays["BingMapsRoadOverlay"]).ApplicationId = bingMapKey; iOSMap.Overlays["OpenStreetMapOverlay"].IsVisible = false; iOSMap.Overlays["BingMapsAerialOverlay"].IsVisible = Global.BaseMapType == BaseMapType.BingMapsAerial; iOSMap.Overlays["BingMapsRoadOverlay"].IsVisible = Global.BaseMapType == BaseMapType.BingMapsRoad; iOSMap.Refresh(); alertViewShadow.Hidden = true; bingMapKeyAlertView.Hidden = true; } else { lblBingMapKeyMessage.Text = "The input BingMapKey is not validate."; } btnOk.Enabled = true; btnCancel.Enabled = true; }); }); } private RectangleShape GetExtentRetainScale(PointShape currentLocationInMecator, double resolution = double.NaN) { if (double.IsNaN(resolution)) { resolution = Math.Max(iOSMap.CurrentExtent.Width / iOSMap.Frame.Width, iOSMap.CurrentExtent.Height / iOSMap.Frame.Height); } double left = currentLocationInMecator.X - resolution * iOSMap.Frame.Width * .5; double right = currentLocationInMecator.X + resolution * iOSMap.Frame.Width * .5; double top = currentLocationInMecator.Y + resolution * iOSMap.Frame.Height * .5; double bottom = currentLocationInMecator.Y - resolution * iOSMap.Frame.Height * .5; return new RectangleShape(left, top, right, bottom); } private bool ValidateBingMapKey(string bingMapsKey, BingMapsMapType mapType) { bool result = false; Stream stream = null; string loginServiceTemplate = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/{0}?&incl=ImageryProviders&o=xml&key={1}"; try { string loginServiceUri = string.Format(CultureInfo.InvariantCulture, loginServiceTemplate, mapType, bingMapsKey); Uri uri = new Uri(loginServiceUri); WebRequest webRequest = new HttpWebRequest(uri); WebResponse response = webRequest.GetResponse(); stream = response.GetResponseStream(); if (stream != null) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(stream); XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable); nsmgr.AddNamespace("bing", "http://schemas.microsoft.com/search/local/ws/rest/v1"); XmlNode root = xDoc.SelectSingleNode("bing:Response", nsmgr); XmlNode imageUrlElement = root.SelectSingleNode("bing:ResourceSets/bing:ResourceSet/bing:Resources/bing:ImageryMetadata/bing:ImageUrl", nsmgr); XmlNodeList subdomainsElement = root.SelectNodes("bing:ResourceSets/bing:ResourceSet/bing:Resources/bing:ImageryMetadata/bing:ImageUrlSubdomains/bing:string", nsmgr); if (imageUrlElement != null && subdomainsElement != null) { result = true; } } } catch { } finally { if (stream != null) stream.Dispose(); } return result; } } }
// WARNING // // This file has been generated automatically by Xamarin Studio from the outlets and // actions declared in your storyboard file. // Manual changes to this file will not be maintained. // using System; using Foundation; using System.CodeDom.Compiler; using UIKit; namespace MapSuiteEarthquakeStatistics { [Register|("MainViewController")] partial class MainViewController { [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIView alertViewShadow { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIView bingMapKeyAlertView { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton btnCancel { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton btnOk { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UILabel lblBingMapKeyMessage { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIToolbar operationToolbar { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIView queryResultView { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UITableView tbvQueryResult { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UITextField txtBingMapKey { get; set; } [Action|("btnCancel_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void btnCancel_TouchUpInside (UIButton sender); [Action|("btnOk_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void btnOk_TouchUpInside (UIButton sender); void ReleaseDesignerOutlets () { if (alertViewShadow != null) { alertViewShadow.Dispose (); alertViewShadow = null; } if (bingMapKeyAlertView != null) { bingMapKeyAlertView.Dispose (); bingMapKeyAlertView = null; } if (btnCancel != null) { btnCancel.Dispose (); btnCancel = null; } if (btnOk != null) { btnOk.Dispose (); btnOk = null; } if (lblBingMapKeyMessage != null) { lblBingMapKeyMessage.Dispose (); lblBingMapKeyMessage = null; } if (operationToolbar != null) { operationToolbar.Dispose (); operationToolbar = null; } if (queryResultView != null) { queryResultView.Dispose (); queryResultView = null; } if (tbvQueryResult != null) { tbvQueryResult.Dispose (); tbvQueryResult = null; } if (txtBingMapKey != null) { txtBingMapKey.Dispose (); txtBingMapKey = null; } } } }
using System; using System.Collections.ObjectModel; using Foundation; using ThinkGeo.MapSuite.Core; using UIKit; namespace MapSuiteEarthquakeStatistics { [Register("BaseMapTypeController")] public class BaseMapTypeController : UITableViewController { public Action DispalyBingMapKeyAlertView; public Action<UITableView, NSIndexPath> RowClick; public BaseMapTypeController() { } public override void ViewDidLoad() { base.ViewDidLoad(); UITableView baseMapTypeTableView = new UITableView(View.Frame); DataTableSource baseMapTypeSource = new DataTableSource(); Collection<RowModel> baseMapTypeRows = new Collection<RowModel>(); string[] baseMapTypeItems = { "World Map Kit Road", "World Map Kit Aerial", "World Map Kit Aerial With Labels", "Open Street Map", "Bing Maps Aerial", "Bing Maps Road" }; foreach (var nameItem in baseMapTypeItems) { RowModel row = new RowModel(nameItem); row.CellAccessory = UITableViewCellAccessory.Checkmark; baseMapTypeRows.Add(row); } baseMapTypeRows[0].IsChecked = true; SectionModel baseMapTypeSection = new SectionModel(string.Empty, baseMapTypeRows); baseMapTypeSource.Sections.Add(baseMapTypeSection); baseMapTypeSource.RowClick = BaseMapTypeRowClick; baseMapTypeTableView.Source = baseMapTypeSource; View = baseMapTypeTableView; } private void BaseMapTypeRowClick(UITableView tableView, NSIndexPath indexPath) { DataTableSource source = (DataTableSource)tableView.Source; string selectedItem = source.Sections[indexPath.Section].Rows[indexPath.Row].Name; Global.BaseMapTypeString = selectedItem; foreach (var row in source.Sections[0].Rows) { row.IsChecked = row.Name.Equals(selectedItem); } tableView.ReloadData(); RefreshBaseMap(); if (RowClick != null) RowClick(tableView, indexPath); } private void RefreshBaseMap() { BaseMapType mapType; string baseMapTypeString = Global.BaseMapTypeString.Replace(" ", ""); if (Enum.TryParse(baseMapTypeString, true, out mapType)) Global.BaseMapType = mapType; switch (Global.BaseMapType) { case BaseMapType.WorldMapKitRoad: Global.WorldMapKitOverlay.TileCache.ClearCache(); Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.Road; Global.WorldMapKitOverlay.IsVisible = true; Global.OpenStreetMapOverlay.IsVisible = false; Global.BingMapsAerialOverlay.IsVisible = false; Global.BingMapsRoadOverlay.IsVisible = false; Global.MapView.Refresh(); break; case BaseMapType.WorldMapKitAerial: Global.WorldMapKitOverlay.TileCache.ClearCache(); Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.Aerial; Global.WorldMapKitOverlay.IsVisible = true; Global.OpenStreetMapOverlay.IsVisible = false; Global.BingMapsAerialOverlay.IsVisible = false; Global.BingMapsRoadOverlay.IsVisible = false; Global.MapView.Refresh(); break; case BaseMapType.WorldMapKitAerialWithLabels: Global.WorldMapKitOverlay.TileCache.ClearCache(); Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.AerialWithLabels; Global.WorldMapKitOverlay.IsVisible = true; Global.OpenStreetMapOverlay.IsVisible = false; Global.BingMapsAerialOverlay.IsVisible = false; Global.BingMapsRoadOverlay.IsVisible = false; Global.MapView.Refresh(); break; case BaseMapType.OpenStreetMap: Global.WorldMapKitOverlay.IsVisible = false; Global.OpenStreetMapOverlay.IsVisible = true; Global.BingMapsAerialOverlay.IsVisible = false; Global.BingMapsRoadOverlay.IsVisible = false; Global.MapView.Refresh(); break; case BaseMapType.BingMapsAerial: case BaseMapType.BingMapsRoad: string applicatoinId = Global.BingMapKey; if (!string.IsNullOrEmpty(applicatoinId)) { Global.BingMapsAerialOverlay.ApplicationId = applicatoinId; Global.BingMapsRoadOverlay.ApplicationId = applicatoinId; Global.WorldMapKitOverlay.IsVisible = false; Global.OpenStreetMapOverlay.IsVisible = false; Global.BingMapsAerialOverlay.IsVisible = Global.BaseMapType == BaseMapType.BingMapsAerial; Global.BingMapsRoadOverlay.IsVisible = Global.BaseMapType == BaseMapType.BingMapsRoad; Global.MapView.Refresh(); } else { if (DispalyBingMapKeyAlertView != null) DispalyBingMapKeyAlertView(); } break; } } } }
using Foundation; using UIKit; using System; using System.Collections.ObjectModel; using System.Drawing; using ThinkGeo.MapSuite.Core; namespace MapSuiteEarthquakeStatistics { partial class OptionsViewController : UIViewController { private DisplayType displayType; private DataTableSource baseMapTypeSource; private HeatLayer earthquakeHeatLayer; private ShapeFileFeatureLayer earthquakePointLayer; private UILabel baseMapLabel; public Action QueryEarthquakeResult; public Action<string> OptionRowClick; public OptionsViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); InitializeOptionsSource(); InitializeComponent(); } public override void ViewDidAppear(bool animated) { baseMapLabel.Text = Global.BaseMapTypeString ?? "World Map Kit Road"; } private void InitializeOptionsSource() { earthquakePointLayer = (ShapeFileFeatureLayer)Global.HighLightOverlay.Layers["EarthquakePointLayer"]; earthquakeHeatLayer = (HeatLayer)Global.HighLightOverlay.Layers["EarthquakeHeatLayer"]; int rowWidth = 400; int sliderWith = 190; if (Global.UserInterfaceIdiomIsPhone) { rowWidth = 300; sliderWith = 90; } baseMapTypeSource = new DataTableSource(); baseMapTypeSource.RowClick += RowClick; RectangleF rowFrame = new RectangleF(10, 5, rowWidth, 30); Collection<RowModel> baseMapRows = new Collection<RowModel>(); RowModel baseMapModel = new RowModel("Base Map"); baseMapLabel = new UILabel(new RectangleF(5, 5, rowWidth * 0.6f, 40)); baseMapLabel.TextAlignment = UITextAlignment.Right; baseMapLabel.TextColor = UIColor.Black; baseMapLabel.UserInteractionEnabled = false; baseMapModel.CellAccessory = UITableViewCellAccessory.DisclosureIndicator; baseMapModel.CustomUI = baseMapLabel; baseMapModel.CustomUIBounds = new RectangleF(rowWidth * 0.35f, 10, rowWidth * 0.6f, 30); baseMapModel.RowHeight = 50; baseMapRows.Add(baseMapModel); baseMapTypeSource.Sections.Add(new SectionModel("Base Map Type", baseMapRows) { HeaderHeight = 30 }); Collection<RowModel> displayTypeRows = new Collection<RowModel>(); RowModel displayTypeModel = new RowModel(string.Empty); UISegmentedControl displayTypeSegment = new UISegmentedControl(); displayTypeSegment.InsertSegment("Point Type", 1, true); displayTypeSegment.InsertSegment("Heat Style", 2, true); displayTypeSegment.InsertSegment("IsoLine Style", 3, true); displayTypeSegment.ValueChanged += DisplayTypeSegmentValueChanged; displayTypeSegment.SelectedSegment = 0; displayTypeModel.CustomUI = displayTypeSegment; displayTypeModel.CustomUIBounds = new RectangleF(10, 10, rowWidth, 30); displayTypeModel.RowHeight = 50; displayTypeRows.Add(displayTypeModel); baseMapTypeSource.Sections.Add(new SectionModel("Display Type", displayTypeRows) { HeaderHeight = 30 }); Collection<RowModel> queryOperation = new Collection<RowModel>(); RowModel magnitude = new RowModel(string.Empty); RowModel depth = new RowModel(string.Empty); RowModel date = new RowModel(string.Empty); RectangleF silderFrame = new RectangleF(150, 0, sliderWith, 30); RangeSliderView magnitudeView = new RangeSliderView(new UIRangeSlider(silderFrame, Global.QueryConfiguration.LowerMagnitude, Global.QueryConfiguration.UpperMagnitude, Global.QueryConfiguration.LowerMagnitude, Global.QueryConfiguration.UpperMagnitude) { Name = "Magnitude:" }); magnitudeView.Frame = rowFrame; magnitude.CustomUI = magnitudeView; magnitude.CustomUIBounds = rowFrame; magnitude.RowHeight = 45; RangeSliderView depthView = new RangeSliderView(new UIRangeSlider(silderFrame, Global.QueryConfiguration.LowerDepth, Global.QueryConfiguration.UpperDepth, Global.QueryConfiguration.LowerDepth, Global.QueryConfiguration.UpperDepth) { Name = "Depth(KM):" }); depthView.Frame = rowFrame; depth.CustomUI = depthView; depth.CustomUIBounds = rowFrame; depth.RowHeight = 45; RangeSliderView dateView = new RangeSliderView(new UIRangeSlider(silderFrame, Global.QueryConfiguration.LowerYear, Global.QueryConfiguration.UpperYear, Global.QueryConfiguration.LowerYear, Global.QueryConfiguration.UpperYear) { Name = "Date(Year):" }); dateView.Frame = rowFrame; date.CustomUI = dateView; date.CustomUIBounds = rowFrame; date.RowHeight = 45; queryOperation.Add(magnitude); queryOperation.Add(depth); queryOperation.Add(date); baseMapTypeSource.Sections.Add(new SectionModel("Query Operation", queryOperation) { HeaderHeight = 30 }); tbvBaseMapType.Source = baseMapTypeSource; } private void InitializeComponent() { btnQuery.Layer.CornerRadius = 5; } private void RowClick(UITableView tableView, NSIndexPath indexPath) { if (OptionRowClick != null) { DataTableSource source = (DataTableSource)tableView.Source; string itemName = source.Sections[indexPath.Section].Rows[indexPath.Row].Name; OptionRowClick(itemName); } } private void DisplayTypeSegmentValueChanged(object sender, EventArgs e) { UISegmentedControl displayTypeSegment = (UISegmentedControl)sender; switch (displayTypeSegment.SelectedSegment) { case 0: displayType = DisplayType.Point; ; break; case 1: displayType = DisplayType.Heat; break; case 2: displayType = DisplayType.ISOLine; break; } earthquakePointLayer.IsVisible = false; earthquakeHeatLayer.IsVisible = false; if (displayType == DisplayType.Heat) { earthquakeHeatLayer.IsVisible = true; } else if (displayType == DisplayType.Point) { earthquakePointLayer.IsVisible = true; } Global.HighLightOverlay.Refresh(); } partial void btnClose_TouchUpInside(UIButton sender) { DismissViewController(true, null); } partial void btnQuery_TouchUpInside(UIButton sender) { if (QueryEarthquakeResult != null) { if (Global.UserInterfaceIdiomIsPhone) DismissViewController(true, () => QueryEarthquakeResult()); else QueryEarthquakeResult(); } } } }
// WARNING // // This file has been generated automatically by Xamarin Studio from the outlets and // actions declared in your storyboard file. // Manual changes to this file will not be maintained. // using System; using Foundation; using UIKit; using System.CodeDom.Compiler; namespace MapSuiteEarthquakeStatistics { [Register|("OptionsViewController")] partial class OptionsViewController { [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton btnClose { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIButton btnQuery { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UIView queryViewController { get; set; } [Outlet] [GeneratedCode|("iOS Designer", "1.0")] UITableView tbvBaseMapType { get; set; } [Action|("btnClose_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void btnClose_TouchUpInside (UIButton sender); [Action|("btnQuery_TouchUpInside:")] [GeneratedCode|("iOS Designer", "1.0")] partial void btnQuery_TouchUpInside (UIButton sender); void ReleaseDesignerOutlets () { if (btnClose != null) { btnClose.Dispose (); btnClose = null; } if (btnQuery != null) { btnQuery.Dispose (); btnQuery = null; } if (queryViewController != null) { queryViewController.Dispose (); queryViewController = null; } if (tbvBaseMapType != null) { tbvBaseMapType.Dispose (); tbvBaseMapType = null; } } } }
using System; using CoreAnimation; using CoreGraphics; using UIKit; namespace MapSuiteEarthquakeStatistics { public class CERangeSliderKnobLayer : CALayer { private bool highlight; private UIRangeSlider slider; public bool Highlight { get { return highlight; } set { highlight = value; } } public UIRangeSlider Slider { get { return slider; } set { slider = value; } } public override void DrawInContext(CGContext ctx) { nfloat cornerRadius = Bounds.Height * Slider.Curvaceousness / 2; UIBezierPath switchOutline = UIBezierPath.FromRoundedRect(Bounds, cornerRadius); ctx.AddPath(switchOutline.CGPath); ctx.Clip(); ctx.SetFillColor(Slider.TrackColor.CGColor); ctx.AddPath(switchOutline.CGPath); ctx.FillPath(); ctx.AddPath(switchOutline.CGPath); ctx.SetStrokeColor(UIColor.Gray.CGColor); ctx.SetLineWidth(0.5f); ctx.StrokePath(); } } }
using System; namespace MapSuiteEarthquakeStatistics { public class RangeChangedEventArgs : EventArgs { private nfloat lowerValue; private nfloat upperValue; public RangeChangedEventArgs(nfloat lowerValue, nfloat upperValue) { this.lowerValue = lowerValue; this.upperValue = upperValue; } public nfloat LowerValue { get { return lowerValue; } set { lowerValue = value; } } public nfloat UpperValue { get { return upperValue; } set { upperValue = value; } } } }
using CoreGraphics; using UIKit; using System.Drawing; namespace MapSuiteEarthquakeStatistics { public class RangeSliderView : UIView { private UILabel name; private UILabel lowerValue; private UILabel upperValue; public RangeSliderView(UIRangeSlider rangeSlider) { rangeSlider.RangeChanged += RangeSlider_RangeChanged; name = new UILabel(new RectangleF(0, 0, 100, 40)); lowerValue = new UILabel(new CGRect(100, 0, 50, 40)); upperValue = new UILabel(new CGRect(150 + rangeSlider.Frame.Width + 10, 0, 50, 40)); name.Text = rangeSlider.Name; lowerValue.Text = rangeSlider.LowerValue.ToString("N0"); upperValue.Text = rangeSlider.UpperValue.ToString("N0"); Add(name); Add(lowerValue); Add(rangeSlider); Add(upperValue); } void RangeSlider_RangeChanged(object sender, RangeChangedEventArgs e) { UIRangeSlider slider = (UIRangeSlider)sender; switch (slider.Name) { case "Magnitude:": Global.QueryConfiguration.LowerMagnitude = (int)e.LowerValue; Global.QueryConfiguration.UpperMagnitude = (int)e.UpperValue; break; case "Depth(KM):": Global.QueryConfiguration.LowerDepth = (int)e.LowerValue; Global.QueryConfiguration.UpperDepth = (int)e.UpperValue; break; case "Date(Year):": Global.QueryConfiguration.LowerYear = (int)e.LowerValue; Global.QueryConfiguration.UpperYear = (int)e.UpperValue; break; } lowerValue.Text = e.LowerValue.ToString("N0"); upperValue.Text = e.UpperValue.ToString("N0"); } } }
using CoreAnimation; using CoreGraphics; using Foundation; using UIKit; using System; using System.Drawing; namespace MapSuiteEarthquakeStatistics { [Register("UIRangeSlider")] public class UIRangeSlider : UIControl { private string name; private nfloat minValue; private nfloat maxValue; private nfloat lowerValue; private nfloat upperValue; private CALayer trackLayer; private CALayer rangeLayer; private CERangeSliderKnobLayer upperKnobLayer; private CERangeSliderKnobLayer lowerKnobLayer; private CGPoint previousTouchPoint; private UIColor trackColor; private nfloat curvaceousness; private nfloat knobWidth; private nfloat usableTrackLength; public event EventHandler<RangeChangedEventArgs> RangeChanged; public UIRangeSlider(RectangleF frame) : this(frame, 0, 10, 2, 8) { } public UIRangeSlider(RectangleF frame, float minValue, float maxValue, float lowerValue, float upperValue) : base(frame) { this.upperValue = upperValue; this.lowerValue = lowerValue; this.minValue = minValue; this.maxValue = maxValue; Initialize(); } public string Name { get { return name; } set { name = value; } } public nfloat LowerValue { get { return lowerValue; } set { lowerValue = value; } } public nfloat UpperValue { get { return upperValue; } set { upperValue = value; } } public nfloat Curvaceousness { get { return curvaceousness; } set { curvaceousness = value; } } public UIColor TrackColor { get { return trackColor; } set { trackColor = value; } } public override bool BeginTracking(UITouch uitouch, UIEvent uievent) { previousTouchPoint = uitouch.LocationInView(this); if (lowerKnobLayer.Frame.Contains(previousTouchPoint)) { lowerKnobLayer.Highlight = true; lowerKnobLayer.SetNeedsDisplay(); } else if (upperKnobLayer.Frame.Contains(previousTouchPoint)) { upperKnobLayer.Highlight = true; upperKnobLayer.SetNeedsDisplay(); } return lowerKnobLayer.Highlight || upperKnobLayer.Highlight; } public override bool ContinueTracking(UITouch uitouch, UIEvent uievent) { CGPoint touchPoint = uitouch.LocationInView(this); nfloat delta = touchPoint.X - previousTouchPoint.X; nfloat valueDelta = (maxValue - minValue) * delta / usableTrackLength; previousTouchPoint = touchPoint; if (lowerKnobLayer.Highlight) { lowerValue += valueDelta; lowerValue = LimitBounds(lowerValue, minValue, upperValue); } else if (upperKnobLayer.Highlight) { upperValue += valueDelta; upperValue = LimitBounds(upperValue, lowerValue, maxValue); } CATransaction.Begin(); CATransaction.DisableActions = true; SetLayerFrames(); CATransaction.Commit(); OnRangeChanged(); return true; } public override void EndTracking(UITouch uitouch, UIEvent uievent) { lowerKnobLayer.Highlight = false; upperKnobLayer.Highlight = false; lowerKnobLayer.SetNeedsDisplay(); upperKnobLayer.SetNeedsDisplay(); } protected virtual void OnRangeChanged() { EventHandler<RangeChangedEventArgs> handler = RangeChanged; if (handler != null) { handler(this, new RangeChangedEventArgs(lowerValue, upperValue)); } } public nfloat PositionForValue(nfloat value) { return usableTrackLength * (value - minValue) / (maxValue - minValue) + knobWidth / 2f; } private void Initialize() { trackColor = UIColor.FromWhiteAlpha(1f, 1); curvaceousness = 1; trackLayer = new CALayer(); trackLayer.BackgroundColor = UIColor.FromRGB(183, 183, 183).CGColor; Layer.AddSublayer(trackLayer); rangeLayer = new CALayer(); rangeLayer.BackgroundColor = UIColor.FromRGB(0, 122, 255).CGColor; Layer.AddSublayer(rangeLayer); upperKnobLayer = new CERangeSliderKnobLayer(); upperKnobLayer.Name = "Upper"; upperKnobLayer.Slider = this; Layer.AddSublayer(upperKnobLayer); lowerKnobLayer = new CERangeSliderKnobLayer(); lowerKnobLayer.Name = "Lower"; lowerKnobLayer.Slider = this; Layer.AddSublayer(lowerKnobLayer); SetLayerFrames(); } private static nfloat LimitBounds(nfloat value, nfloat minValue, nfloat maxValue) { if (value < minValue) return minValue; if (value > maxValue) return maxValue; return value; } private void SetLayerFrames() { float trackHeight = 2; trackLayer.Frame = new CGRect(0, Bounds.Height / 2f - trackHeight / 2f, Bounds.Width, trackHeight); trackLayer.SetNeedsDisplay(); knobWidth = Bounds.Height; usableTrackLength = Bounds.Size.Width - knobWidth; nfloat upperKnobCentre = PositionForValue(upperValue); SetKnobLayer(upperKnobCentre, upperKnobLayer); nfloat lowerKnobCentre = PositionForValue(lowerValue); SetKnobLayer(lowerKnobCentre, lowerKnobLayer); rangeLayer.Frame = new CGRect(lowerKnobCentre, Bounds.Height / 2f - trackHeight / 2f, upperKnobCentre - lowerKnobCentre, trackHeight); } private void SetKnobLayer(nfloat centerPosition, CERangeSliderKnobLayer layer) { layer.Frame = new CGRect(centerPosition - knobWidth / 2f, 0, knobWidth, knobWidth); layer.ShadowOffset = new SizeF(0, 3); layer.ShadowOpacity = 0.4f; layer.ShadowColor = UIColor.Gray.CGColor; layer.SetNeedsDisplay(); } } }
namespace MapSuiteEarthquakeStatistics { public enum BaseMapType { WorldMapKitRoad = 0, WorldMapKitAerial = 1, WorldMapKitAerialWithLabels = 2, OpenStreetMap = 3, BingMapsAerial = 4, BingMapsRoad = 5 } }
using System.Drawing; using Foundation; using UIKit; using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace MapSuiteEarthquakeStatistics { internal class DataTableSource : UITableViewSource { private Collection<SectionModel> sections; public Action<UITableView, NSIndexPath> RowClick; public DataTableSource() : this(null) { } public DataTableSource(IEnumerable<SectionModel> rows) { this.sections = new Collection<SectionModel>(); if (rows != null) { foreach (var item in rows) { this.sections.Add(item); } } } public Collection<SectionModel> Sections { get { return sections; } } public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { RowModel currentModel = sections[indexPath.Section].Rows[indexPath.Row]; UITableViewCell cell = tableView.DequeueReusableCell("cell") ?? new UITableViewCell(UITableViewCellStyle.Subtitle, "Cell"); switch (currentModel.CellAccessory) { case UITableViewCellAccessory.Checkmark: cell.Accessory = currentModel.IsChecked ? currentModel.CellAccessory : UITableViewCellAccessory.None; break; default: cell.Accessory = currentModel.CellAccessory; break; } cell.Tag = indexPath.Row; cell.TextLabel.Text = currentModel.Name; cell.AccessoryView = currentModel.AccessoryView; if (currentModel.CustomUI != null) { currentModel.CustomUI.Frame = currentModel.CustomUIBounds; cell.Add(currentModel.CustomUI); } return cell; } public override nint NumberOfSections(UITableView tableView) { return sections.Count; } public override nint RowsInSection(UITableView tableview, nint section) { return sections[(int)section].Rows.Count; } public override string TitleForHeader(UITableView tableView, nint section) { return sections[(int)section].Title; } public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { tableView.DeselectRow(indexPath, true); if (RowClick != null) RowClick(tableView, indexPath); } public override nfloat GetHeightForHeader(UITableView tableView, nint section) { SectionModel currentSection = sections[(int)section]; if (currentSection.HeaderHeight > 0) return currentSection.HeaderHeight; return UITableView.AutomaticDimension; } public override nfloat GetHeightForRow(UITableView tableView, NSIndexPath indexPath) { RowModel currentModel = sections[indexPath.Section].Rows[indexPath.Row]; if (currentModel.RowHeight > 0) return currentModel.RowHeight; return UITableView.AutomaticDimension; } } internal class SectionModel { private Collection<RowModel> rows; public SectionModel(string title) : this(title, null) { } public SectionModel(string title, IEnumerable<RowModel> rows) { this.Title = title; this.rows = new Collection<RowModel>(); if (rows != null) { foreach (var item in rows) { this.rows.Add(item); } } } public string Title { get; set; } public Collection<RowModel> Rows { get { return rows; } } public float HeaderHeight { get; set; } } internal class RowModel { private RectangleF customUIBounds; public RowModel(string name) : this(name, null) { } public RowModel(string name, UIImageView accessoryView) { this.Name = name; this.AccessoryView = accessoryView; } public string Name { get; set; } public bool IsChecked { get; set; } public UIView CustomUI { get; set; } public RectangleF CustomUIBounds { get { return customUIBounds; } set { customUIBounds = value; } } public float RowHeight { get; set; } public UIView AccessoryView { get; set; } public UITableViewCellAccessory CellAccessory { get; set; } } internal class EarthquakeRow { public EarthquakeRow() : this(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty) { } private EarthquakeRow(string yearValue, string longitudeValue, string latitudeValue, string depthValue, string magnitudeValue, string locationValue) { YearValue = yearValue; LongitudeValue = longitudeValue; LatitudeValue = latitudeValue; DepthValue = depthValue; MagnitudeValue = magnitudeValue; LocationValue = locationValue; } public string YearValue { get; set; } public string LongitudeValue { get; set; } public string LatitudeValue { get; set; } public string DepthValue { get; set; } public string MagnitudeValue { get; set; } public string LocationValue { get; set; } public UIImageView AccessoryView { get; set; } public override string ToString() { return string.Format("Year: {0}. At: Lon: {1}, Lat: {2}. Depth: {3}. Magnitude: {4}.", YearValue, LongitudeValue ?? string.Empty, LatitudeValue ?? string.Empty, DepthValue ?? string.Empty, MagnitudeValue ?? string.Empty); } } }
namespace MapSuiteEarthquakeStatistics { public enum DisplayType { Heat = 0, Point = 1, ISOLine = 2 } }
using UIKit; using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace MapSuiteEarthquakeStatistics { class EarthquakeToolBar : Dictionary<string, UIBarButtonItem> { private static EarthquakeToolBar instance; public event EventHandler<EventArgs> ToolBarButtonClick; private EarthquakeToolBar() { // Tool bar buttons AddBarItem(EarthquakeConstant.Cursor, "pan.png", OnToolBarButtonClick); AddBarItem(EarthquakeConstant.Polygon, "polygon.png", OnToolBarButtonClick); AddBarItem(EarthquakeConstant.Rectangle, "rectangle.png", OnToolBarButtonClick); AddBarItem(EarthquakeConstant.Clear, "recycle.png", OnToolBarButtonClick); AddBarItem(EarthquakeConstant.Search, "search.png", OnToolBarButtonClick); AddBarItem(EarthquakeConstant.Options, "options.png", OnToolBarButtonClick); this[EarthquakeConstant.FlexibleSpace] = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); } public static EarthquakeToolBar Instance { get { return instance ?? (instance = new EarthquakeToolBar()); } } public IEnumerable<UIBarButtonItem> GetToolBarItems() { Collection<UIBarButtonItem> toolBarItems = new Collection<UIBarButtonItem>(); toolBarItems.Add(Instance[EarthquakeConstant.Cursor]); toolBarItems.Add(Instance[EarthquakeConstant.Polygon]); toolBarItems.Add(Instance[EarthquakeConstant.Rectangle]); toolBarItems.Add(Instance[EarthquakeConstant.Clear]); toolBarItems.Add(Instance[EarthquakeConstant.FlexibleSpace]); toolBarItems.Add(Instance[EarthquakeConstant.Search]); toolBarItems.Add(Instance[EarthquakeConstant.Options]); return toolBarItems; } private void AddBarItem(string title, string iconPath, EventHandler handler) { UIBarButtonItem item = new UIBarButtonItem(UIImage.FromBundle(iconPath), UIBarButtonItemStyle.Bordered, handler); item.Title = title; this[title] = item; } private void OnToolBarButtonClick(object sender, EventArgs e) { EventHandler<EventArgs> handler = ToolBarButtonClick; if (handler != null) { handler(sender, e); } } } }
namespace MapSuiteEarthquakeStatistics { public class QueryConfiguration { public QueryConfiguration() { LowerMagnitude = 0; UpperMagnitude = 12; LowerDepth = 0; UpperDepth = 300; LowerYear = 1568; UpperYear = 2010; } public int LowerMagnitude { get; set; } public int UpperMagnitude { get; set; } public int LowerDepth { get; set; } public int UpperDepth { get; set; } public int LowerYear { get; set; } public int UpperYear { get; set; } } }
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("MapSuiteEarthquakeStatistics")] [assembly: AssemblyDescription("")] [assembly:|AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly:|AssemblyProduct("MapSuiteEarthquakeStatistics")] [assembly: AssemblyCopyright("Copyright © 2015")] [assembly:|AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly:|ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly:|Guid("d3718d7c-002e-4790-b466-c89f533ecd37")] // 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")]
namespace MapSuiteEarthquakeStatistics { public class EarthquakeConstant { // Tool bar buttons public const string Cursor = "Cursor"; public const string Polygon = "Polygon"; public const string Rectangle = "Rectangle"; public const string Clear = "Clear"; public const string Search = "Search"; public const string Options = "Options"; public const string FlexibleSpace = "FlexibleSpace"; } }
using System; using CoreGraphics; using UIKit; using System.Collections.Generic; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace MapSuiteEarthquakeStatistics { public static class Global { private static UIStoryboard storyboard; private static Collection<Feature> queriedFeatures; private static Dictionary<string, UIViewController> controllers; public static readonly string OpenStreetMapOverlayKey = "OpenStreetMapOverlay"; public static readonly string BingMapsAerialOverlayKey = "BingMapsAerialOverlay"; public static readonly string WorldMapKitOverlayKey = "WorldMapKitOverlay"; public static readonly string BingMapsRoadOverlayKey = "BingMapsRoadOverlay"; public static readonly string HighLightOverlayKey = "HighlightOverlay"; static Global() { QueryConfiguration = new QueryConfiguration(); controllers = new Dictionary<string, UIViewController>(); } private static UIStoryboard Storyboard { get { string storyboardName = UserInterfaceIdiomIsPhone ? "MainStoryboard_iPhone" : "MainStoryboard_iPad"; return storyboard ?? (storyboard = UIStoryboard.FromName(storyboardName, null)); } } public static bool UserInterfaceIdiomIsPhone { get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; } } public static MapView MapView { get; set; } public static string BingMapKey { get; set; } public static QueryConfiguration QueryConfiguration { get; set; } public static BaseMapType BaseMapType { get; set; } public static string BaseMapTypeString { get; set; } public static Collection<Feature> QueriedFeatures { get { return queriedFeatures ?? (queriedFeatures = new Collection<Feature>()); } } public static WorldMapKitOverlay WorldMapKitOverlay { get { return (WorldMapKitOverlay)MapView.Overlays[WorldMapKitOverlayKey]; } } public static Overlay OpenStreetMapOverlay { get { return MapView.Overlays[OpenStreetMapOverlayKey]; } } public static BingMapsOverlay BingMapsAerialOverlay { get { return (BingMapsOverlay)MapView.Overlays[BingMapsAerialOverlayKey]; } } public static BingMapsOverlay BingMapsRoadOverlay { get { return (BingMapsOverlay)MapView.Overlays[BingMapsRoadOverlayKey]; } } public static LayerOverlay HighLightOverlay { get { return (LayerOverlay)MapView.Overlays[HighLightOverlayKey]; } } public static ManagedProj4Projection GetWgs84ToMercatorProjection() { ManagedProj4Projection wgs84ToMercatorProjection = new ManagedProj4Projection(); wgs84ToMercatorProjection.InternalProjectionParametersString = ManagedProj4Projection.GetWgs84ParametersString(); wgs84ToMercatorProjection.ExternalProjectionParametersString = ManagedProj4Projection.GetBingMapParametersString(); return wgs84ToMercatorProjection; } public static void FilterSelectedEarthquakeFeatures() { InMemoryFeatureLayer selectMarkerLayer = (InMemoryFeatureLayer)HighLightOverlay.Layers["SelectMarkerLayer"]; selectMarkerLayer.InternalFeatures.Clear(); foreach (var feature in QueriedFeatures) { double year, depth, magnitude; double.TryParse(feature.ColumnValues["MAGNITUDE"], out magnitude); double.TryParse(feature.ColumnValues["DEPTH_KM"], out depth); double.TryParse(feature.ColumnValues["YEAR"], out year); if ((magnitude >= QueryConfiguration.LowerMagnitude && magnitude <= QueryConfiguration.UpperMagnitude || magnitude == -9999) && (depth <= QueryConfiguration.UpperDepth && depth >= QueryConfiguration.LowerDepth || depth == -9999) && (year >= QueryConfiguration.LowerYear && year <= QueryConfiguration.UpperYear) || year == -9999) { selectMarkerLayer.InternalFeatures.Add(feature); } } } public static UIViewController FindViewController(string viewControllerName) { if (!controllers.ContainsKey(viewControllerName)) { UIViewController controller = (UIViewController)Storyboard.InstantiateViewController(viewControllerName); controllers.Add(viewControllerName, controller); } return controllers[viewControllerName]; } public static void AnimatedShow(this UIView view) { if (Math.Abs(view.Transform.y0) < 0.001f) { nfloat y = -view.Frame.Height; UIView.Animate(0.3, () => { view.Transform = CGAffineTransform.MakeTranslation(0, y); view.Hidden = false; }); } } public static void AnimatedHide(this UIView view) { if (Math.Abs(view.Transform.y0) > 0.001f) { UIView.Animate(0.3, () => { view.Transform = CGAffineTransform.MakeTranslation(0, 0); }, () => { view.Hidden = true; }); } } } }