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 System.Reflection; using Android.App; using Android.Content; using Android.OS; using Android.Views; using Android.Widget; using System; using System.Collections.ObjectModel; using System.Linq; using System.Xml.Linq; namespace LabelingStyle { [Activity(Label|= "Label Style", Icon = "@drawable/Icon", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden | Android.Content.PM.ConfigChanges.ScreenSize)] public class MainActivity : Activity { private BaseSample currentSample; private ListView sampleListView; private SliderView sampleListContainer; private Collection<BaseSample> samples; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.Main); sampleListContainer = FindViewById<SliderView>(Resource.Id.slider_view); sampleListView = FindViewById<ListView>(Resource.Id.sampleListView); InitializeSmapleListView(); currentSample = samples.FirstOrDefault(); currentSample.UpdateSampleLayout(); sampleListContainer.MainView.AddView(currentSample.SampleView); FindViewById<ImageButton>(Resource.Id.sampleListMoreButton).Click += OnMoreButtonClick; } private void sampleListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { currentSample.DisposeMap(); currentSample = samples[e.Position]; currentSample.UpdateSampleLayout(); sampleListContainer.SetSlided(false); sampleListContainer.MainView.RemoveAllViews(); sampleListContainer.MainView.AddView(currentSample.SampleView); } private void InitializeSmapleListView() { samples = new Collection<BaseSample>(); XDocument xDoc = XDocument.Load(Assets.Open("StyleList.xml")); if (xDoc.Root != null) { 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; BaseSample sample = (BaseSample)Activator.CreateInstance(Assembly.GetExecutingAssembly().GetType("LabelingStyle." + className), this); sample.Title = name; sample.ImageId = (int)typeof(Resource.Drawable).GetField(image).GetValue(null); sample.SampleListButtonClick += (s, e) => sampleListContainer.SetSlided(!sampleListContainer.IsSlided()); samples.Add(sample); } } SampleListItemAdapter adapter = new SampleListItemAdapter(this, samples); sampleListView.Adapter = adapter; sampleListView.ItemClick += sampleListView_ItemClick; } private void OnMoreButtonClick(object sender, EventArgs eventArgs) { Intent helpIntent = new Intent(Intent.ActionView, Android.Net.Uri.Parse("http://www.thinkgeo.com")); StartActivity(helpIntent); } } }
using Android.App; using Android.OS; using Android.Widget; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Threading.Tasks; namespace LabelingStyle { [Activity(Theme|= "@android:style/Theme.Light.NoTitleBar", MainLauncher = true, NoHistory = true, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden | Android.Content.PM.ConfigChanges.ScreenSize)] public class SplashActivity : Activity { private TextView uploadTextView; private ProgressBar uploadProgressBar; protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.SplashLayout); uploadTextView = FindViewById<TextView>(Resource.Id.uploadDataTextView); uploadProgressBar = FindViewById<ProgressBar>(Resource.Id.uploadProgressBar); Task updateSampleDatasTask = Task.Factory.StartNew(() => { Collection<string> unLoadDatas = CollectUnloadDatas(SampleHelper.SampleDataDictionary, SampleHelper.AssetsDataDictionary); UploadDataFiles(SampleHelper.SampleDataDictionary, unLoadDatas, OnCopyingSourceFile); uploadTextView.Post(() => { uploadTextView.Text = "Ready"; uploadProgressBar.Progress = 100; }); }); updateSampleDatasTask.ContinueWith(t => { uploadTextView.PostDelayed(() => { StartActivity(typeof(MainActivity)); Finish(); }, 200); }); } private void OnCopyingSourceFile(string targetPathFilename, int completeCount, int totalCount) { uploadTextView.Post(() => { uploadTextView.Text = string.Format("Copying {0} ({1}/{2})", Path.GetFileName(targetPathFilename), completeCount, totalCount); uploadProgressBar.Progress = (int)(completeCount * 100f / totalCount); }); } private Collection<string> CollectUnloadDatas(string targetDirectory, string sourceDirectory) { Collection<string> result = new Collection<string>(); foreach (string filename in Assets.List(sourceDirectory)) { string sourcePath = System.IO.Path.Combine(sourceDirectory, filename); string targetPath = System.IO.Path.Combine(targetDirectory, sourcePath); if (!string.IsNullOrEmpty(Path.GetExtension(sourcePath)) && !File.Exists(targetPath)) { result.Add(sourcePath); } else if (string.IsNullOrEmpty(Path.GetExtension(sourcePath))) { foreach (string item in CollectUnloadDatas(targetDirectory, sourcePath)) { result.Add(item); } } } return result; } private void UploadDataFiles(string targetDirectory, IEnumerable<string> sourcePathFilenames, Action<string, int, int> onCopyingSourceFile = null) { int completeCount = 0; if (!Directory.Exists(targetDirectory)) Directory.CreateDirectory(targetDirectory); foreach (string sourcePathFilename in sourcePathFilenames) { string targetPathFilename = Path.Combine(targetDirectory, sourcePathFilename); if (!File.Exists(targetPathFilename)) { if (onCopyingSourceFile != null) onCopyingSourceFile(targetPathFilename, completeCount, sourcePathFilenames.Count()); string targetPath = Path.GetDirectoryName(targetPathFilename); if (!Directory.Exists(targetPath)) Directory.CreateDirectory(targetPath); Stream sourceStream = Assets.Open(sourcePathFilename); FileStream fileStream = File.Create(targetPathFilename); sourceStream.CopyTo(fileStream); fileStream.Close(); sourceStream.Close(); completeCount++; } } } } }
using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Android.App; // 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 © 2014")] [assembly:|AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly:|ComVisible(false)] // 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")]
#pragma warning disable 1591 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ [assembly:|global::Android.Runtime.ResourceDesignerAttribute("LabelingStyle.Resource", IsApplication=true)] namespace LabelingStyle { [System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Android.Build.Tasks",|"1.0.0.0")] public partial class Resource { static Resource() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } public static void UpdateIdValues() { global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_default256x256 = global::LabelingStyle.Resource.Drawable.icon_mapsuite_default256x256; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_default512x512 = global::LabelingStyle.Resource.Drawable.icon_mapsuite_default512x512; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe = global::LabelingStyle.Resource.Drawable.icon_mapsuite_globe; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe_Pressed = global::LabelingStyle.Resource.Drawable.icon_mapsuite_globe_Pressed; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus = global::LabelingStyle.Resource.Drawable.icon_mapsuite_Minus; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus_Pressed = global::LabelingStyle.Resource.Drawable.icon_mapsuite_Minus_Pressed; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_noImageTile = global::LabelingStyle.Resource.Drawable.icon_mapsuite_noImageTile; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus = global::LabelingStyle.Resource.Drawable.icon_mapsuite_Plus; global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus_Pressed = global::LabelingStyle.Resource.Drawable.icon_mapsuite_Plus_Pressed; } public partial class Attribute { static Attribute() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Attribute() { } } public partial class Color { // aapt resource value: 0x7f050000 public const int transparent = 2131034112; static Color() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Color() { } } public partial class Drawable { // aapt resource value: 0x7f020000 public const int baseSettingsDialogStyle = 2130837504; // aapt resource value: 0x7f020001 public const int @checked = 2130837505; // aapt resource value: 0x7f020002 public const int CustomLabeling = 2130837506; // aapt resource value: 0x7f020003 public const int CustomLabelingIcon = 2130837507; // aapt resource value: 0x7f020004 public const int detail40 = 2130837508; // aapt resource value: 0x7f020005 public const int Icon = 2130837509; // aapt resource value: 0x7f020006 public const int icon_mapsuite_default256x256 = 2130837510; // aapt resource value: 0x7f020007 public const int icon_mapsuite_default512x512 = 2130837511; // aapt resource value: 0x7f020008 public const int icon_mapsuite_globe = 2130837512; // aapt resource value: 0x7f020009 public const int icon_mapsuite_globe_Pressed = 2130837513; // aapt resource value: 0x7f02000a public const int icon_mapsuite_Minus = 2130837514; // aapt resource value: 0x7f02000b public const int icon_mapsuite_Minus_Pressed = 2130837515; // aapt resource value: 0x7f02000c public const int icon_mapsuite_noImageTile = 2130837516; // aapt resource value: 0x7f02000d public const int icon_mapsuite_Plus = 2130837517; // aapt resource value: 0x7f02000e public const int icon_mapsuite_Plus_Pressed = 2130837518; // aapt resource value: 0x7f02000f public const int LabelingLinesIcon = 2130837519; // aapt resource value: 0x7f020010 public const int LabelingPoints = 2130837520; // aapt resource value: 0x7f020011 public const int LabelingPointsIcon = 2130837521; // aapt resource value: 0x7f020012 public const int LabelingPolygons = 2130837522; // aapt resource value: 0x7f020013 public const int LabelingPolygonsIcon = 2130837523; // aapt resource value: 0x7f020014 public const int LabelStyling = 2130837524; // aapt resource value: 0x7f020015 public const int LabelStylingIcon = 2130837525; // aapt resource value: 0x7f020016 public const int MapSuite = 2130837526; // aapt resource value: 0x7f020017 public const int more40 = 2130837527; // aapt resource value: 0x7f020018 public const int settings40 = 2130837528; // aapt resource value: 0x7f020019 public const int SettingsDialogBackground = 2130837529; // aapt resource value: 0x7f02001a public const int SliderLineBackground = 2130837530; // aapt resource value: 0x7f02001b public const int @unchecked = 2130837531; // aapt resource value: 0x7f02001c public const int valuestyle = 2130837532; static Drawable() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Drawable() { } } public partial class Id { // aapt resource value: 0x7f06001d public const int CancelButton = 2131099677; // aapt resource value: 0x7f06000f public const int DuplicateRuleSpinner = 2131099663; // aapt resource value: 0x7f06000e public const int GridSizeSpinner = 2131099662; // aapt resource value: 0x7f060016 public const int LabelStylingLayout = 2131099670; // aapt resource value: 0x7f06001a public const int MapContainerView = 2131099674; // aapt resource value: 0x7f06000c public const int MaskCheckBox = 2131099660; // aapt resource value: 0x7f060003 public const int MaxFontSizeEditText = 2131099651; // aapt resource value: 0x7f060002 public const int MinFontSizeEditText = 2131099650; // aapt resource value: 0x7f06001c public const int OkButton = 2131099676; // aapt resource value: 0x7f060009 public const int OnlyWithinCheckBox = 2131099657; // aapt resource value: 0x7f06000b public const int OutlineColorCheckBox = 2131099659; // aapt resource value: 0x7f06000d public const int OverlappingCheckBox = 2131099661; // aapt resource value: 0x7f060006 public const int PointPlacementSpinner = 2131099654; // aapt resource value: 0x7f06000a public const int PolygonPartsCheckBox = 2131099658; // aapt resource value: 0x7f060017 public const int SampleListButton = 2131099671; // aapt resource value: 0x7f060019 public const int SettingsButton = 2131099673; // aapt resource value: 0x7f060018 public const int TitleTextView = 2131099672; // aapt resource value: 0x7f060010 public const int drawingMarginsText = 2131099664; // aapt resource value: 0x7f060005 public const int lineSegmentRatioEditText = 2131099653; // aapt resource value: 0x7f060000 public const int linearLayout1 = 2131099648; // aapt resource value: 0x7f06001b public const int mainLayout = 2131099675; // aapt resource value: 0x7f060015 public const int mainLinearLayout = 2131099669; // aapt resource value: 0x7f060014 public const int sampleListMoreButton = 2131099668; // aapt resource value: 0x7f060012 public const int sampleListTitle = 2131099666; // aapt resource value: 0x7f060013 public const int sampleListView = 2131099667; // aapt resource value: 0x7f060011 public const int slider_view = 2131099665; // aapt resource value: 0x7f060004 public const int splineTypeSpinner = 2131099652; // aapt resource value: 0x7f060001 public const int textView1 = 2131099649; // aapt resource value: 0x7f06001f public const int uploadDataTextView = 2131099679; // aapt resource value: 0x7f06001e public const int uploadProgressBar = 2131099678; // aapt resource value: 0x7f060007 public const int xOffsetEditText = 2131099655; // aapt resource value: 0x7f060008 public const int yOffsetEditText = 2131099656; static Id() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Id() { } } public partial class Layout { // aapt resource value: 0x7f030000 public const int ButtonBackgroundSelector = 2130903040; // aapt resource value: 0x7f030001 public const int CustomLabelingSettingsLayout = 2130903041; // aapt resource value: 0x7f030002 public const int LabelingLinesSettingsLayout = 2130903042; // aapt resource value: 0x7f030003 public const int LabelingPointsSettingsLayout = 2130903043; // aapt resource value: 0x7f030004 public const int LabelingPolygonsSettingsLayout = 2130903044; // aapt resource value: 0x7f030005 public const int LabelStylingSettingsLayout = 2130903045; // aapt resource value: 0x7f030006 public const int Main = 2130903046; // aapt resource value: 0x7f030007 public const int SampleBaseLayout = 2130903047; // aapt resource value: 0x7f030008 public const int SampleCheckBoxSelector = 2130903048; // aapt resource value: 0x7f030009 public const int SampleSpinnerCheckedText = 2130903049; // aapt resource value: 0x7f03000a public const int SettingsDialogBaseLayout = 2130903050; // aapt resource value: 0x7f03000b public const int SplashLayout = 2130903051; static Layout() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private Layout() { } } public partial class String { // aapt resource value: 0x7f040001 public const int ApplicationName = 2130968577; // aapt resource value: 0x7f040000 public const int Hello = 2130968576; static String() { global::Android.Runtime.ResourceIdManager.UpdateIdValues(); } private String() { } } } } #pragma warning restore 1591
using Android.App; using Android.Content; using Android.Graphics; using Android.Util; using Android.Views; using Android.Widget; using System; using ThinkGeo.MapSuite.AndroidEdition; namespace LabelingStyle { public abstract class BaseSample { private Context context; private View sampleView; private MapView mapView; private TextView titleTextView; private ImageButton settingsButton; public EventHandler<EventArgs> SampleListButtonClick; public BaseSample(Context context) { this.context = context; sampleView = View.Inflate(context, Resource.Layout.SampleBaseLayout, null); settingsButton = sampleView.FindViewById<ImageButton>(Resource.Id.SettingsButton); titleTextView = sampleView.FindViewById<TextView>(Resource.Id.TitleTextView); settingsButton.Click += (s, e) => ApplySettings(); sampleView.FindViewById<ImageButton>(Resource.Id.SampleListButton).Click += OnSampleListButtonClick; } public Context Context { get { return context; } } public string Title { get { return titleTextView.Text; } set { titleTextView.Text = value; } } public int ImageId { get; set; } /// <summary> /// This is map view, if it doesn't exist, we will create one. /// </summary> public MapView MapView { get { return mapView ?? (mapView = new MapView(Application.Context)); } } /// <summary> /// This is a container for a concrete sample. Including map and corresponding components for interaction. /// </summary> public View SampleView { get { return sampleView; } } /// <summary> /// This method updates the sample layout; including creating new map with default themes. /// </summary> public void UpdateSampleLayout() { try { FrameLayout mapContainerView = sampleView.FindViewById<FrameLayout>(Resource.Id.MapContainerView); mapContainerView.RemoveAllViews(); mapView = new MapView(Application.Context); mapView.SetBackgroundColor(Color.Argb(255, 244, 242, 238)); InitalizeMap(); mapContainerView.AddView(mapView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent)); } catch (Exception ex) { Log.Debug("Sample Changed", ex.Message); } // Customize the sample layout with specific sample. UpdateSampleLayoutCore(); } /// <summary> /// Allows user to customize the sample layout. /// </summary> protected virtual void UpdateSampleLayoutCore() { } /// <summary> /// Disposes the map view. /// It is necessary to dispose the map resources when current sample is changed to avoid the OOM issue. /// </summary> public void DisposeMap() { if (mapView != null && mapView.Parent != null) { FrameLayout mapContainerView = sampleView.FindViewById<FrameLayout>(Resource.Id.MapContainerView); mapContainerView.RemoveAllViews(); mapView.Dispose(); mapView = null; GC.Collect(); GC.WaitForPendingFinalizers(); } } protected virtual void OnSampleListButtonClick(object sender, EventArgs e) { EventHandler<EventArgs> handler = SampleListButtonClick; if (handler != null) handler(this, e); } /// <summary> /// This method customizes the map for a specific sample. /// We could add overlays, layers, styles inside of this method. /// </summary> protected abstract void InitalizeMap(); /// <summary> /// Applies the settings when clicked the settings apply button. /// </summary> protected virtual void ApplySettings() { } } }
using Android.App; using Android.Content; using Android.Views; using Android.Widget; using System; namespace LabelingStyle { public abstract class BaseSettingsDialog<T> : AlertDialog { public event EventHandler<EventArgs> ApplyingSettings; private int width; private T settings; private TextView titleTextView; private View settingsDialogView; public BaseSettingsDialog(Context context, T settings) : base(context) { this.settings = settings; settingsDialogView = View.Inflate(context, Resource.Layout.SettingsDialogBaseLayout, null); settingsDialogView.FindViewById<Button>(Resource.Id.OkButton).Click += OkButtonClick; settingsDialogView.FindViewById<Button>(Resource.Id.CancelButton).Click += CancelButtonClick; titleTextView = settingsDialogView.FindViewById<TextView>(Resource.Id.TitleTextView); SetCanceledOnTouchOutside(false); SetView(settingsDialogView); } public int Width { get { return width; } set { width = value; } } public T Settings { get { return settings; } } public string Title { get { return titleTextView.Text; } set { titleTextView.Text = value; } } public override void Show() { base.Show(); InitalizeDialog(); int dialogWidth = (int)(Width * Context.Resources.DisplayMetrics.Density); WindowManagerLayoutParams windowLayoutParams = Window.Attributes; windowLayoutParams.Gravity = GravityFlags.Center; windowLayoutParams.Width = dialogWidth > Window.WindowManager.DefaultDisplay.Width ? Window.WindowManager.DefaultDisplay.Width : dialogWidth; Window.Attributes = windowLayoutParams; Window.SetGravity(GravityFlags.Center); } protected ViewGroup SettingsContainerView { get { return settingsDialogView.FindViewById<FrameLayout>(Resource.Id.mainLayout); } } protected abstract void SaveSettings(); protected abstract void InitalizeDialog(); private void CancelButtonClick(object sender, EventArgs e) { Cancel(); } private void OkButtonClick(object sender, EventArgs e) { SaveSettings(); Cancel(); OnApplyingSettings(this, e); } private void OnApplyingSettings(object sender, EventArgs e) { EventHandler<EventArgs> handler = ApplyingSettings; if (handler != null) handler(sender, e); } } }
namespace LabelingStyle { public abstract class StyleSettings { protected StyleSettings() { } public string Title { get; set; } /// <summary> /// This method parses the setting value to double. /// </summary> /// <param name="source">The source.</param> /// <param name="defaultValue">The default value.</param> /// <returns>System.Double.</returns> protected static double ParseToDouble(string source, double defaultValue) { double temp; double result = defaultValue; if (double.TryParse(source, out temp)) { result = temp; } return result; } /// <summary> /// This method parses the setting value to int. /// </summary> /// <param name="source">The source.</param> /// <param name="defaultValue">The default value.</param> /// <returns>System.Int32.</returns> protected static int ParseToInt(string source, int defaultValue) { int temp; int result = defaultValue; if (int.TryParse(source, out temp)) { result = temp; } return result; } /// <summary> /// This method parses the setting value to float. /// </summary> /// <param name="source">The source.</param> /// <param name="defaultValue">The default value.</param> /// <returns>System.Single.</returns> protected static float ParseToFloat(string source, float defaultValue) { float temp; float result = defaultValue; if (float.TryParse(source, out temp)) { result = temp; } return result; } } }
using Android.Content; using System; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class CustomLabelingSample : BaseSample { private CustomLabelingStyleSettingsDialog customLabelingStyleSettingsDialog; public CustomLabelingSample(Context context) : base(context) { Title = "Custom Labeling"; } protected override void ApplySettings() { if (customLabelingStyleSettingsDialog == null) { customLabelingStyleSettingsDialog = new CustomLabelingStyleSettingsDialog(Context, new CustomLabelingStyleSettings()); customLabelingStyleSettingsDialog.ApplyingSettings += customLabelingStyleSettingsDialog_ApplyingSettings; } customLabelingStyleSettingsDialog.Show(); } private void customLabelingStyleSettingsDialog_ApplyingSettings(object sender, EventArgs e) { LayerOverlay labelingStyleOverlay = MapView.Overlays["CustomLabeling"] as LayerOverlay; if (labelingStyleOverlay != null) { UpdateLabelStylingOverlay(labelingStyleOverlay, customLabelingStyleSettingsDialog.Settings); MapView.Refresh(); } } protected override void InitalizeMap() { MapView.MapUnit = GeographyUnit.Meter; MapView.CurrentExtent = new RectangleShape(-10777472.620674, 3909177.1327916, -10776518.8812938, 3907779.90459956); WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay(); worldOverlay.Projection = WorldMapKitProjection.SphericalMercator; MapView.Overlays.Add("WMK", worldOverlay); ShapeFileFeatureLayer customLabelingStyleLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("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); } private void UpdateLabelStylingOverlay(LayerOverlay layerOverlay, CustomLabelingStyleSettings settings) { 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(); } } }
namespace LabelingStyle { public class CustomLabelingStyleSettings : StyleSettings { public CustomLabelingStyleSettings() { Title = "Custom Labeling Edit Settings"; MinFontSize = "8"; MaxFontSize = "60"; } public string MinFontSize { get; set; } public string MaxFontSize { get; set; } public float GetMinFontSize() { return ParseToFloat(MinFontSize, 8); } public float GetMaxFontSize() { return ParseToFloat(MaxFontSize, 60); } } }
using Android.Content; using Android.Views; using Android.Widget; namespace LabelingStyle { public class CustomLabelingStyleSettingsDialog : BaseSettingsDialog<CustomLabelingStyleSettings> { private EditText maxFontSizeEditText; private EditText minFontSizeEditText; public CustomLabelingStyleSettingsDialog(Context context, CustomLabelingStyleSettings settings) : base(context, settings) { Width = 500; Title = settings.Title; View.Inflate(context, Resource.Layout.CustomLabelingSettingsLayout, SettingsContainerView); maxFontSizeEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.MaxFontSizeEditText); minFontSizeEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.MinFontSizeEditText); } protected override void InitalizeDialog() { maxFontSizeEditText.Text = Settings.MaxFontSize; minFontSizeEditText.Text = Settings.MinFontSize; } protected override void SaveSettings() { Settings.MaxFontSize = maxFontSizeEditText.Text; Settings.MinFontSize = minFontSizeEditText.Text; } } }
using Android.Content; using System; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingLinesSample : BaseSample { private LabelingLinesSettingsDialog labelingLinesSettingsDialog; public LabelingLinesSample(Context context) : base(context) { Title = "Labeling Lines"; } protected override void ApplySettings() { if (labelingLinesSettingsDialog == null) { labelingLinesSettingsDialog = new LabelingLinesSettingsDialog(Context, new LabelingLinesStyleSettings()); labelingLinesSettingsDialog.ApplyingSettings += labelingLinesSettingsDialog_ApplyingSettings; } labelingLinesSettingsDialog.Show(); } private void labelingLinesSettingsDialog_ApplyingSettings(object sender, EventArgs e) { LayerOverlay labelingStyleOverlay = MapView.Overlays["LabelingLine"] as LayerOverlay; if (labelingStyleOverlay != null) { UpdateLabelStylingOverlay(labelingStyleOverlay, labelingLinesSettingsDialog.Settings); MapView.Refresh(); } } protected override void InitalizeMap() { MapView.MapUnit = GeographyUnit.Meter; MapView.CurrentExtent = new RectangleShape(-10777472.620674, 3909177.1327916, -10776518.8812938, 3907779.90459956); ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("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); } private 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; } private void UpdateLabelStylingOverlay(LayerOverlay layerOverlay, LabelingLinesStyleSettings settings) { 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(); } } }
using Android.Content; using Android.Views; using Android.Widget; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingLinesSettingsDialog : BaseSettingsDialog<LabelingLinesStyleSettings> { private static readonly string[] SplineTypeItems = new string[] { "Default", "None", "StandardSplining", "ForceSplining" }; private Spinner splineTypeSpinner; private EditText lineSegmentRatioEditText; public LabelingLinesSettingsDialog(Context context, LabelingLinesStyleSettings settings) : base(context, settings) { Width = 500; Title = settings.Title; View.Inflate(context, Resource.Layout.LabelingLinesSettingsLayout, SettingsContainerView); splineTypeSpinner = SettingsContainerView.FindViewById<Spinner>(Resource.Id.splineTypeSpinner); lineSegmentRatioEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.lineSegmentRatioEditText); } protected override void InitalizeDialog() { ArrayAdapter<string> splineTypeAdapter = new ArrayAdapter<string>(Context, Resource.Layout.SampleSpinnerCheckedText, SplineTypeItems); splineTypeSpinner.Adapter = splineTypeAdapter; splineTypeSpinner.SetSelection((int)Settings.SplineType); lineSegmentRatioEditText.Text = Settings.LineSegmentRatio; } protected override void SaveSettings() { Settings.SplineType = (SplineType)splineTypeSpinner.SelectedItemPosition; Settings.LineSegmentRatio = lineSegmentRatioEditText.Text; } } }
using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingLinesStyleSettings : StyleSettings { public LabelingLinesStyleSettings() { Title = "Labeling Lines Edit Settings"; SplineType = SplineType.Default; LineSegmentRatio = "0.9"; } public SplineType SplineType { get; set; } public string LineSegmentRatio { get; set; } public double GetLineSegmentRatio() { return ParseToDouble(LineSegmentRatio, 0.9); } } }
using Android.Content; using System; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingPointsSample : BaseSample { private LabelingPointsSettingsDialog labelingPointsSettingsDialog; public LabelingPointsSample(Context context) : base(context) { Title = "Labeling Points"; } protected override void ApplySettings() { if (labelingPointsSettingsDialog == null) { labelingPointsSettingsDialog = new LabelingPointsSettingsDialog(Context, new LabelingPointsStyleSettings()); labelingPointsSettingsDialog.ApplyingSettings += labelingPointsSettingsDialog_ApplyingSettings; } labelingPointsSettingsDialog.Show(); } private void labelingPointsSettingsDialog_ApplyingSettings(object sender, EventArgs e) { LayerOverlay labelingPointsOverlay = MapView.Overlays["LabelingPoints"] as LayerOverlay; if (labelingPointsOverlay != null) { UpdateLabelingPointsOverlay(labelingPointsOverlay, labelingPointsSettingsDialog.Settings); MapView.Refresh(); } } protected override void InitalizeMap() { MapView.MapUnit = GeographyUnit.Meter; MapView.CurrentExtent = new RectangleShape(-10777472.620674, 3909177.1327916, -10776518.8812938, 3907779.90459956); WorldMapKitOverlay worldOverlay = new WorldMapKitOverlay(); worldOverlay.Projection = WorldMapKitProjection.SphericalMercator; MapView.Overlays.Add("WMK", worldOverlay); ShapeFileFeatureLayer poiLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("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); } private void UpdateLabelingPointsOverlay(LayerOverlay layerOverlay, LabelingPointsStyleSettings settings) { FeatureLayer poiLayer = (FeatureLayer)layerOverlay.Layers["poi"]; poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.PointPlacement = settings.Placement; poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.XOffsetInPixel = settings.GetXOffset(); poiLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.YOffsetInPixel = settings.GetYOffset(); layerOverlay.Refresh(); } } }
using Android.Content; using Android.Views; using Android.Widget; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { class LabelingPointsSettingsDialog : BaseSettingsDialog<LabelingPointsStyleSettings> { private static readonly string[] PointPlacementItems = new string[] { "UpperLeft", "UpperCenter", "UpperRight", "CenterRight", "Center", "CenterLeft", "LowerLeft", "LowerCenter", "LowerRight" }; private EditText xOffsetEditText; private EditText yOffsetEditText; private Spinner pointPlacementSpinner; public LabelingPointsSettingsDialog(Context context, LabelingPointsStyleSettings settings) : base(context, settings) { Width = 500; Title = settings.Title; View.Inflate(context, Resource.Layout.LabelingPointsSettingsLayout, SettingsContainerView); xOffsetEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.xOffsetEditText); yOffsetEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.yOffsetEditText); pointPlacementSpinner = SettingsContainerView.FindViewById<Spinner>(Resource.Id.PointPlacementSpinner); } protected override void InitalizeDialog() { ArrayAdapter<string> pointPlacementAdapter = new ArrayAdapter<string>(Context, Resource.Layout.SampleSpinnerCheckedText, PointPlacementItems); pointPlacementSpinner.Adapter = pointPlacementAdapter; xOffsetEditText.Text = Settings.XOffset; yOffsetEditText.Text = Settings.YOffset; pointPlacementSpinner.SetSelection((int)Settings.Placement); } protected override void SaveSettings() { Settings.XOffset = xOffsetEditText.Text; Settings.YOffset = yOffsetEditText.Text; Settings.Placement = (PointPlacement)pointPlacementSpinner.SelectedItemPosition; } } }
using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingPointsStyleSettings : StyleSettings { public LabelingPointsStyleSettings() { Title = "Labeling Points Edit Settings"; Placement = PointPlacement.UpperCenter; XOffset = "0"; YOffset = "8"; } public PointPlacement Placement { get; set; } public string XOffset { get; set; } public string YOffset { get; set; } public float GetXOffset() { return ParseToFloat(XOffset, 0f); } public float GetYOffset() { return ParseToFloat(YOffset, 8f); } } }
using Android.Content; using System; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelingPolygonsSample : BaseSample { private LabelingPolygonsSettingsDialog labelingPolygonsSettingsDialog; public LabelingPolygonsSample(Context context) : base(context) { Title = "Labeling Plygons"; } protected override void ApplySettings() { if (labelingPolygonsSettingsDialog == null) { labelingPolygonsSettingsDialog = new LabelingPolygonsSettingsDialog(Context, new LabelingPolygonsStyleSettings()); labelingPolygonsSettingsDialog.ApplyingSettings += labelingPolygonsSettingsDialog_ApplyingSettings; } labelingPolygonsSettingsDialog.Show(); } private void labelingPolygonsSettingsDialog_ApplyingSettings(object sender, EventArgs e) { LayerOverlay labelingStyleOverlay = MapView.Overlays["LabelingPolygons"] as LayerOverlay; if (labelingStyleOverlay != null) { UpdateLabelStylingOverlay(labelingStyleOverlay, labelingPolygonsSettingsDialog.Settings); MapView.Refresh(); } } protected override void InitalizeMap() { MapView.MapUnit = GeographyUnit.Meter; MapView.CurrentExtent = new RectangleShape(-10777472.620674, 3909177.1327916, -10776518.8812938, 3907779.90459956); WkbFileFeatureLayer subdivisionsLayer = new WkbFileFeatureLayer(SampleHelper.GetDataPath("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); } private void UpdateLabelStylingOverlay(LayerOverlay layerOverlay, LabelingPolygonsStyleSettings settings) { FeatureLayer featureLayer = (FeatureLayer)layerOverlay.Layers["subdivision"]; featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.FittingPolygonFactor = settings.FittingFactorsOnlyWithin ? 2 : 0; featureLayer.ZoomLevelSet.ZoomLevel10.DefaultTextStyle.LabelAllPolygonParts = settings.LabelAllPolygonParts; layerOverlay.Refresh(); } } }
using Android.Content; using Android.Views; using Android.Widget; namespace LabelingStyle { public class LabelingPolygonsSettingsDialog : BaseSettingsDialog<LabelingPolygonsStyleSettings> { private CheckBox onlyWithinCheckBox; private CheckBox polygonPartsCheckBox; public LabelingPolygonsSettingsDialog(Context context, LabelingPolygonsStyleSettings settings) : base(context, settings) { Width = 500; Title = settings.Title; View.Inflate(context, Resource.Layout.LabelingPolygonsSettingsLayout, SettingsContainerView); onlyWithinCheckBox = SettingsContainerView.FindViewById<CheckBox>(Resource.Id.OnlyWithinCheckBox); polygonPartsCheckBox = SettingsContainerView.FindViewById<CheckBox>(Resource.Id.PolygonPartsCheckBox); } protected override void InitalizeDialog() { onlyWithinCheckBox.Checked = Settings.FittingFactorsOnlyWithin; polygonPartsCheckBox.Checked = Settings.LabelAllPolygonParts; } protected override void SaveSettings() { Settings.FittingFactorsOnlyWithin = onlyWithinCheckBox.Checked; Settings.LabelAllPolygonParts = polygonPartsCheckBox.Checked; } } }
namespace LabelingStyle { public class LabelingPolygonsStyleSettings : StyleSettings { public LabelingPolygonsStyleSettings() { Title = "Labeling Polygons Edit Settings"; FittingFactorsOnlyWithin = true; LabelAllPolygonParts = false; } public bool FittingFactorsOnlyWithin { get; set; } public bool LabelAllPolygonParts { get; set; } } }
using Android.Content; using System.Collections.Generic; using System.Linq; using ThinkGeo.MapSuite.AndroidEdition; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelStylingSample : BaseSample { private static Dictionary<string, int> gridSizeDictionary; private LabelStylingSettingsDialog labelStylingSettingsDialog; static LabelStylingSample() { gridSizeDictionary = new Dictionary<string, int>(); gridSizeDictionary["Small"] = 100; gridSizeDictionary["Medium"] = 500; gridSizeDictionary["Large"] = 1000; } public LabelStylingSample(Context context) : base(context) { Title = "Label Styling"; } protected override void ApplySettings() { if (labelStylingSettingsDialog == null) { labelStylingSettingsDialog = new LabelStylingSettingsDialog(Context, new LabelStylingStyleSettings()); labelStylingSettingsDialog.ApplyingSettings += labelStylingSettingsDialog_ApplyingSettings; } labelStylingSettingsDialog.Show(); } private void labelStylingSettingsDialog_ApplyingSettings(object sender, System.EventArgs e) { LayerOverlay labelingStyleOverlay = MapView.Overlays["LabelingStyle"] as LayerOverlay; if (labelingStyleOverlay != null) { UpdateLabelStylingOverlay(labelingStyleOverlay, labelStylingSettingsDialog.Settings); MapView.Refresh(); } } protected override void InitalizeMap() { MapView.MapUnit = GeographyUnit.Meter; MapView.CurrentExtent = new RectangleShape(-10777472.620674, 3909177.1327916, -10776518.8812938, 3907779.90459956); WkbFileFeatureLayer parcelLayer = new WkbFileFeatureLayer(SampleHelper.GetDataPath("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(SampleHelper.GetDataPath("Street.shp")); streetLayer.ZoomLevelSet.ZoomLevel10.CustomStyles.Add(GetRoadStyle()); streetLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; streetLayer.DrawingMarginPercentage = 50; ShapeFileFeatureLayer restaurantsLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("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.NoOverlapping; 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); } private static void UpdateLabelStylingOverlay(LayerOverlay layerOverlay, LabelStylingStyleSettings settings) { string gridSize = settings.GridSize.ToString(); string drawingMargin = settings.DrawingMarginPercentage; 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<TextStyle> textStyles = new List<TextStyle>(); 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 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; } } }
using Android.Content; using Android.Views; using Android.Widget; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelStylingSettingsDialog : BaseSettingsDialog<LabelStylingStyleSettings> { private static readonly string[] GridSizeLabelItems = { "Small", "Medium", "Large" }; private static readonly string[] DuplicateRuleItems = { "OneDuplicateLabelPerQuadrant", "NoDuplicateLabels", "UnlimitedDuplicateLabels" }; private Spinner duplicateRuleSpinner; private Spinner gridSizeSpinner; private CheckBox overlappingCheckBox; private CheckBox backgroundMaskCheckBox; private CheckBox outlineCheckBox; private EditText drawingMarginsEditText; public LabelStylingSettingsDialog(Context context, LabelStylingStyleSettings settings) : base(context, settings) { Width = 500; Title = settings.Title; View.Inflate(context, Resource.Layout.LabelStylingSettingsLayout, SettingsContainerView); duplicateRuleSpinner = SettingsContainerView.FindViewById<Spinner>(Resource.Id.DuplicateRuleSpinner); gridSizeSpinner = SettingsContainerView.FindViewById<Spinner>(Resource.Id.GridSizeSpinner); overlappingCheckBox = SettingsContainerView.FindViewById<CheckBox>(Resource.Id.OverlappingCheckBox); backgroundMaskCheckBox = SettingsContainerView.FindViewById<CheckBox>(Resource.Id.MaskCheckBox); outlineCheckBox = SettingsContainerView.FindViewById<CheckBox>(Resource.Id.OutlineColorCheckBox); drawingMarginsEditText = SettingsContainerView.FindViewById<EditText>(Resource.Id.drawingMarginsText); } protected override void InitalizeDialog() { ArrayAdapter<string> duplicateRuleAdapter = new ArrayAdapter<string>(Context, Resource.Layout.SampleSpinnerCheckedText, DuplicateRuleItems); duplicateRuleSpinner.Adapter = duplicateRuleAdapter; ArrayAdapter<string> gridSizeAdapter = new ArrayAdapter<string>(Context, Resource.Layout.SampleSpinnerCheckedText, GridSizeLabelItems); gridSizeSpinner.Adapter = gridSizeAdapter; overlappingCheckBox.Checked = Settings.LabelsOverlappingEachOther; backgroundMaskCheckBox.Checked = Settings.ApplyBackgroundMask; outlineCheckBox.Checked = Settings.ApplyOutlineColor; gridSizeSpinner.SetSelection((int)Settings.GridSize); duplicateRuleSpinner.SetSelection((int)Settings.DuplicateRule); drawingMarginsEditText.Text = Settings.DrawingMarginPercentage; } protected override void SaveSettings() { Settings.LabelsOverlappingEachOther = overlappingCheckBox.Checked; Settings.ApplyBackgroundMask = backgroundMaskCheckBox.Checked; Settings.ApplyOutlineColor = outlineCheckBox.Checked; Settings.GridSize = (LabelGridSize)gridSizeSpinner.SelectedItemPosition; Settings.DuplicateRule = (LabelDuplicateRule)duplicateRuleSpinner.SelectedItemPosition; Settings.DrawingMarginPercentage = drawingMarginsEditText.Text; } } }
using ThinkGeo.MapSuite.Core; namespace LabelingStyle { public class LabelStylingStyleSettings : StyleSettings { public LabelStylingStyleSettings() { Title = "Label Styling Edit Settings"; ApplyOutlineColor = true; ApplyBackgroundMask = true; LabelsOverlappingEachOther = false; GridSize = LabelGridSize.Large; DuplicateRule = LabelDuplicateRule.NoDuplicateLabels; DrawingMarginPercentage = "50"; } public bool ApplyOutlineColor { get; set; } public bool ApplyBackgroundMask { get; set; } public bool LabelsOverlappingEachOther { get; set; } public LabelGridSize GridSize { get; set; } public LabelDuplicateRule DuplicateRule { get; set; } public string DrawingMarginPercentage { get; set; } public double GetDrawingMarginPercentage() { return ParseToDouble(DrawingMarginPercentage, 50); } } public enum LabelGridSize { Small = 0, Medium = 1, Large = 2 } }
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using ThinkGeo.MapSuite.Core; namespace LabelingStyle { 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<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> 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); } } }
using System.IO; namespace LabelingStyle { internal class SampleHelper { public readonly static string AssetsDataDictionary = @"SampleData"; public readonly static string SampleDataDictionary = @"mnt/sdcard/MapSuiteSampleData/LabelingStyle/"; public static string GetDataPath(params string[] fileNames) { string[] paths = new string[fileNames.Length|+ 2]; paths[0] = SampleDataDictionary; paths[1] = AssetsDataDictionary; for (int i = 0; i < fileNames.Length; i++) { paths[i|+ 2] = fileNames[i]; } return Path.Combine(paths); } } }
using Android.App; using Android.Graphics; using Android.Views; using Android.Widget; using System.Collections.Generic; namespace LabelingStyle { public class SampleListItemAdapter : ArrayAdapter<BaseSample> { Activity context; public SampleListItemAdapter(Activity context, IList<BaseSample> objects) : base(context, Android.Resource.Id.Text1, objects) { this.context = context; } public override View GetView(int position, View convertView, ViewGroup parent) { float ratio = context.Resources.DisplayMetrics.Density; LinearLayout layout = (LinearLayout)context.LayoutInflater.Inflate(Android.Resource.Layout.ActivityListItem, null); var item = GetItem(position); TextView textView = layout.FindViewById<TextView>(Android.Resource.Id.Text1); textView.Text = item.Title; textView.SetTextColor(Color.Black); textView.SetTextSize(Android.Util.ComplexUnitType.Px, 14 * ratio); ((LinearLayout.LayoutParams)(textView.LayoutParameters)).Gravity = GravityFlags.CenterVertical; ImageView imageView = layout.FindViewById<ImageView>(Android.Resource.Id.Icon); imageView.SetImageResource(item.ImageId); imageView.LayoutParameters.Width = (int)(30 * ratio); imageView.LayoutParameters.Height = (int)(30 * ratio); ((LinearLayout.LayoutParams)imageView.LayoutParameters).SetMargins(0, 2, 0, 2); return layout; } } }
using Android.Content; using Android.Util; using Android.Views; using Android.Widget; using System; namespace LabelingStyle { public class SliderView : ViewGroup { private static readonly int VELOCITY_X_SPEED = 800; private float x; private Context context; private Scroller scroller; private bool dispatched; private bool slided; private int leftViewWidth; private int startScrollLeftOffset; private VelocityTracker mVelocityTracker; public SliderView(Context context, IAttributeSet attrs) : base(context, attrs) { this.context = context; this.leftViewWidth = 200; this.scroller = new Scroller(context); } public int LeftViewWidth { get { return leftViewWidth; } set { leftViewWidth = value; } } public View LeftView { get { return this.GetChildAt(0); } } public ViewGroup MainView { get { return this.GetChildAt(1) as ViewGroup; } } protected override void OnLayout(bool arg0, int arg1, int arg2, int arg3, int arg4) { int childCount = this.ChildCount; for (int i = 0; i < childCount; ++i) { View view = this.GetChildAt(i); if (view.Visibility != ViewStates.Gone) { view.Layout(0, 0, view.MeasuredWidth, view.MeasuredHeight); } } } public override bool OnInterceptTouchEvent(MotionEvent ev) { return true; } public override bool OnTouchEvent(MotionEvent e) { if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.Obtain(); } mVelocityTracker.AddMovement(e); MotionEventActions action = e.Action; if (action == MotionEventActions.Down) { x = e.GetX(); if (IsSlided()) { dispatched = DispatchTouchEventToView(GetChildAt(0), e); } else { dispatched = DispatchTouchEventToView(GetChildAt(1), e); } } else if (action == MotionEventActions.Move) { if (dispatched) { if (IsSlided()) { DispatchTouchEventToView(GetChildAt(0), e); } else { DispatchTouchEventToView(GetChildAt(1), e); } } else { float dx = e.GetX() - x; View view = this.GetChildAt(1); int left = (int)(view.Left + dx); if (left >= 0) { view.Layout(left, view.Top, view.Width + left, view.Top + view.Height); } } x = e.GetX(); } else if (action == MotionEventActions.Cancel || action == MotionEventActions.Up) { if (dispatched) { if (IsSlided()) { DispatchTouchEventToView(GetChildAt(0), e); } else { DispatchTouchEventToView(GetChildAt(1), e); } } else { mVelocityTracker.ComputeCurrentVelocity(1000); int velocityX = (int)mVelocityTracker.GetXVelocity(0); if (velocityX > VELOCITY_X_SPEED) { SetSlided(true); } else if (velocityX < -VELOCITY_X_SPEED) { SetSlided(false); } else { View view = GetChildAt(1); if (view.Left >= view.Width / 2) { SetSlided(true); } else { SetSlided(false); } } if (mVelocityTracker != null) { try { mVelocityTracker.Recycle(); } catch { } } } } else if (!IsSlided()) { DispatchTouchEventToView(GetChildAt(1), e); } return true; } public bool IsSlided() { return slided; } public void SetSlided(bool slided) { View view = GetChildAt(1); startScrollLeftOffset = view.Left; if (slided) { scroller.StartScroll(0, Top, (int)(leftViewWidth * context.Resources.DisplayMetrics.Density) - startScrollLeftOffset, 0); } else { scroller.StartScroll(0, Top, -startScrollLeftOffset, 0); } this.slided = slided; PostInvalidate(); } public override void ComputeScroll() { if (scroller.ComputeScrollOffset()) { View view = GetChildAt(1); int left = startScrollLeftOffset + scroller.CurrX; view.Layout(left, view.Top, left + view.Width, view.Height); PostInvalidate(); } } protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); for (int i = 0; i < ChildCount; ++i) { GetChildAt(i).Measure(widthMeasureSpec, heightMeasureSpec); } } public bool DispatchTouchEventToView(View view, MotionEvent ev) { try { return view.DispatchTouchEvent(ev); } catch (Exception e) { } return false; } } }