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 LayerSample { // 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 LayerSample { 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 MonoTouch.Dialog; using System; using System.Collections.ObjectModel; using System.Globalization; using System.Linq; using System.Reflection; using System.Xml.Linq; using UIKit; namespace LayerSample { public partial class RootViewController : UIViewController { private SliderViewController navigation; public RootViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); navigation = new SliderViewController(); navigation.Position = FlyOutPosition.Left; navigation.View.Frame = UIScreen.MainScreen.Bounds; View.AddSubview(navigation.View); AddChildViewController(navigation); RootElement root = new RootElement("Layer List"); DetailViewController rootViewController = new DetailViewController(); rootViewController.BackToMenuButtonClick = navigation.ToggleMenu; XDocument xdoc = XDocument.Load("AppData/LayerSamples.xml"); Collection<UIViewController> layerList = new Collection<UIViewController>(); if (xdoc != null) { Assembly currentAssembly = Assembly.GetExecutingAssembly(); foreach (var element in xdoc.Root.Elements()) { string name = element.Attribute("Name").Value; int sampleCount = int.Parse(element.Attribute("SampleCount").Value); Section section = new Section(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", name, sampleCount)); foreach (var sampleElement in element.Elements()) { string sampleName = sampleElement.Attribute("Name").Value; string sampleClassName = "LayerSample." + sampleElement.Attribute("Class").Value; string sampleDescription = sampleElement.Attribute("Description").Value; var result = currentAssembly.GetTypes().Select(t => t.FullName).ToList(); Type sampleType = currentAssembly.GetType(sampleClassName); BaseSample sample = (BaseSample)Activator.CreateInstance(sampleType); sample.SampleName = sampleName; section.Add(new StringElement(sampleName, sampleDescription)); rootViewController.LayerSamples.Add(sample); } root.Add(section); } } navigation.ViewController = rootViewController; navigation.NavigationRoot = root; } } }
// // This file has been generated automatically by Visual Studio to store outlets and // actions made in the Xcode designer. If it is removed, they will be lost. // Manual changes to this file may not be handled correctly. // using Foundation; namespace LayerSample { [Register("RootViewController")] partial class RootViewController { void ReleaseDesignerOutlets() { } } }
using System.Linq; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class CustomizedLayersSample : BaseSample { public CustomizedLayersSample() { BoundingBox = new RectangleShape(-96.8149783155792, 33.1369158368377, -96.8046004008134, 33.12307861715); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { ThinkGeoHeadquartersFeatureLayer thinkGeoHeadquartersFeatureLayer = new ThinkGeoHeadquartersFeatureLayer(); thinkGeoHeadquartersFeatureLayer.Name = "CustomizedLayer"; TextStyle textStyle = new TextStyle("name", (new GeoFont("Arial", 12)), new GeoSolidBrush(GeoColor.StandardColors.DarkOliveGreen)); textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.FloralWhite, 5); textStyle.SplineType = SplineType.ForceSplining; thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush = new GeoSolidBrush(new GeoColor(50, GeoColor.SimpleColors.Orange)); thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen = new GeoPen(GeoColor.SimpleColors.Black); thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.SimpleColors.Orange, 5)); thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8); thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle; thinkGeoHeadquartersFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; layerOverlay.Layers.Add(thinkGeoHeadquartersFeatureLayer); } } }
using System.Collections.Generic; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class InMemorySample : BaseSample { public InMemorySample() { BoundingBox = new RectangleShape(-96.8632815614601, 33.1842037917427, -96.7636189580416, 33.0513203205181); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); inMemoryFeatureLayer.Name = "inMemoryFeature"; IEnumerable<Feature> inMemoryLayerFeatures = SampleHelper.GetFeatures("InMemoryLayer"); foreach (var feature in inMemoryLayerFeatures) { inMemoryFeatureLayer.InternalFeatures.Add(feature); } inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue; inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 5); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8); TextStyle textStyle = new TextStyle("name", (new GeoFont("Arial", 12)), new GeoSolidBrush(GeoColor.StandardColors.DarkOliveGreen)); textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.FloralWhite, 3); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle; inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; layerOverlay.Layers.Add(inMemoryFeatureLayer); } } }
using System.Linq; using System.Collections.Generic; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class MapShapeSample : BaseSample { public MapShapeSample() { BoundingBox = new RectangleShape(-96.8149783155792, 33.1369158368377, -96.8046004008134, 33.12307861715); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { MapShapeLayer mapShapeLayer = new MapShapeLayer(); mapShapeLayer.Name = "mapShape"; TextStyle textStyle = new TextStyle("name", (new GeoFont("Arial", 12)), new GeoSolidBrush(GeoColor.StandardColors.DarkOliveGreen)); textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.FloralWhite, 5); textStyle.SplineType = SplineType.ForceSplining; GeoPen pointPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Green), 8); LineStyle lineStyle = new LineStyle(new GeoPen(GeoColor.SimpleColors.Orange, 5)); GeoPen polygonPen = new GeoPen(GeoColor.StandardColors.Transparent, 0); GeoPen polygonOutlinePen = new GeoPen(GeoColor.SimpleColors.Black); int polygonCount = 1; IEnumerable<Feature> mapShapeLayerFeatures = SampleHelper.GetFeatures("MapShapeLayer"); foreach (var feature in mapShapeLayerFeatures) { feature.GetWellKnownType(); MapShape mapShape = new MapShape(feature); switch (feature.GetWellKnownType()) { case WellKnownType.Point: mapShape.ZoomLevels.ZoomLevel01.DefaultPointStyle.SymbolPen = pointPen; mapShape.ZoomLevels.ZoomLevel01.DefaultTextStyle = textStyle; mapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapShapeLayer.MapShapes.Add(feature.Id, mapShape); break; case WellKnownType.Line: mapShape.ZoomLevels.ZoomLevel01.DefaultLineStyle = lineStyle; mapShape.ZoomLevels.ZoomLevel01.DefaultTextStyle = textStyle; mapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapShapeLayer.MapShapes.Add(feature.Id, mapShape); break; case WellKnownType.Polygon: if (polygonCount == 1) mapShape.ZoomLevels.ZoomLevel01.DefaultAreaStyle = new AreaStyle(polygonPen, new GeoSolidBrush(new GeoColor(255, 211, 226, 190))); if (polygonCount == 2) mapShape.ZoomLevels.ZoomLevel01.DefaultAreaStyle = new AreaStyle(polygonPen, new GeoSolidBrush(new GeoColor(255, 240, 240, 216))); if (polygonCount == 3) mapShape.ZoomLevels.ZoomLevel01.DefaultAreaStyle = new AreaStyle(polygonPen, new GeoSolidBrush(new GeoColor(255, 160, 207, 235))); mapShape.ZoomLevels.ZoomLevel01.DefaultTextStyle = textStyle; mapShape.ZoomLevels.ZoomLevel01.DefaultAreaStyle.OutlinePen = polygonOutlinePen; mapShape.ZoomLevels.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapShapeLayer.MapShapes.Add(feature.Id, mapShape); polygonCount++; break; } } layerOverlay.Layers.Add(mapShapeLayer); } } }
using Foundation; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class ShapefileSample : BaseSample { public ShapefileSample() { BoundingBox = new RectangleShape(-137.103712753609, 91.7147720173118, -65.1376294732061, -4.24000568989159); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer("AppData/Shapefile/USStates.shp"); shapeFileFeatureLayer.Name = "shapeFile"; shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush = new GeoSolidBrush(new GeoColor(50, GeoColor.SimpleColors.Orange)); shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen = new GeoPen(GeoColor.SimpleColors.Black); shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; layerOverlay.Layers.Add(shapeFileFeatureLayer); } } }
using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class TabSample : BaseSample { public TabSample() { BoundingBox = new RectangleShape(-137.103712753609, 91.7147720173118, -65.1376294732061, -4.24000568989159); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { TabFeatureLayer tabFeatureLayer = new TabFeatureLayer("AppData/TAB/USStates.tab"); tabFeatureLayer.Name = "tab"; tabFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush = new GeoSolidBrush(new GeoColor(50, GeoColor.SimpleColors.Orange)); tabFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen = new GeoPen(GeoColor.SimpleColors.Black); tabFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; layerOverlay.Layers.Add(tabFeatureLayer); } } }
using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class WkbSample : BaseSample { public WkbSample() { BoundingBox = new RectangleShape(-137.103712753609, 91.7147720173118, -65.1376294732061, -4.24000568989159); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { WkbFileFeatureLayer wkbFileFeatureLayer = new WkbFileFeatureLayer("AppData/Wkb/USStates.wkb"); wkbFileFeatureLayer.Name = "wkb"; wkbFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush = new GeoSolidBrush(new GeoColor(50, GeoColor.SimpleColors.Orange)); wkbFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen = new GeoPen(GeoColor.SimpleColors.Black); wkbFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; layerOverlay.Layers.Add(wkbFileFeatureLayer); } } }
using System; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public class WmsSample : BaseSample { public WmsSample() { BoundingBox = new RectangleShape(-137.103712753609, 91.7147720173118, -65.1376294732061, -4.24000568989159); } public override void LoadDynamicOverlay(LayerOverlay layerOverlay) { WmsRasterLayer wmsLayer = new WmsRasterLayer(); wmsLayer.Name = "wms"; wmsLayer.Crs = "EPSG:4326"; wmsLayer.Uri = new Uri("http://howdoiwms.thinkgeo.com/WmsServer.aspx"); wmsLayer.ActiveLayerNames.Add("COUNTRIES02"); wmsLayer.ActiveLayerNames.Add("USSTATES"); wmsLayer.ActiveLayerNames.Add("USMAJORCITIES"); wmsLayer.Parameters.Add("STYLES", "SIMPLE"); layerOverlay.Layers.Add(wmsLayer); } } }
using UIKit; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; namespace LayerSample { public abstract class BaseSample : UIViewController { private string sampleName; private RectangleShape boundingBox; static void ReloadSample() { } public string SampleName { get { return sampleName; } set { sampleName = value; } } public RectangleShape BoundingBox { get { return boundingBox; } protected set { boundingBox = value; } } public abstract void LoadDynamicOverlay(LayerOverlay layerOverlay); } }
using CoreGraphics; using Foundation; using System; using System.Collections.ObjectModel; using System.Linq; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.iOSEdition; using UIKit; namespace LayerSample { [Register("DetailViewController")] public class DetailViewController : UIViewController { protected MapView MapView; private Action backToMenuButtonClick; private BaseSample selectedSample; private Collection<BaseSample> layerSamples; public DetailViewController() { } public Action BackToMenuButtonClick { get { return backToMenuButtonClick; } set { backToMenuButtonClick = value; } } public BaseSample SelectedSample { get { return selectedSample; } set { selectedSample = value; } } public Collection<BaseSample> LayerSamples { get { return layerSamples ?? (layerSamples = new Collection<BaseSample>()); } } public override void ViewDidLoad() { base.ViewDidLoad(); InitializeToolbar(); View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; MapView = new MapView(View.Frame); MapView.MapUnit = GeographyUnit.DecimalDegree; MapView.BackgroundColor = UIColor.FromRGB(244, 242, 238); MapView.CurrentExtent = new RectangleShape(10, 20, 30, -20); MapView.MapTools.ZoomMapTool.Center = new CGPoint(MapView.MapTools.ZoomMapTool.Center.X + 10, MapView.MapTools.ZoomMapTool.Center.Y + 55); WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay(); worldOverlay.TileType = TileType.MultiTile; worldOverlay.Projection = WorldMapKitProjection.DecimalDegrees; MapView.Overlays.Insert(0, "WMK", worldOverlay); MapView.Overlays.Add("SampleLayerOverlay", new LayerOverlay()); View.AddSubview(MapView); RefreshMap(); } public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration) { base.WillAnimateRotation(toInterfaceOrientation, duration); double resolution = Math.Max(MapView.CurrentExtent.Width / MapView.Frame.Width, MapView.CurrentExtent.Height / MapView.Frame.Height); MapView.Frame = View.Bounds; MapView.CurrentExtent = GetExtentRetainScale(MapView.CurrentExtent.GetCenterPoint(), MapView.Frame, resolution); MapView.Refresh(); } public void RefreshMap() { if (MapView != null) { LayerOverlay sampleLayerOverlay = MapView.Overlays["SampleLayerOverlay"] as LayerOverlay; if (sampleLayerOverlay != null) { sampleLayerOverlay.Layers.Clear(); selectedSample.LoadDynamicOverlay(sampleLayerOverlay); MapView.CurrentExtent = selectedSample.BoundingBox; } MapView.Refresh(); } } private static RectangleShape GetExtentRetainScale(PointShape currentLocationInMecator, CGRect frame, double resolution) { double left = currentLocationInMecator.X - resolution * frame.Width * .5; double right = currentLocationInMecator.X + resolution * frame.Width * .5; double top = currentLocationInMecator.Y + resolution * frame.Height * .5; double bottom = currentLocationInMecator.Y - resolution * frame.Height * .5; return new RectangleShape(left, top, right, bottom); } private void OnBackToMenuItemClick(object sender, EventArgs e) { if (BackToMenuButtonClick != null) BackToMenuButtonClick(); } private void InitializeToolbar() { UIBarButtonItem backToMenuButton = new UIBarButtonItem(UIImage.FromBundle("detail40"), UIBarButtonItemStyle.Plain, OnBackToMenuItemClick); backToMenuButton.TintColor = UIColor.Black; NavigationItem.SetLeftBarButtonItem(backToMenuButton, true); } } }
using CoreGraphics; using Foundation; using MediaPlayer; using MonoTouch.Dialog; using ObjCRuntime; using System; using System.Drawing; using UIKit; namespace LayerSample { public enum FlyOutPosition { Left = 0, // default Right }; [Register("SilderViewController")] public class SliderViewController : UIViewController { private const float sidebarFlickVelocity = 1000.0f; private const int menuWidth = 240; private bool hideShadow; private UIButton closeButton; private FlyOutPosition position; private DialogViewController leftNavigation; private int selectedIndex; private UIView shadowView; private nfloat startX; private UIView statusImage; private DetailViewController viewController; private bool isIos7; private bool isOpen; public event UITouchEventArgs ShouldReceiveTouch; public Action SelectedIndexChanged; public SliderViewController(IntPtr handle) : base(handle) { Initialize(); } public SliderViewController(UITableViewStyle navigationStyle = UITableViewStyle.Plain) { Initialize(navigationStyle); } public FlyOutPosition Position { get { return position; } set { position = value; shadowView.Layer.ShadowOffset = new CGSize(Position == FlyOutPosition.Left ? -5 : 5, -1); } } public bool AlwaysShowLandscapeMenu { get; set; } public bool ForceMenuOpen { get; set; } public bool HideShadow { get { return hideShadow; } set { if (value == hideShadow) return; hideShadow = value; if (hideShadow) { if (mainView != null) View.InsertSubviewBelow(shadowView, mainView); } else { shadowView.RemoveFromSuperview(); } } } public UIColor ShadowViewColor { get { return shadowView.BackgroundColor; } set { shadowView.BackgroundColor = value; } } public UIViewController CurrentViewController { get; set; } public UIView mainView { get { if (CurrentViewController == null) return null; return CurrentViewController.View; } } public RootElement NavigationRoot { get { return leftNavigation.Root; } set { EnsureInvokedOnMainThread(delegate { leftNavigation.Root = value; }); } } public UITableView NavigationTableView { get { return leftNavigation.TableView; } } public DetailViewController ViewController { get { return viewController; } set { EnsureInvokedOnMainThread(delegate { viewController = value; NavigationItemSelected(GetIndexPath(SelectedIndex)); }); } } public bool IsOpen { get { if (Position == FlyOutPosition.Left) { return mainView.Frame.X == menuWidth; } else { return mainView.Frame.X == -menuWidth; } } set { isOpen = value; if (value) HideMenu(); else ShowMenu(); } } public bool ShouldStayOpen { get { if (ForceMenuOpen || (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && AlwaysShowLandscapeMenu && (InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight))) return true; return false; } } public int SelectedIndex { get { return selectedIndex; } set { if (selectedIndex == value) return; selectedIndex = value; EnsureInvokedOnMainThread(delegate { NavigationItemSelected(value); }); } } public bool DisableRotation { get; set; } public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) { if (DisableRotation) return toInterfaceOrientation == InterfaceOrientation; bool theReturn = CurrentViewController == null ? true : CurrentViewController.ShouldAutorotateToInterfaceOrientation(toInterfaceOrientation); return theReturn; } public override UIInterfaceOrientationMask GetSupportedInterfaceOrientations() { if (CurrentViewController != null) return CurrentViewController.GetSupportedInterfaceOrientations(); return UIInterfaceOrientationMask.All; } public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); CGRect navFrame = View.Bounds; navFrame.Width = menuWidth; if (Position == FlyOutPosition.Right) navFrame.X = mainView.Frame.Width - menuWidth; if (leftNavigation.View.Frame != navFrame) leftNavigation.View.Frame = navFrame; } public override void ViewWillAppear(bool animated) { CGRect navFrame = leftNavigation.View.Frame; navFrame.Width = menuWidth; if (Position == FlyOutPosition.Right) navFrame.X = mainView.Frame.Width - menuWidth; navFrame.Location = PointF.Empty; leftNavigation.View.Frame = navFrame; View.BackgroundColor = NavigationTableView.BackgroundColor; var frame = mainView.Frame; setViewSize(); SetLocation(frame); base.ViewWillAppear(animated); } private void Initialize(UITableViewStyle navigationStyle = UITableViewStyle.Plain) { DisableStatusBarMoving = true; statusImage = new UIView { ClipsToBounds = true }.SetAccessibilityId("statusbar"); leftNavigation = new DialogViewController(navigationStyle, null); leftNavigation.OnSelection += NavigationItemSelected; CGRect navFrame = leftNavigation.View.Frame; navFrame.Width = menuWidth; if (Position == FlyOutPosition.Right) navFrame.X = mainView.Frame.Width - menuWidth; leftNavigation.View.Frame = navFrame; View.AddSubview(leftNavigation.View); var version = new Version(UIDevice.CurrentDevice.SystemVersion); isIos7 = version.Major >= 7; if (isIos7) { leftNavigation.TableView.TableHeaderView = new UIView(new CGRect(0, 0, 320, 22)) { BackgroundColor = UIColor.Clear }; leftNavigation.TableView.SectionHeaderHeight = 50; } leftNavigation.TableView.TableFooterView = new UIView(new CGRect(0, 0, 100, 100)) { BackgroundColor = UIColor.Clear }; leftNavigation.TableView.ScrollsToTop = false; shadowView = new UIView(); shadowView.BackgroundColor = UIColor.White; shadowView.Layer.ShadowOffset = new CGSize(Position == FlyOutPosition.Left ? -5 : 5, -1); shadowView.Layer.ShadowColor = UIColor.Black.CGColor; shadowView.Layer.ShadowOpacity = .75f; closeButton = new UIButton(); closeButton.TouchUpInside += delegate { HideMenu(); }; AlwaysShowLandscapeMenu = true; View.AddGestureRecognizer(new OpenMenuGestureRecognizer(DragContentView, shouldReceiveTouch)); } private void DragContentView(UIPanGestureRecognizer panGesture) { if (mainView == null) return; if (!HideShadow) View.InsertSubviewBelow(shadowView, mainView); leftNavigation.View.Hidden = false; CGRect frame = mainView.Frame; shadowView.Frame = frame; nfloat translation = panGesture.TranslationInView(View).X; if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.X = translation + startX; if (Position == FlyOutPosition.Left) { if (frame.X < 0) frame.X = 0; else if (frame.X > menuWidth) frame.X = menuWidth; } else { if (frame.X > 0) frame.X = 0; else if (frame.X < -menuWidth) frame.X = -menuWidth; } SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { nfloat velocity = panGesture.VelocityInView(View).X; nfloat newX = translation + startX; bool show = Math.Abs(velocity) > sidebarFlickVelocity ? velocity > 0 : newX > (menuWidth / 2); if (Position == FlyOutPosition.Right) { show = Math.Abs(velocity) > sidebarFlickVelocity ? velocity < 0 : newX < -(menuWidth / 2); } if (show) { ShowMenu(); } else { HideMenu(); } } } private bool shouldReceiveTouch(UIGestureRecognizer gesture, UITouch touch) { if (ShouldReceiveTouch != null) return ShouldReceiveTouch(gesture, touch); return true; } private void NavigationItemSelected(NSIndexPath indexPath) { int index = GetIndex(indexPath); NavigationItemSelected(index); } private void NavigationItemSelected(int index) { if (selectedIndex == index && CurrentViewController != null) { HideMenu(); return; } selectedIndex = index; if (viewController == null || viewController.LayerSamples.Count <= index || index < 0) { if (SelectedIndexChanged != null) SelectedIndexChanged(); return; } if (ViewController == null) { if (SelectedIndexChanged != null) SelectedIndexChanged(); return; } if (!DisableStatusBarMoving) UIApplication.SharedApplication.SetStatusBarHidden(false, UIStatusBarAnimation.Fade); if (ChildViewControllers.Length == 0) { CurrentViewController = new UINavigationController(ViewController); CGRect frame = View.Bounds; if (isOpen) { frame.X = Position == FlyOutPosition.Left ? menuWidth : -menuWidth; frame.Width = frame.Width - frame.X; } SetLocation(frame); View.AddSubview(mainView); AddChildViewController(CurrentViewController); } ViewController.SelectedSample = ViewController.LayerSamples[selectedIndex]; ViewController.Title = viewController.SelectedSample.SampleName; ViewController.RefreshMap(); HideMenu(); if (SelectedIndexChanged != null) SelectedIndexChanged(); } private void ShowMenu() { if (mainView == null) return; EnsureInvokedOnMainThread(delegate { leftNavigation.View.Hidden = false; closeButton.Frame = mainView.Frame; shadowView.Frame = mainView.Frame; var statusFrame = statusImage.Frame; statusFrame.X = mainView.Frame.X; statusImage.Frame = statusFrame; View.AddSubview(closeButton); if (!HideShadow) View.InsertSubviewBelow(shadowView, mainView); UIView.BeginAnimations("slideMenu"); UIView.SetAnimationCurve(UIViewAnimationCurve.EaseIn); UIView.SetAnimationDuration(.3); setViewSize(); CGRect frame = mainView.Frame; frame.X = Position == FlyOutPosition.Left ? menuWidth : -menuWidth; SetLocation(frame); setViewSize(); frame = mainView.Frame; shadowView.Frame = frame; closeButton.Frame = frame; statusFrame.X = mainView.Frame.X; statusImage.Frame = statusFrame; UIView.CommitAnimations(); isOpen = true; }); } private void setViewSize() { CGRect frame = View.Bounds; if (isOpen) frame.Width -= menuWidth; if (mainView.Bounds == frame) return; mainView.Bounds = frame; } private void SetLocation(CGRect frame) { mainView.Layer.AnchorPoint = new CGPoint(.5f, .5f); frame.Y = 0; if (mainView.Frame.Location == frame.Location) return; frame.Size = mainView.Frame.Size; var center = new CGPoint(frame.Left + frame.Width / 2, frame.Top + frame.Height / 2); mainView.Center = center; shadowView.Center = center; if (Math.Abs(frame.X - 0) > float.Epsilon) { getStatus(); var statusFrame = statusImage.Frame; statusFrame.X = mainView.Frame.X; statusImage.Frame = statusFrame; } } private bool DisableStatusBarMoving { get; set; } private void getStatus() { if (DisableStatusBarMoving || !isIos7 || statusImage.Superview != null) return; var image = captureStatusBarImage(); if (image == null) return; this.View.AddSubview(statusImage); foreach (var view in statusImage.Subviews) view.RemoveFromSuperview(); statusImage.AddSubview(image); statusImage.Frame = UIApplication.SharedApplication.StatusBarFrame; UIApplication.SharedApplication.StatusBarHidden = true; } private UIView captureStatusBarImage() { try { UIView screenShot = UIScreen.MainScreen.SnapshotView(false); return screenShot; } catch (Exception ex) { return null; } } private void hideStatus() { if (!isIos7) return; statusImage.RemoveFromSuperview(); UIApplication.SharedApplication.StatusBarHidden = false; } private void HideMenu() { //if (mainView == null || mainView.Frame.X == 0) if (mainView == null) return; EnsureInvokedOnMainThread(delegate { isOpen = false; leftNavigation.FinishSearch(); closeButton.RemoveFromSuperview(); shadowView.Frame = mainView.Frame; var statusFrame = statusImage.Frame; statusFrame.X = mainView.Frame.X; statusImage.Frame = statusFrame; UIView.Animate(.5, () => { UIView.SetAnimationCurve(UIViewAnimationCurve.EaseInOut); CGRect frame = View.Bounds; frame.X = 0; setViewSize(); SetLocation(frame); shadowView.Frame = frame; statusFrame.X = 0; statusImage.Frame = statusFrame; }, hideComplete); }); } [Export("animationEnded")] private void hideComplete() { hideStatus(); shadowView.RemoveFromSuperview(); leftNavigation.View.Hidden = true; } private void ResignFirstResponders(UIView view) { if (view.Subviews == null) return; foreach (UIView subview in view.Subviews) { if (subview.IsFirstResponder) subview.ResignFirstResponder(); ResignFirstResponders(subview); } } public void ToggleMenu() { EnsureInvokedOnMainThread(delegate { if (!IsOpen && CurrentViewController != null && CurrentViewController.IsViewLoaded) ResignFirstResponders(CurrentViewController.View); if (IsOpen) HideMenu(); else ShowMenu(); }); } private int GetIndex(NSIndexPath indexPath) { int section = 0; int rowCount = 0; while (section < indexPath.Section) { rowCount += leftNavigation.Root[section].Count; section++; } return rowCount + indexPath.Row; } private NSIndexPath GetIndexPath(int index) { if (leftNavigation.Root == null) return NSIndexPath.FromRowSection(0, 0); int currentCount = 0; int section = 0; foreach (Section element in leftNavigation.Root) { if (element.Count + currentCount > index) break; currentCount += element.Count; section++; } int row = index - currentCount; return NSIndexPath.FromRowSection(row, section); } private void EnsureInvokedOnMainThread(Action action) { if (NSThread.Current.IsMainThread) { action(); return; } BeginInvokeOnMainThread(() => action() ); } } internal static class Helpers { static readonly IntPtr selAccessibilityIdentifier_Handle = Selector.GetHandle("accessibilityIdentifier"); public static UIView SetAccessibilityId(this UIView view, string id) { var nsId = NSString.CreateNative(id); return view; } } internal class OpenMenuGestureRecognizer : UIPanGestureRecognizer { public OpenMenuGestureRecognizer(Action<UIPanGestureRecognizer> callback, Func<UIGestureRecognizer, UITouch, bool> shouldReceiveTouch) : base(callback) { ShouldReceiveTouch += (sender, touch) => { bool isMovingCell = touch.View.ToString().IndexOf("UITableViewCellReorderControl", StringComparison.InvariantCultureIgnoreCase) > -1; if (touch.View is UISlider || touch.View is MPVolumeView || isMovingCell) return false; return shouldReceiveTouch(sender, touch); }; } } }
using ThinkGeo.MapSuite.Core; namespace LayerSample { public class ThinkGeoHeadquartersFeatureLayer : FeatureLayer { public ThinkGeoHeadquartersFeatureLayer() { FeatureSource = new ThinkGeoHeadquartersFeatureSource(); } } }
using System.Collections.Generic; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; namespace LayerSample { public class ThinkGeoHeadquartersFeatureSource : FeatureSource { private Collection<Feature> features; public ThinkGeoHeadquartersFeatureSource() { } protected override Collection<Feature> GetAllFeaturesCore(IEnumerable<string> returningColumnNames) { if (features == null) features = SampleHelper.GetFeatures("CustomizedLayer"); return features; } } }
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("LayerSample")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("LayerSample")] [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("70f69395-26eb-4b7e-9255-3aab6168dbc5")] // 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")]
using System.Collections.ObjectModel; using System.Linq; using System.Xml.Linq; using ThinkGeo.MapSuite.Core; namespace LayerSample { public static class SampleHelper { public static Collection<Feature> GetFeatures(string layerType) { Collection<Feature> result = new Collection<Feature>(); XElement layerData = XElement.Load("AppData/LayerData.xml"); XElement featureElements = layerData.Elements("Layer").FirstOrDefault(a => a.Attribute("type").Value.Contains(layerType)); if (featureElements != null) { foreach (var featureItem in featureElements.Elements("Feature")) { Feature feature = new Feature(featureItem.Value); XAttribute featureAttribute = featureItem.FirstAttribute; feature.ColumnValues[featureAttribute.Name.ToString()] = featureAttribute.Value; result.Add(feature); } } return result; } } }