====== Source Code iOSEditionSample Labeling.zip ======
====AppDelegate.cs====
using Foundation;
using UIKit;
namespace LabelingStyle
{
// 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)
{
}
}
}
====Main.cs====
using UIKit;
namespace LabelingStyle
{
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");
}
}
}
====MainViewController.cs====
using MonoTouch.Dialog;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using UIKit;
namespace LabelingStyle
{
public partial class MainViewController : UIViewController
{
private SliderViewController navigation;
public MainViewController(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);
XDocument xDoc = XDocument.Load("AppData/StyleList.xml");
Section section = new Section("Layer List");
if (xDoc.Root != null)
{
Collection styleList = new Collection();
foreach (var element in xDoc.Root.Elements())
{
string image = element.Attribute("Image").Value;
string className = element.Attribute("Class").Value;
string name = element.Attribute("Name").Value;
section.Add(new BadgeElement(UIImage.FromBundle(image), name));
DetailViewController rootController = (DetailViewController)Activator.CreateInstance(Assembly.GetExecutingAssembly().GetType("LabelingStyle." + className), navigation);
rootController.Title = name;
UINavigationController mainController = new UINavigationController(rootController);
styleList.Add(mainController);
}
navigation.ViewControllers = styleList.ToArray();
}
navigation.NavigationRoot = new RootElement("Layer List") { section };
}
}
}
====MainViewController.designer.cs====
// 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 LabelingStyle
{
[Register|("MainViewController")]
partial class MainViewController
{
void ReleaseDesignerOutlets ()
{
}
}
}
====CustomLabelingViewContoller.cs====
using CoreGraphics;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
public class CustomLabelingViewContoller : DetailViewController
{
private StyleSettingsController settingsController;
public CustomLabelingViewContoller(SliderViewController navigation)
: base(navigation)
{ }
protected override void InitializeMap()
{
base.InitializeMap();
MapView.MapUnit = GeographyUnit.Meter;
WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay();
worldOverlay.Projection = WorldMapKitProjection.SphericalMercator;
MapView.Overlays.Add(worldOverlay);
ShapeFileFeatureLayer customLabelingStyleLayer = new ShapeFileFeatureLayer("AppData/POIs.shp");
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromHtml("#99cc33")), new GeoPen(GeoColor.FromHtml("#666666"), 1), 7);
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = new CustomLabelStyle("Name", new GeoFont("Arail", 9, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 1);
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.Mask = new AreaStyle();
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.XOffsetInPixel = 10;
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.YOffsetInPixel = 10;
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.PointPlacement = PointPlacement.Center;
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
customLabelingStyleLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
customLabelingStyleLayer.DrawingMarginPercentage = 100;
LayerOverlay customLabelingOverlay = new LayerOverlay();
customLabelingOverlay.Layers.Add("customLabeling", customLabelingStyleLayer);
MapView.Overlays.Add("CustomLabeling", customLabelingOverlay);
MapView.ZoomTo(new PointShape(-10776995.7509839, 3908478.51869558), MapView.ZoomLevelSet.ZoomLevel18.Scale);
}
protected override void OnConfigureButtonClicked()
{
if (settingsController == null)
{
settingsController = new StyleSettingsController();
settingsController.PreferredContentSize = new CGSize(540, 620);
settingsController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
settingsController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
settingsController.StyleSettingsChanged += SettingsControllerStyleSettingsChanged;
}
PresentViewController(settingsController, true, null);
}
private void SettingsControllerStyleSettingsChanged(object sender, StyleSettingsChangedStyleSettingsControllerEventArgs e)
{
CustomLabelingStyleSettings settings = (CustomLabelingStyleSettings)e.StyleSettings;
LayerOverlay layerOverlay = (LayerOverlay)MapView.Overlays["CustomLabeling"];
FeatureLayer featureLayer = (FeatureLayer)layerOverlay.Layers["customLabeling"];
CustomLabelStyle customLabelStyle = featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle as CustomLabelStyle;
if (customLabelStyle != null)
{
customLabelStyle.MinFontSize = settings.GetMinFontSize();
customLabelStyle.MaxFontSize = settings.GetMaxFontSize();
}
layerOverlay.Refresh();
}
}
}
====LabelingLinesViewContoller.cs====
using CoreGraphics;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
public class LabelingLinesViewContoller : DetailViewController
{
private StyleSettingsController settingsController;
public LabelingLinesViewContoller(SliderViewController navigation)
: base(navigation)
{ }
protected override void InitializeMap()
{
base.InitializeMap();
MapView.MapUnit = GeographyUnit.Meter;
ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer("AppData/Street.shp");
streetLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Add(GetRoadStyle());
streetLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
streetLayer.DrawingMarginPercentage = 50;
LayerOverlay labelingLinesOverlay = new LayerOverlay();
labelingLinesOverlay.Layers.Add("street", streetLayer);
MapView.Overlays.Add("LabelingLine", labelingLinesOverlay);
MapView.ZoomTo(new PointShape(-10776995.7509839, 3908478.51869558), MapView.ZoomLevelSet.ZoomLevel17.Scale);
}
protected override void OnConfigureButtonClicked()
{
if (settingsController == null)
{
settingsController = new StyleSettingsController();
settingsController.PreferredContentSize = new CGSize(540, 620);
settingsController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
settingsController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
settingsController.StyleSettingsChanged += SettingsControllerStyleSettingsChanged;
}
PresentViewController(settingsController, true, null);
}
private void SettingsControllerStyleSettingsChanged(object sender, StyleSettingsChangedStyleSettingsControllerEventArgs e)
{
LabelingLinesStyleSettings settings = (LabelingLinesStyleSettings)e.StyleSettings;
LayerOverlay layerOverlay = (LayerOverlay)MapView.Overlays["LabelingLine"];
FeatureLayer featureLayer = (FeatureLayer)layerOverlay.Layers["street"];
ClassBreakStyle classBreakStyle = featureLayer.ZoomLevelSet.ZoomLevel10.CustomStyles[0] as ClassBreakStyle;
if (classBreakStyle != null)
{
foreach (var classBreak in classBreakStyle.ClassBreaks)
{
classBreak.DefaultTextStyle.SplineType = settings.SplineType;
classBreak.DefaultTextStyle.TextLineSegmentRatio = settings.GetLineSegmentRatio();
}
}
layerOverlay.Refresh();
}
private static ClassBreakStyle GetRoadStyle()
{
ClassBreakStyle roadStyle = new ClassBreakStyle("Type");
ClassBreak pwyBreak = new ClassBreak();
pwyBreak.Value = 1;
pwyBreak.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#544c63"), 12f), new GeoPen(GeoColor.FromHtml("#9e98b0"), 8f));
pwyBreak.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 12, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
pwyBreak.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 2);
pwyBreak.DefaultTextStyle.Mask = new AreaStyle();
pwyBreak.DefaultTextStyle.BestPlacement = true;
roadStyle.ClassBreaks.Add(pwyBreak);
ClassBreak mainRoad = new ClassBreak();
mainRoad.Value = 4;
mainRoad.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#544c63"), 10f), new GeoPen(GeoColor.FromHtml("#e9cab0"), 7f));
mainRoad.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
mainRoad.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 1);
mainRoad.DefaultTextStyle.Mask = new AreaStyle();
mainRoad.DefaultTextStyle.BestPlacement = true;
roadStyle.ClassBreaks.Add(mainRoad);
ClassBreak localRoadBreak = new ClassBreak();
localRoadBreak.Value = 5;
localRoadBreak.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#bba7a2"), 6f), new GeoPen(GeoColor.FromHtml("#ffffff"), 4f));
localRoadBreak.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 8, DrawingFontStyles.Regular), new GeoSolidBrush(GeoColor.SimpleColors.Black));
localRoadBreak.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 2);
localRoadBreak.DefaultTextStyle.Mask = new AreaStyle();
localRoadBreak.DefaultTextStyle.BestPlacement = true;
roadStyle.ClassBreaks.Add(localRoadBreak);
return roadStyle;
}
}
}
====LabelingPointsViewContoller.cs====
using CoreGraphics;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
public class LabelingPointsViewContoller : DetailViewController
{
private StyleSettingsController settingsController;
public LabelingPointsViewContoller(SliderViewController navigation)
: base(navigation)
{ }
protected override void InitializeMap()
{
base.InitializeMap();
MapView.MapUnit = GeographyUnit.Meter;
WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay();
worldOverlay.Projection = WorldMapKitProjection.SphericalMercator;
MapView.Overlays.Add("WMK", worldOverlay);
ShapeFileFeatureLayer poiLayer = new ShapeFileFeatureLayer("AppData/POIs.shp");
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromHtml("#99cc33")), new GeoPen(GeoColor.FromHtml("#666666"), 1), 7);
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = new TextStyle("Name", new GeoFont("Arail", 9, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 2);
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.Mask = new AreaStyle();
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.XOffsetInPixel = 0;
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.YOffsetInPixel = 8;
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.PointPlacement = PointPlacement.UpperCenter;
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
poiLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
poiLayer.DrawingMarginPercentage = 100;
LayerOverlay labelingPointsOverlay = new LayerOverlay();
labelingPointsOverlay.Layers.Add("poi", poiLayer);
MapView.Overlays.Add("LabelingPoints", labelingPointsOverlay);
MapView.ZoomTo(new PointShape(-10776995.7509839, 3908478.51869558), MapView.ZoomLevelSet.ZoomLevel18.Scale);
}
protected override void OnConfigureButtonClicked()
{
if (settingsController == null)
{
settingsController = new StyleSettingsController();
settingsController.PreferredContentSize = new CGSize(540, 620);
settingsController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
settingsController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
settingsController.StyleSettingsChanged += SettingsControllerStyleSettingsChanged;
}
PresentViewController(settingsController, true, null);
}
private void SettingsControllerStyleSettingsChanged(object sender, StyleSettingsChangedStyleSettingsControllerEventArgs e)
{
LayerOverlay layerOverlay = (LayerOverlay)MapView.Overlays["LabelingPoints"];
FeatureLayer poiLayer = (FeatureLayer)layerOverlay.Layers["poi"];
LabelingPointsStyleSettings settings = (LabelingPointsStyleSettings)e.StyleSettings;
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.PointPlacement = settings.Placement;
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.XOffsetInPixel = settings.GetXOffset();
poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.YOffsetInPixel = settings.GetYOffset();
layerOverlay.Refresh();
}
}
}
====LabelingPolygonsViewContoller.cs====
using CoreGraphics;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
public class LabelingPolygonsViewContoller : DetailViewController
{
private StyleSettingsController settingsController;
public LabelingPolygonsViewContoller(SliderViewController navigation)
: base(navigation)
{ }
protected override void InitializeMap()
{
base.InitializeMap();
MapView.MapUnit = GeographyUnit.Meter;
WkbFileFeatureLayer subdivisionsLayer = new WkbFileFeatureLayer("AppData/WkbFiles/Subdivisions.wkb");
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.White, GeoColor.FromHtml("#9C9C9C"), 1);
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = new TextStyle("NAME_COMMO", new GeoFont("Arail", 9, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 1);
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.Mask = new AreaStyle();
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.BestPlacement = true;
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.GridSize = 3000;
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.DuplicateRule = LabelDuplicateRule.NoDuplicateLabels;
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.SuppressPartialLabels = true;
subdivisionsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
LayerOverlay labelingPolygonsOverlay = new LayerOverlay();
labelingPolygonsOverlay.Layers.Add("subdivision", subdivisionsLayer);
MapView.Overlays.Add("LabelingPolygons", labelingPolygonsOverlay);
MapView.ZoomTo(new PointShape(-10776995.7509839, 3908478.51869558), MapView.ZoomLevelSet.ZoomLevel17.Scale);
}
protected override void OnConfigureButtonClicked()
{
if (settingsController == null)
{
settingsController = new StyleSettingsController();
settingsController.PreferredContentSize = new CGSize(540, 620);
settingsController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
settingsController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
settingsController.StyleSettingsChanged += SettingsControllerStyleSettingsChanged;
}
PresentViewController(settingsController, true, null);
}
private void SettingsControllerStyleSettingsChanged(object sender, StyleSettingsChangedStyleSettingsControllerEventArgs e)
{
LabelingPolygonsStyleSettings settings = (LabelingPolygonsStyleSettings)e.StyleSettings;
LayerOverlay layerOverlay = (LayerOverlay)MapView.Overlays["LabelingPolygons"];
FeatureLayer featureLayer = (FeatureLayer)layerOverlay.Layers["subdivision"];
featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.FittingPolygonFactor = settings.FittingFactorsOnlyWithin ? 2 : 0;
featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.LabelAllPolygonParts = settings.LabelAllPolygonParts;
layerOverlay.Refresh();
}
}
}
====LabelStylingViewController.cs====
using CoreGraphics;
using System.Collections.Generic;
using System.Linq;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
public class LabelStylingViewController : DetailViewController
{
private static Dictionary gridSizeDictionary;
private StyleSettingsController settingsController;
static LabelStylingViewController()
{
gridSizeDictionary = new Dictionary();
gridSizeDictionary["Small"] = 100;
gridSizeDictionary["Medium"] = 500;
gridSizeDictionary["Large"] = 1000;
}
public LabelStylingViewController(SliderViewController navigation)
: base(navigation)
{ }
protected override void InitializeMap()
{
base.InitializeMap();
MapView.MapUnit = GeographyUnit.Meter;
WkbFileFeatureLayer parcelLayer = new WkbFileFeatureLayer("AppData/WkbFiles/Parcels.wkb");
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.FromHtml("#666666"), 2), new GeoSolidBrush(GeoColor.SimpleColors.White), PenBrushDrawingOrder.PenFirst);
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = new TextStyle("X_REF", new GeoFont("Arail", 6, DrawingFontStyles.Regular), new GeoSolidBrush(GeoColor.FromHtml("#7b7b78")));
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.DuplicateRule = LabelDuplicateRule.NoDuplicateLabels;
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.GridSize = 1000;
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 1);
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.Mask = new AreaStyle();
parcelLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;
parcelLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
parcelLayer.DrawingMarginPercentage = 50;
ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer("AppData/Street.shp");
streetLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Add(GetRoadStyle());
streetLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
streetLayer.DrawingMarginPercentage = 50;
ShapeFileFeatureLayer restaurantsLayer = new ShapeFileFeatureLayer("AppData/POIs.shp");
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromHtml("#99cc33")), new GeoPen(GeoColor.FromHtml("#666666"), 1), 7);
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle = new TextStyle("Name", new GeoFont("Arail", 9, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 1);
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.XOffsetInPixel = 10;
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.Mask = new AreaStyle(new GeoPen(GeoColor.FromHtml("#999999"), 1), new GeoSolidBrush(new GeoColor(100, GeoColor.FromHtml("#cccc99"))), PenBrushDrawingOrder.PenFirst);
restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.OverlappingRule = LabelOverlappingRule.AllowOverlapping;
restaurantsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
restaurantsLayer.DrawingMarginPercentage = 50;
LayerOverlay labelingStyleOverlay = new LayerOverlay();
labelingStyleOverlay.Layers.Add("parcel", parcelLayer);
labelingStyleOverlay.Layers.Add("street", streetLayer);
labelingStyleOverlay.Layers.Add("poi", restaurantsLayer);
MapView.Overlays.Add("LabelingStyle", labelingStyleOverlay);
MapView.ZoomTo(new PointShape(-10776995.7509839, 3908478.51869558), MapView.ZoomLevelSet.ZoomLevel18.Scale);
}
protected override void OnConfigureButtonClicked()
{
if (settingsController == null)
{
settingsController = new StyleSettingsController();
settingsController.PreferredContentSize = new CGSize(540, 620);
settingsController.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
settingsController.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
settingsController.StyleSettingsChanged += SettingsControllerStyleSettingsChanged;
}
PresentViewController(settingsController, true, null);
}
private void SettingsControllerStyleSettingsChanged(object sender, StyleSettingsChangedStyleSettingsControllerEventArgs e)
{
LabelStylingStyleSettings settings = (LabelStylingStyleSettings)e.StyleSettings;
LayerOverlay layerOverlay = (LayerOverlay)MapView.Overlays["LabelingStyle"];
UpdateLabelStylingOverlay(layerOverlay, settings);
layerOverlay.Refresh();
}
private static void UpdateLabelStylingOverlay(LayerOverlay layerOverlay, LabelStylingStyleSettings settings)
{
string gridSize = settings.GridSize.ToString();
bool useHalopen = settings.ApplyOutlineColor;
bool useMask = settings.ApplyBackgroundMask;
bool allowOverlapping = settings.LabelsOverlappingEachOther;
LabelDuplicateRule labelDuplicateRule = settings.DuplicateRule;
double drawingMarginPercentage = settings.GetDrawingMarginPercentage();
int gridSizeValue = gridSizeDictionary[gridSize];
ShapeFileFeatureLayer featureLayer = (ShapeFileFeatureLayer)layerOverlay.Layers["poi"];
List textStyles = new List();
if (featureLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Count > 0)
{
ClassBreakStyle classBreakStyle = featureLayer.ZoomLevelSet.ZoomLevel10.CustomStyles[0] as ClassBreakStyle;
textStyles.AddRange(classBreakStyle.ClassBreaks.Select(c => c.DefaultTextStyle));
}
else
{
textStyles.Add(featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle);
}
foreach (var textStyle in textStyles)
{
int r = textStyle.HaloPen.Color.RedComponent;
int g = textStyle.HaloPen.Color.GreenComponent;
int b = textStyle.HaloPen.Color.BlueComponent;
if (useHalopen)
{
textStyle.HaloPen = new GeoPen(GeoColor.FromArgb(255, r, g, b), textStyle.HaloPen.Width);
}
else
{
textStyle.HaloPen = new GeoPen(GeoColor.FromArgb(0, r, g, b), textStyle.HaloPen.Width);
}
textStyle.Mask.IsActive = useMask;
textStyle.GridSize = gridSizeValue;
textStyle.DuplicateRule = labelDuplicateRule;
textStyle.OverlappingRule = allowOverlapping ? LabelOverlappingRule.AllowOverlapping : LabelOverlappingRule.NoOverlapping;
featureLayer.DrawingMarginPercentage = drawingMarginPercentage;
}
}
private static ClassBreakStyle GetRoadStyle()
{
ClassBreakStyle roadStyle = new ClassBreakStyle("Type");
ClassBreak pwyBreak = new ClassBreak();
pwyBreak.Value = 1;
pwyBreak.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#544c63"), 12f), new GeoPen(GeoColor.FromHtml("#9e98b0"), 8f));
pwyBreak.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 12, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
pwyBreak.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 2);
pwyBreak.DefaultTextStyle.Mask = new AreaStyle();
roadStyle.ClassBreaks.Add(pwyBreak);
ClassBreak mainRoad = new ClassBreak();
mainRoad.Value = 4;
mainRoad.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#544c63"), 10f), new GeoPen(GeoColor.FromHtml("#e9cab0"), 7f));
mainRoad.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 10, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.SimpleColors.Black));
mainRoad.DefaultTextStyle.HaloPen = new GeoPen(GeoColor.SimpleColors.White, 1);
mainRoad.DefaultTextStyle.Mask = new AreaStyle();
roadStyle.ClassBreaks.Add(mainRoad);
ClassBreak localRoadBreak = new ClassBreak();
localRoadBreak.Value = 5;
localRoadBreak.DefaultLineStyle = new LineStyle(new GeoPen(GeoColor.FromHtml("#bba7a2"), 8f), new GeoPen(GeoColor.FromHtml("#ffffff"), 6f));
localRoadBreak.DefaultTextStyle = new TextStyle("ROAD_NAME", new GeoFont("Arial", 8, DrawingFontStyles.Regular), new GeoSolidBrush(GeoColor.SimpleColors.Black));
localRoadBreak.DefaultTextStyle.Mask = new AreaStyle();
roadStyle.ClassBreaks.Add(localRoadBreak);
return roadStyle;
}
}
}
====DetailViewController.cs====
using CoreGraphics;
using Foundation;
using System;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.iOSEdition;
using UIKit;
namespace LabelingStyle
{
[Register("DetailViewController")]
public class DetailViewController : UIViewController
{
private UIBarButtonItem rightSettingItem;
protected MapView MapView;
public DetailViewController()
: this(null)
{
}
public DetailViewController(SliderViewController navigation)
{
UIBarButtonItem leftDetailItem = new UIBarButtonItem(UIImage.FromBundle("detail40"), UIBarButtonItemStyle.Plain, delegate { navigation.ToggleMenu(); });
leftDetailItem.TintColor = UIColor.Black;
NavigationItem.SetLeftBarButtonItem(leftDetailItem, true);
rightSettingItem = new UIBarButtonItem(UIImage.FromBundle("settings40"), UIBarButtonItemStyle.Plain, null);
rightSettingItem.TintColor = UIColor.Black;
rightSettingItem.Clicked += RightSettingItem_Clicked;
NavigationItem.SetRightBarButtonItem(rightSettingItem, true);
}
private void RightSettingItem_Clicked(object sender, EventArgs e)
{
OnConfigureButtonClicked();
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
InitializeMap();
}
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();
}
protected virtual void InitializeMap()
{
MapView = new MapView(View.Frame);
MapView.BackgroundColor = UIColor.FromRGB(244, 242, 238);
MapView.MapTools.ZoomMapTool.Center = new CGPoint(MapView.MapTools.ZoomMapTool.Center.X + 10, MapView.MapTools.ZoomMapTool.Center.Y + 55);
View.AddSubview(MapView);
}
protected virtual void OnConfigureButtonClicked()
{ }
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);
}
}
}
====SliderViewController.cs====
using CoreGraphics;
using MonoTouch.Dialog;
using Foundation;
using MediaPlayer;
using ObjCRuntime;
using UIKit;
using System;
using System.Drawing;
namespace LabelingStyle
{
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 UIViewController[] viewControllers;
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 UIViewController[] ViewControllers
{
get { return viewControllers; }
set
{
EnsureInvokedOnMainThread(delegate
{
viewControllers = 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.Y += UIApplication.SharedApplication.StatusBarFrame.Height;
// navFrame.Height -= navFrame.Y;
//this.statusbar
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 (ShouldStayOpen || mainView == null)
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)
{
selectedIndex = index;
if (viewControllers == null || viewControllers.Length <= index || index < 0)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged();
return;
}
if (ViewControllers[index] == null)
{
if (SelectedIndexChanged != null)
SelectedIndexChanged();
return;
}
if (!DisableStatusBarMoving)
//if (!DisableStatusBarMoving && !ShouldStayOpen)
UIApplication.SharedApplication.SetStatusBarHidden(false, UIStatusBarAnimation.Fade);
//bool isOpen = false;
//if (mainView != null)
//{
// mainView.RemoveFromSuperview();
// isOpen = IsOpen;
//}
//isOpen = false;
CurrentViewController = ViewControllers[SelectedIndex];
CGRect frame = View.Bounds;
//if (isOpen || ShouldStayOpen)
if (isOpen)
{
frame.X = Position == FlyOutPosition.Left ? menuWidth : -menuWidth;
frame.Width = frame.Width - frame.X;
}
//setViewSize();
SetLocation(frame);
View.AddSubview(mainView);
AddChildViewController(CurrentViewController);
//if (!ShouldStayOpen)
HideMenu();
if (SelectedIndexChanged != null)
SelectedIndexChanged();
}
//bool isOpen {get{ return mainView.Frame.X == menuWidth; }}
private void ShowMenu()
{
if (mainView == null)
return;
EnsureInvokedOnMainThread(delegate
{
//navigation.ReloadData ();
//isOpen = true;
leftNavigation.View.Hidden = false;
closeButton.Frame = mainView.Frame;
shadowView.Frame = mainView.Frame;
var statusFrame = statusImage.Frame;
statusFrame.X = mainView.Frame.X;
statusImage.Frame = statusFrame;
//if (!ShouldStayOpen)
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;
//frame.Location = PointF.Empty;
//if (ShouldStayOpen)
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 || ShouldStayOpen)
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);
}
//public override void DidRotate(UIInterfaceOrientation fromInterfaceOrientation)
//{
// base.DidRotate(fromInterfaceOrientation);
// if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
// return;
// switch (InterfaceOrientation)
// {
// case UIInterfaceOrientation.LandscapeLeft:
// case UIInterfaceOrientation.LandscapeRight:
// ShowMenu();
// break;
// default:
// HideMenu();
// break;
// }
//}
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);
//Messaging.void_objc_msgSend_IntPtr(view.Handle, selAccessibilityIdentifier_Handle, nsId);
return view;
}
}
internal class OpenMenuGestureRecognizer : UIPanGestureRecognizer
{
public OpenMenuGestureRecognizer(Action callback, Func shouldReceiveTouch)
: base(callback)
{
ShouldReceiveTouch += (sender, touch) =>
{
//Ugly hack to ignore touches that are on a cell that is moving...
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);
};
}
}
}
====CustomLabelingStyleSettings.cs====
using MonoTouch.Dialog;
namespace LabelingStyle
{
public class CustomLabelingStyleSettings : StyleSettings
{
public CustomLabelingStyleSettings()
{
Title = "Custom Labeling Edit Settings";
MinFontSize = "8";
MaxFontSize = "25";
}
[Entry("Min|Font Size")]
public string MinFontSize;
[Entry("Max|Font Size")]
public string MaxFontSize;
public override void Sync()
{
MinFontSize = GetEntryElementValue(0);
MaxFontSize = GetEntryElementValue(1);
}
public float GetMinFontSize()
{
return ParseToFloat(MinFontSize, 8);
}
public float GetMaxFontSize()
{
return ParseToFloat(MaxFontSize, 25);
}
}
}
====CustomLabelStyle.cs====
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using ThinkGeo.MapSuite.Core;
namespace LabelingStyle
{
[Serializable]
public class CustomLabelStyle : TextStyle
{
private float minFontSize;
private float maxFontSize;
public CustomLabelStyle(string textColumnName, GeoFont textFont, GeoSolidBrush textSolidBrush)
: base(textColumnName, textFont, textSolidBrush)
{
this.minFontSize = 8;
this.MaxFontSize = 60;
}
public float MinFontSize
{
get { return minFontSize; }
set { minFontSize = value; }
}
public float MaxFontSize
{
get { return maxFontSize; }
set { maxFontSize = value; }
}
protected override void DrawCore(IEnumerable features, GeoCanvas canvas, Collection labelsInThisLayer, Collection labelsInAllLayers)
{
TextStyle clonedStyle = new TextStyle(this.TextColumnName, this.Font, this.TextSolidBrush);
clonedStyle.HaloPen = this.HaloPen;
clonedStyle.Mask = this.Mask;
clonedStyle.GridSize = this.GridSize;
clonedStyle.OverlappingRule = this.OverlappingRule;
clonedStyle.DuplicateRule = this.DuplicateRule;
float fontSize = Convert.ToInt32(50000 / canvas.CurrentScale);
if (fontSize < minFontSize)
{
fontSize = minFontSize;
}
else if (fontSize > maxFontSize)
{
fontSize = maxFontSize;
}
clonedStyle.Font = new GeoFont(clonedStyle.Font.FontName, fontSize, clonedStyle.Font.Style);
clonedStyle.Draw(features, canvas, labelsInThisLayer, labelsInAllLayers);
}
}
}
====LabelingLinesStyleSettings.cs====
using MonoTouch.Dialog;
using ThinkGeo.MapSuite.Core;
namespace LabelingStyle
{
public class LabelingLinesStyleSettings : StyleSettings
{
public LabelingLinesStyleSettings()
{
Title = "Labeling Lines Edit Settings";
SplineType = SplineType.ForceSplining;
LineSegmentRatio = "0.9";
}
[Caption("Spline|Type")]
public SplineType SplineType;
[Entry("Line|Segment Ratio")]
public string LineSegmentRatio;
public override void Sync()
{
SplineType = GetRadioElementValue(0);
LineSegmentRatio = GetEntryElementValue(1);
}
public double GetLineSegmentRatio()
{
return ParseToDouble(LineSegmentRatio, 0.9);
}
}
}
====LabelingPointsStyleSettings.cs====
using MonoTouch.Dialog;
using ThinkGeo.MapSuite.Core;
namespace LabelingStyle
{
public class LabelingPointsStyleSettings : StyleSettings
{
public LabelingPointsStyleSettings()
{
Title = "Custom Labeling Edit Settings";
Placement = PointPlacement.UpperCenter;
XOffset = "0";
YOffset = "8";
}
[Caption("Placement")]
public PointPlacement Placement;
[Entry("XOffset")]
public string XOffset;
[Entry("YOffset")]
public string YOffset;
public override void Sync()
{
Placement = GetRadioElementValue(0);
XOffset = GetEntryElementValue(1);
YOffset = GetEntryElementValue(2);
}
public float GetXOffset()
{
return ParseToFloat(XOffset, 0f);
}
public float GetYOffset()
{
return ParseToFloat(YOffset, 8f);
}
}
}
====LabelingPolygonsStyleSettings.cs====
using MonoTouch.Dialog;
namespace LabelingStyle
{
public class LabelingPolygonsStyleSettings : StyleSettings
{
public LabelingPolygonsStyleSettings()
{
Title = "Labeling Polygons Edit Settings";
FittingFactorsOnlyWithin = true;
}
[Checkbox]
[Caption("Fitting|Factors Only Within")]
public bool FittingFactorsOnlyWithin;
[Checkbox]
[Caption("Label|All Polygon Parts")]
public bool LabelAllPolygonParts;
public override void Sync()
{
FittingFactorsOnlyWithin = GetCheckBoxElementValue(0);
LabelAllPolygonParts = GetCheckBoxElementValue(1);
}
}
}
====LabelStylingStyleSettings.cs====
using MonoTouch.Dialog;
using ThinkGeo.MapSuite.Core;
namespace LabelingStyle
{
public class LabelStylingStyleSettings : StyleSettings
{
public LabelStylingStyleSettings()
{
Title = "Label Styling Settings";
ApplyOutlineColor = true;
ApplyBackgroundMask = true;
LabelsOverlappingEachOther = false;
GridSize = LabelGridSize.Large;
DuplicateRule = LabelDuplicateRule.NoDuplicateLabels;
DrawingMarginPercentage = "300";
}
[Checkbox]
[Caption("Apply|Outline Color")]
public bool ApplyOutlineColor;
[Checkbox]
[Caption("Apply|Background Mask")]
public bool ApplyBackgroundMask;
[Checkbox]
[Caption("Labels|Overlapping Each Other")]
public bool LabelsOverlappingEachOther;
[Caption("Grid|Size")]
public LabelGridSize GridSize;
[Caption("Duplicate|Rule")]
public LabelDuplicateRule DuplicateRule;
[Entry("Drawing|Margins")]
[Caption("Drawing|Margins")]
public string DrawingMarginPercentage;
public override void Sync()
{
ApplyOutlineColor = GetCheckBoxElementValue(0);
ApplyBackgroundMask = GetCheckBoxElementValue(1);
LabelsOverlappingEachOther = GetCheckBoxElementValue(2);
GridSize = GetRadioElementValue(3);
DuplicateRule = GetRadioElementValue(4);
DrawingMarginPercentage = GetEntryElementValue(5);
}
public double GetDrawingMarginPercentage()
{
return ParseToDouble(DrawingMarginPercentage, 300);
}
}
public enum LabelGridSize
{
Small = 0,
Medium = 1,
Large = 2
}
}
====StyleSettingsChangedStyleSettingsControllerEventArgs.cs====
using System;
namespace LabelingStyle
{
public class StyleSettingsChangedStyleSettingsControllerEventArgs : EventArgs
{
private StyleSettings styleSettings;
public StyleSettingsChangedStyleSettingsControllerEventArgs(StyleSettings styleSettings)
{
this.styleSettings = styleSettings;
}
public StyleSettings StyleSettings
{
get { return styleSettings; }
set { styleSettings = value; }
}
}
}
====StyleSettingsController.cs====
using MonoTouch.Dialog;
using UIKit;
using System;
namespace LabelingStyle
{
public class StyleSettingsController : UINavigationController where T : StyleSettings, new()
{
private T styleSettings;
public event EventHandler StyleSettingsChanged;
public StyleSettingsController()
: this(new T())
{
}
public StyleSettingsController(T setting)
{
styleSettings = setting;
Title = styleSettings.Title;
BindingContext context = new BindingContext(this, styleSettings, styleSettings.Title);
styleSettings.BindingContext = context;
DialogViewController dialogViewController = new DialogViewController(context.Root);
UIBarButtonItem cancelItem = new UIBarButtonItem("Cancel", UIBarButtonItemStyle.Plain, new EventHandler((s, e) => DismissViewController(true, null)));
UIBarButtonItem saveItem = new UIBarButtonItem("Save", UIBarButtonItemStyle.Plain, new EventHandler((s, e) => OnStyleSettingsChanged()));
dialogViewController.NavigationItem.SetRightBarButtonItem(saveItem, true);
dialogViewController.NavigationItem.SetLeftBarButtonItem(cancelItem, true);
PushViewController(dialogViewController, true);
}
public T StyleSettings
{
get { return styleSettings; }
}
protected void OnStyleSettingsChanged()
{
EventHandler handler = StyleSettingsChanged;
if (handler != null)
{
styleSettings.Sync();
handler(this, new StyleSettingsChangedStyleSettingsControllerEventArgs(styleSettings));
DismissViewController(true, null);
}
}
}
}
====StyleSettings.cs====
using MonoTouch.Dialog;
using System;
namespace LabelingStyle
{
public abstract class StyleSettings
{
public string Title;
private BindingContext bindingContext;
public StyleSettings()
{
}
public RootElement Root
{
get { return bindingContext.Root; }
}
public BindingContext BindingContext
{
get { return bindingContext; }
set { bindingContext = value; }
}
public virtual void Sync()
{
}
protected bool GetCheckBoxElementValue(int index)
{
return ((CheckboxElement)Root[0][index]).Value;
}
protected string GetEntryElementValue(int index)
{
EntryElement element = (EntryElement) Root[0][index];
//element.FetchValue();
bindingContext.Fetch();
return element.Value;
}
protected T GetRadioElementValue(int index)
{
RootElement subRoot = (RootElement)Root[0][index];
RadioElement radioElement = (RadioElement)subRoot[0][subRoot.RadioSelected];
return (T)Enum.Parse(typeof(T), radioElement.Caption.Replace(" ", string.Empty));
}
protected static double ParseToDouble(string content, double defaultValue)
{
double temp;
double result = defaultValue;
if (double.TryParse(content, out temp))
{
result = temp;
}
return result;
}
protected static int ParseToInt(string content, int defaultValue)
{
int temp;
int result = defaultValue;
if (int.TryParse(content, out temp))
{
result = temp;
}
return result;
}
protected static float ParseToFloat(string content, float defaultValue)
{
float temp;
float result = defaultValue;
if (float.TryParse(content, out temp))
{
result = temp;
}
return result;
}
}
}
====AssemblyInfo.cs====
using System.Reflection;
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("LabelingStyle")]
[assembly: AssemblyDescription("")]
[assembly:|AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly:|AssemblyProduct("LabelingStyle")]
[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("84efb68d-6dbd-4d6e-a2e8-f4ef414d8ee0")]
// 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("9.0.0.0")]
[assembly:|AssemblyFileVersion("9.0.0.0")]