Source Code Android Edition ProjectTemplates USEarthquakeStatics CS.zip
MainActivity.cs
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.ObjectModel;
using System.IO;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
[Activity(Label|= "US Earthquake", Icon = "@drawable/MapSuite", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden | Android.Content.PM.ConfigChanges.ScreenSize)]
public class MainActivity : Activity
{
private SelectBaseMapTypeDialog selectBaseMapTypeDialog;
private SelectDisplayTypeDialog selectDisplayTypeDialog;
private RadioButton panRadioButton;
private RadioButton polygonRadioButton;
private RadioButton rectangleRadioButton;
private LayerOverlay highlightOverlay;
private LayerOverlay earthquakeOverlay;
private HeatLayer earthquakeHeatLayer;
private ShapeFileFeatureLayer earthquakePointLayer;
private InMemoryFeatureLayer selectedMarkerLayer;
private InMemoryFeatureLayer highlightMarkerLayer;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
InitializeAndroidMap();
InitializeDialogs();
panRadioButton = FindViewById<RadioButton>(Resource.Id.PanButton);
polygonRadioButton = FindViewById<RadioButton>(Resource.Id.DrawPolygonButton);
rectangleRadioButton = FindViewById<RadioButton>(Resource.Id.DrawRectangleButton);
Button clearButton = FindViewById<Button>(Resource.Id.ClearButton);
Button moreOptionsButton = FindViewById<Button>(Resource.Id.MoreOptionsButton);
panRadioButton.CheckedChange += ControlMode_CheckedChange;
polygonRadioButton.CheckedChange += ControlMode_CheckedChange;
rectangleRadioButton.CheckedChange += ControlMode_CheckedChange;
clearButton.Click += ClearButton_Click;
moreOptionsButton.Click += (sender, e) => StartActivity(typeof(ConfigurationActivity));
}
public override bool OnCreateOptionsMenu(IMenu menu)
{
menu.Add(Menu.None, Menu.First + 1, 1, "Base Map").SetIcon(Resource.Drawable.basemap);
menu.Add(Menu.None, Menu.First + 2, 1, "Display Type").SetIcon(Resource.Drawable.displaytype);
menu.Add(Menu.None, Menu.First + 3, 1, "Query Configuration").SetIcon(Resource.Drawable.searchicon);
return true;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.ItemId)
{
case Menu.First + 1:
selectBaseMapTypeDialog.Show();
break;
case Menu.First + 2:
selectDisplayTypeDialog.Show();
break;
case Menu.First + 3:
StartActivity(typeof(ConfigurationActivity));
break;
}
return false;
}
private void ControlMode_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
{
if (sender.Equals(panRadioButton) && panRadioButton.Checked)
{
Global.MapView.TrackOverlay.TrackMode = TrackMode.None;
}
else if (sender.Equals(polygonRadioButton) && polygonRadioButton.Checked)
{
Global.MapView.TrackOverlay.TrackMode = TrackMode.Polygon;
}
else if (sender.Equals(rectangleRadioButton) && rectangleRadioButton.Checked)
{
Global.MapView.TrackOverlay.TrackMode = TrackMode.Rectangle;
}
}
private void ClearButton_Click(object sender, EventArgs e)
{
Global.ClearBackupQueriedFeatures();
selectedMarkerLayer.InternalFeatures.Clear();
highlightMarkerLayer.InternalFeatures.Clear();
Global.MapView.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
highlightOverlay.Refresh();
Global.MapView.TrackOverlay.Refresh();
}
private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
{
MultipolygonShape resultShape = PolygonShape.Union(Global.MapView.TrackOverlay.TrackShapeLayer.InternalFeatures);
FeatureLayer featureLayer = earthquakePointLayer;
if (!featureLayer.IsOpen)
{ featureLayer.Open(); }
Collection<Feature> features = featureLayer.FeatureSource.GetFeaturesWithinDistanceOf(new Feature(resultShape), Global.MapView.MapUnit, DistanceUnit.Meter, 0.0001, ReturningColumnsType.AllColumns);
Global.BackupQueriedFeatures(features);
Global.FilterSelectedEarthquakeFeatures(Global.GetBackupQueriedFeatures());
}
private void InitializeDialogs()
{
Global.BaseMapType = BaseMapType.WorldMapKitRoad;
selectBaseMapTypeDialog = new SelectBaseMapTypeDialog(this, GetSharedPreferences(Global.PREFS_NAME, 0));
selectDisplayTypeDialog = new SelectDisplayTypeDialog(this, DisplayType.Point);
}
private void InitializeAndroidMap()
{
string baseFolder = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
string cachePathFilename = Path.Combine(baseFolder, "MapSuiteTileCaches/SampleCaches.db");
ManagedProj4Projection proj4 = Global.GetWgs84ToMercatorProjection();
// WMK
WorldMapKitOverlay wmkOverlay = new WorldMapKitOverlay();
wmkOverlay.Projection = WorldMapKitProjection.SphericalMercator;
// OSM
OpenStreetMapOverlay osmOverlay = new OpenStreetMapOverlay();
osmOverlay.TileCache = new SqliteBitmapTileCache(cachePathFilename, "OSMSphericalMercator");
osmOverlay.IsVisible = false;
// Bing - Aerial
BingMapsOverlay bingMapsAerialOverlay = new BingMapsOverlay();
bingMapsAerialOverlay.IsVisible = false;
bingMapsAerialOverlay.MapType = BingMapsMapType.AerialWithLabels;
bingMapsAerialOverlay.TileCache = new SqliteBitmapTileCache(cachePathFilename, "BingAerialWithLabels");
// Bing - Road
BingMapsOverlay bingMapsRoadOverlay = new BingMapsOverlay();
bingMapsRoadOverlay.IsVisible = false;
bingMapsRoadOverlay.MapType = BingMapsMapType.Road;
bingMapsRoadOverlay.TileCache = new SqliteBitmapTileCache(cachePathFilename, "BingRoad");
// Earthquake points
earthquakePointLayer = new ShapeFileFeatureLayer(SampleHelper.GetDataPath("usEarthquake.shp"));
earthquakePointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red, 5, GeoColor.SimpleColors.White, 1));
earthquakePointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
earthquakePointLayer.FeatureSource.Projection = proj4;
ShapeFileFeatureSource earthquakeHeatFeatureSource = new ShapeFileFeatureSource(SampleHelper.GetDataPath("usEarthquake_Simplify.shp"));
earthquakeHeatFeatureSource.Projection = proj4;
earthquakeHeatLayer = new HeatLayer(earthquakeHeatFeatureSource);
earthquakeHeatLayer.HeatStyle = new HeatStyle(10, 75, DistanceUnit.Kilometer);
earthquakeHeatLayer.HeatStyle.Alpha = 180;
earthquakeHeatLayer.IsVisible = false;
earthquakeOverlay = new LayerOverlay();
earthquakeOverlay.Layers.Add(Global.EarthquakePointLayerKey, earthquakePointLayer);
earthquakeOverlay.Layers.Add(Global.EarthquakeHeatLayerKey, earthquakeHeatLayer);
// Highlighted points
selectedMarkerLayer = new InMemoryFeatureLayer();
selectedMarkerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Orange, 8, GeoColor.SimpleColors.White, 2);
selectedMarkerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
PointStyle highLightMarkerStyle = new PointStyle();
highLightMarkerStyle.CustomPointStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(50, GeoColor.SimpleColors.Blue), 20, GeoColor.SimpleColors.LightBlue, 1));
highLightMarkerStyle.CustomPointStyles.Add(PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(255, 0, 122, 255), 10, GeoColor.SimpleColors.White, 2));
highlightMarkerLayer = new InMemoryFeatureLayer();
highlightMarkerLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = highLightMarkerStyle;
highlightMarkerLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
highlightOverlay = new LayerOverlay();
highlightOverlay.Layers.Add(Global.SelectMarkerLayerKey, selectedMarkerLayer);
highlightOverlay.Layers.Add(Global.HighlightMarkerLayerKey, highlightMarkerLayer);
// Maps
Global.MapView = FindViewById<MapView>(Resource.Id.androidMap);
Global.MapView.MapUnit = GeographyUnit.Meter;
Global.MapView.MapTools.ZoomMapTool.Visibility = ViewStates.Invisible;
Global.MapView.ZoomLevelSet = new BingMapsZoomLevelSet();
Global.MapView.CurrentExtent = new RectangleShape(-19062735.6816748, 9273256.52450252, -5746827.16371793, 2673516.56066139);
Global.MapView.SetBackgroundColor(new Android.Graphics.Color(255, 244, 242, 238));
Global.MapView.Overlays.Add(Global.WorldMapKitOverlayKey, wmkOverlay);
Global.MapView.Overlays.Add(Global.OpenStreetMapOverlayKey, osmOverlay);
Global.MapView.Overlays.Add(Global.BingMapsAerialOverlayKey, bingMapsAerialOverlay);
Global.MapView.Overlays.Add(Global.BingMapsRoadOverlayKey, bingMapsRoadOverlay);
Global.MapView.Overlays.Add(Global.EarthquakeOverlayKey, earthquakeOverlay);
Global.MapView.Overlays.Add(Global.HighlightOverlayKey, highlightOverlay);
Global.MapView.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();
Global.MapView.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(80, GeoColor.SimpleColors.LightGreen), 8);
Global.MapView.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.White, 3, true);
Global.MapView.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(80, GeoColor.SimpleColors.LightGreen), GeoColor.SimpleColors.White, 2);
Global.MapView.TrackOverlay.TrackEnded += TrackOverlay_TrackEnded;
}
}
}
ConfigurationActivity.cs
using Android.App;
using Android.OS;
using Android.Views;
using Android.Widget;
using System;
using System.Collections.Generic;
using System.Globalization;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
[Activity(Label|= "Query Configuration", Icon = "@drawable/MapSuite", ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation | Android.Content.PM.ConfigChanges.KeyboardHidden | Android.Content.PM.ConfigChanges.ScreenSize)]
public class ConfigurationActivity : Activity
{
private readonly string UnknownString = "Unknown";
private Feature queryFeature;
private RangeSeekBar dateRangeSeekBar;
private RangeSeekBar depthRangeSeekBar;
private RangeSeekBar magnitudeRangeSeekBar;
public ConfigurationActivity()
: base()
{ }
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Configuration);
RefreshQueryResultList();
Button queryButton = FindViewById<Button>(Resource.Id.queryButton);
ListView resultListView = FindViewById<ListView>(Resource.Id.resultListView);
magnitudeRangeSeekBar = FindViewById<RangeSeekBar>(Resource.Id.magnitudeRange);
dateRangeSeekBar = FindViewById<RangeSeekBar>(Resource.Id.dateRange);
depthRangeSeekBar = FindViewById<RangeSeekBar>(Resource.Id.depthRange);
dateRangeSeekBar.SmallRange = Global.QueryConfiguration.LowerYear;
depthRangeSeekBar.SmallRange = Global.QueryConfiguration.LowerDepth;
magnitudeRangeSeekBar.SmallRange = Global.QueryConfiguration.LowerMagnitude;
dateRangeSeekBar.BigRange = Global.QueryConfiguration.UpperYear;
depthRangeSeekBar.BigRange = Global.QueryConfiguration.UpperDepth;
magnitudeRangeSeekBar.BigRange = Global.QueryConfiguration.UpperMagnitude;
dateRangeSeekBar.SmallValue = 1568;
depthRangeSeekBar.SmallValue = 0;
magnitudeRangeSeekBar.SmallValue = 0;
dateRangeSeekBar.BigValue = 2010;
depthRangeSeekBar.BigValue = 300;
magnitudeRangeSeekBar.BigValue = 12;
dateRangeSeekBar.RangeChanged += OptionRangeSeekBar_RangeChanged;
depthRangeSeekBar.RangeChanged += OptionRangeSeekBar_RangeChanged;
magnitudeRangeSeekBar.RangeChanged += OptionRangeSeekBar_RangeChanged;
queryButton.Click += QueryButton_Click;
resultListView.ItemLongClick += ResultListView_ItemLongClick;
RegisterForContextMenu(resultListView);
RefreshQueryResultList();
}
public override void OnCreateContextMenu(IContextMenu menu, View v, IContextMenuContextMenuInfo menuInfo)
{
if (v.Id == Resource.Id.resultListView && queryFeature != null)
{
menu.SetHeaderTitle("Options");
menu.SetHeaderIcon(Android.Resource.Drawable.IcMenuInfoDetails);
menu.Add(0, Menu.First + 1, 1, "Center at").SetIcon(Android.Resource.Drawable.IcMenuInfoDetails);
menu.Add(0, Menu.First + 2, 2, "Zoom to").SetIcon(Android.Resource.Drawable.IcMenuInfoDetails);
}
base.OnCreateContextMenu(menu, v, menuInfo);
}
public override bool OnMenuItemSelected(int featureId, IMenuItem item)
{
if (queryFeature != null)
{
Finish();
LayerOverlay highLightOverlay = Global.MapView.Overlays[Global.HighlightOverlayKey] as LayerOverlay;
InMemoryFeatureLayer highlightMarkerLayer = highLightOverlay.Layers[Global.HighlightMarkerLayerKey] as InMemoryFeatureLayer;
highlightMarkerLayer.InternalFeatures.Clear();
switch (item.ItemId)
{
case Menu.First + 1:
highlightMarkerLayer.InternalFeatures.Add(queryFeature);
Global.MapView.CenterAt(queryFeature);
highLightOverlay.Refresh();
break;
case Menu.First + 2:
highlightMarkerLayer.InternalFeatures.Add(queryFeature);
Global.MapView.ZoomTo(queryFeature);
break;
default:
break;
}
}
return base.OnMenuItemSelected(featureId, item);
}
private void OptionRangeSeekBar_RangeChanged(object sender, RangeChangedEventArgs e)
{
if (sender.Equals(dateRangeSeekBar))
{
Global.QueryConfiguration.LowerYear = e.LowerValue;
Global.QueryConfiguration.UpperYear = e.UpperValue;
}
else if (sender.Equals(magnitudeRangeSeekBar))
{
Global.QueryConfiguration.LowerMagnitude = e.LowerValue;
Global.QueryConfiguration.UpperMagnitude = e.UpperValue;
}
else if (sender.Equals(depthRangeSeekBar))
{
Global.QueryConfiguration.LowerDepth = e.LowerValue;
Global.QueryConfiguration.UpperDepth = e.UpperValue;
}
}
private void ResultListView_ItemLongClick(object sender, AdapterView.ItemLongClickEventArgs e)
{
LayerOverlay highLightOverlay = Global.MapView.Overlays[Global.HighlightOverlayKey] as LayerOverlay;
InMemoryFeatureLayer selectMarkerLayer = highLightOverlay.Layers[Global.SelectMarkerLayerKey] as InMemoryFeatureLayer;
if (selectMarkerLayer != null)
{
queryFeature = selectMarkerLayer.InternalFeatures[e.Position];
e.Handled = false;
}
}
private void QueryButton_Click(object sender, EventArgs e)
{
RefreshQueryResultList();
}
private void RefreshQueryResultList()
{
TextView title = FindViewById<TextView>(Resource.Id.queryResultTitleTextView);
ListView view = FindViewById<ListView>(Resource.Id.resultListView);
EarthquakeListAdapter adapter = view.Adapter == null ? new EarthquakeListAdapter(this) : (EarthquakeListAdapter)view.Adapter;
adapter.Data.Clear();
ManagedProj4Projection mercatorToWgs84Projection = Global.GetWgs84ToMercatorProjection();
mercatorToWgs84Projection.Open();
try
{
Global.FilterSelectedEarthquakeFeatures(Global.GetBackupQueriedFeatures());
LayerOverlay highLightOverlay = Global.MapView.Overlays[Global.HighlightOverlayKey] as LayerOverlay;
InMemoryFeatureLayer selectMarkerLayer = highLightOverlay.Layers[Global.SelectMarkerLayerKey] as InMemoryFeatureLayer;
foreach (var feature in selectMarkerLayer.InternalFeatures)
{
double longitude = 0, latitude = 0;
if (double.TryParse(feature.ColumnValues["LONGITUDE"], out longitude) && double.TryParse(feature.ColumnValues["LATITIUDE"], out latitude))
{
PointShape point = new PointShape(longitude, latitude);
point = (PointShape)mercatorToWgs84Projection.ConvertToInternalProjection(point);
longitude = point.X;
latitude = point.Y;
}
double year, depth, magnitude;
double.TryParse(feature.ColumnValues["MAGNITUDE"], out magnitude);
double.TryParse(feature.ColumnValues["DEPTH_KM"], out depth);
double.TryParse(feature.ColumnValues["YEAR"], out year);
Dictionary<String, Object> result = new Dictionary<string, object>();
result["yearValue"] = year != -9999 ? year.ToString(CultureInfo.InvariantCulture) : UnknownString;
result["longitudeValue"] = longitude.ToString("f2", CultureInfo.InvariantCulture);
result["latitudeValue"] = latitude.ToString("f2", CultureInfo.InvariantCulture);
result["depthValue"] = depth != -9999 ? depth.ToString(CultureInfo.InvariantCulture) : UnknownString;
result["magnitudeValue"] = magnitude != -9999 ? magnitude.ToString(CultureInfo.InvariantCulture) : UnknownString;
result["locationValue"] = feature.ColumnValues["LOCATION"];
adapter.Data.Add(result);
}
view.Adapter = adapter;
title.Text = String.Format("Query Result (Find {0} results)", adapter.Data.Count);
}
finally
{
mercatorToWgs84Projection.Close();
}
}
}
}
Global.cs
using System.Collections.ObjectModel;
using System.Linq;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
public static class Global
{
public static readonly string EarthquakeHeatLayerKey = "EarthquakeHeatLayer";
public static readonly string EarthquakePointLayerKey = "EarthquakePointLayer";
public static readonly string SelectMarkerLayerKey = "SelectMarkerLayer";
public static readonly string HighlightMarkerLayerKey = "HighlightMarkerLayer";
public static readonly string WorldMapKitOverlayKey = "WorldMapKitOverlay";
public static readonly string OpenStreetMapOverlayKey = "OpenStreetMapOverlay";
public static readonly string BingMapsAerialOverlayKey = "BingMapsAerialOverlay";
public static readonly string BingMapsRoadOverlayKey = "BingMapsRoadOverlay";
public static readonly string EarthquakeOverlayKey = "EarthquakeOverlay";
public static readonly string HighlightOverlayKey = "HighlightOverlay";
public static readonly string PREFS_BINGMAPKEY = "BingMapKey";
public static readonly string PREFS_NAME = "SamplePrefsFile";
private static Collection<Feature> backupQueriedFeatures;
static Global()
{
QueryConfiguration = new QueryConfiguration();
backupQueriedFeatures = new Collection<Feature>();
}
public static MapView MapView { get; set; }
public static QueryConfiguration QueryConfiguration { get; set; }
public static BaseMapType BaseMapType { get; set; }
public static WorldMapKitOverlay WorldMapKitOverlay
{
get { return (WorldMapKitOverlay)MapView.Overlays[WorldMapKitOverlayKey]; }
}
public static Overlay OpenStreetMapOverlay
{
get { return MapView.Overlays[OpenStreetMapOverlayKey]; }
}
public static BingMapsOverlay BingMapsAerialOverlay
{
get { return (BingMapsOverlay)MapView.Overlays[BingMapsAerialOverlayKey]; }
}
public static BingMapsOverlay BingMapsRoadOverlay
{
get { return (BingMapsOverlay)MapView.Overlays[BingMapsRoadOverlayKey]; }
}
public static void ClearBackupQueriedFeatures()
{
backupQueriedFeatures.Clear();
}
public static void BackupQueriedFeatures(Collection<Feature> queriedFeatures)
{
backupQueriedFeatures.Clear();
foreach (var item in queriedFeatures)
{
backupQueriedFeatures.Add(item);
}
}
public static Collection<Feature> GetBackupQueriedFeatures()
{
return new Collection<Feature>(backupQueriedFeatures);
}
public static ManagedProj4Projection GetWgs84ToMercatorProjection()
{
ManagedProj4Projection wgs84ToMercatorProjection = new ManagedProj4Projection();
wgs84ToMercatorProjection.InternalProjectionParametersString = ManagedProj4Projection.GetWgs84ParametersString();
wgs84ToMercatorProjection.ExternalProjectionParametersString = ManagedProj4Projection.GetBingMapParametersString();
return wgs84ToMercatorProjection;
}
public static void FilterSelectedEarthquakeFeatures(Collection<Feature> features)
{
LayerOverlay highlightOverlay = Global.MapView.Overlays[Global.HighlightOverlayKey] as LayerOverlay;
InMemoryFeatureLayer selectMarkerLayer = highlightOverlay.Layers[Global.SelectMarkerLayerKey] as InMemoryFeatureLayer;
selectMarkerLayer.InternalFeatures.Clear();
foreach (var feature in features)
{
double year, depth, magnitude;
double.TryParse(feature.ColumnValues["MAGNITUDE"], out magnitude);
double.TryParse(feature.ColumnValues["DEPTH_KM"], out depth);
double.TryParse(feature.ColumnValues["YEAR"], out year);
if ((magnitude >= Global.QueryConfiguration.LowerMagnitude && magnitude <= Global.QueryConfiguration.UpperMagnitude || magnitude == -9999)
&& (depth <= Global.QueryConfiguration.UpperDepth && depth >= Global.QueryConfiguration.LowerDepth || depth == -9999)
&& (year >= Global.QueryConfiguration.LowerYear && year <= Global.QueryConfiguration.UpperYear) || year == -9999)
{
selectMarkerLayer.InternalFeatures.Add(feature);
}
}
highlightOverlay.Refresh();
}
}
}
QueryConfiguration.cs
namespace MapSuiteEarthquakeStatistics
{
public class QueryConfiguration
{
public QueryConfiguration()
{
LowerMagnitude = 0;
UpperMagnitude = 12;
LowerDepth = 0;
UpperDepth = 300;
LowerYear = 1568;
UpperYear = 2010;
}
public int LowerMagnitude { get; set; }
public int UpperMagnitude { get; set; }
public int LowerDepth { get; set; }
public int UpperDepth { get; set; }
public int LowerYear { get; set; }
public int UpperYear { get; set; }
}
}
SampleHelper.cs
using System.IO;
namespace MapSuiteEarthquakeStatistics
{
internal class SampleHelper
{
public readonly static string AssetsDataDictionary = @"SampleData";
public readonly static string SampleDataDictionary = @"mnt/sdcard/MapSuiteSampleData/EarthquakeStatistics";
public static string GetDataPath(string fileName)
{
return Path.Combine(SampleDataDictionary, AssetsDataDictionary, fileName);
}
}
}
SplashActivity.cs
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 MapSuiteEarthquakeStatistics
{
[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++;
}
}
}
}
}
BaseMapType.cs
namespace MapSuiteEarthquakeStatistics
{
public enum BaseMapType
{
WorldMapKitRoad = 0,
WorldMapKitAerial = 1,
WorldMapKitAerialWithLabels = 2,
OpenStreetMap = 3,
BingMapsAerial = 4,
BingMapsRoad = 5
}
}
DisplayType.cs
namespace MapSuiteEarthquakeStatistics
{
public enum DisplayType
{
Heat = 0,
Point = 1,
ISOLine = 2
}
}
EarthquakeListAdapter.cs
using Android.Content;
using Android.Views;
using Android.Widget;
using System.Collections.Generic;
namespace MapSuiteEarthquakeStatistics
{
internal class EarthquakeListAdapter : BaseAdapter
{
private LayoutInflater mInflater;
private List<Dictionary<string, object>> data;
public EarthquakeListAdapter(Context context)
{
mInflater = LayoutInflater.From(context);
}
public override int Count
{
get { return data.Count; }
}
public List<Dictionary<string, object>> Data
{
get
{
if (data == null)
{
data = new List<Dictionary<string, object>>();
}
return data;
}
}
public override Java.Lang.Object GetItem(int position)
{
Java.Util.HashMap map = new Java.Util.HashMap();
foreach (var item in data[position])
{
map.Put(item.Key, item.Value.ToString());
}
return map;
}
public override long GetItemId(int position)
{
return position;
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
EarthquakeResultHolder holder = null;
if (convertView == null)
{
holder = new EarthquakeResultHolder();
convertView = mInflater.Inflate(Resource.Layout.listviewLayout, null);
holder.YearValue = convertView.FindViewById<TextView>(Resource.Id.yearValue);
holder.LongitudeValue = convertView.FindViewById<TextView>(Resource.Id.longitudeValue);
holder.LatitudeValue = convertView.FindViewById<TextView>(Resource.Id.latitudeValue);
holder.DepthValue = convertView.FindViewById<TextView>(Resource.Id.depthValue);
holder.MagnitudeValue = convertView.FindViewById<TextView>(Resource.Id.magnitudeValue);
holder.LocationValue = convertView.FindViewById<TextView>(Resource.Id.locationValue);
convertView.Tag = holder;
}
else
{
holder = (EarthquakeResultHolder)convertView.Tag;
}
holder.YearValue.Text = data[position]["yearValue"].ToString();
holder.LongitudeValue.Text = data[position]["longitudeValue"].ToString();
holder.LatitudeValue.Text = data[position]["latitudeValue"].ToString();
holder.DepthValue.Text = data[position]["depthValue"].ToString();
holder.MagnitudeValue.Text = data[position]["magnitudeValue"].ToString();
holder.LocationValue.Text = data[position]["locationValue"].ToString();
return convertView;
}
}
}
EarthquakeResultHolder.cs
using Android.Widget;
using Java.Lang;
namespace MapSuiteEarthquakeStatistics
{
internal class EarthquakeResultHolder : Object
{
public TextView YearValue { get; set; }
public TextView LongitudeValue { get; set; }
public TextView LatitudeValue { get; set; }
public TextView DepthValue { get; set; }
public TextView MagnitudeValue { get; set; }
public TextView LocationValue { get; set; }
}
}
using Android.App;
using Android.Content;
using Android.Views;
using Android.Widget;
using Java.Net;
using System;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
using System.Xml;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
public class InputBingMapKeyDialog : AlertDialog
{
private Context context;
private View inputBingMapsKeyView;
private Button bingMapsKeyOkButton;
private ISharedPreferences preferences;
private SelectBaseMapTypeDialog selectBaseMapTypeDialog;
public InputBingMapKeyDialog(Context context, SelectBaseMapTypeDialog selectBaseMapTypeDialog, ISharedPreferences preferences)
: base(context)
{
inputBingMapsKeyView = View.Inflate(context, Resource.Layout.BingMapsKeyLayout, null);
this.SetView(inputBingMapsKeyView);
this.context = context;
this.preferences = preferences;
this.selectBaseMapTypeDialog = selectBaseMapTypeDialog;
EditText bingMapsKeyEditText = inputBingMapsKeyView.FindViewById<EditText>(Resource.Id.BingMapsKeyEditText);
Button bingMapsKeyCancelButton = inputBingMapsKeyView.FindViewById<Button>(Resource.Id.CancelButton);
bingMapsKeyOkButton = inputBingMapsKeyView.FindViewById<Button>(Resource.Id.OkButton);
bingMapsKeyOkButton.Click += BingMapsKeyOkButton_Click;
bingMapsKeyCancelButton.Click += BingMapsKeyCancelButton_Click;
}
private void BingMapsKeyOkButton_Click(object sender, EventArgs e)
{
EditText bingMapsKeyEditText = inputBingMapsKeyView.FindViewById<EditText>(Resource.Id.BingMapsKeyEditText);
string inputKey = bingMapsKeyEditText.Text;
bingMapsKeyEditText.Enabled = false;
bingMapsKeyOkButton.Enabled = false;
Task.Factory.StartNew(() =>
{
bool isValid = Validate(inputKey, BingMapsMapType.Aerial);
Global.MapView.Post(() =>
{
if (isValid)
{
Cancel();
ISharedPreferencesEditor editor = preferences.Edit();
editor.PutString(Global.PREFS_BINGMAPKEY, bingMapsKeyEditText.Text);
editor.Commit();
((BingMapsOverlay)Global.MapView.Overlays[Global.BingMapsAerialOverlayKey]).ApplicationId = bingMapsKeyEditText.Text;
((BingMapsOverlay)Global.MapView.Overlays[Global.BingMapsRoadOverlayKey]).ApplicationId = bingMapsKeyEditText.Text;
Global.MapView.Overlays[Global.WorldMapKitOverlayKey].IsVisible = false;
Global.MapView.Overlays[Global.OpenStreetMapOverlayKey].IsVisible = false;
Global.MapView.Overlays[Global.BingMapsAerialOverlayKey].IsVisible = Global.BaseMapType == BaseMapType.BingMapsAerial;
Global.MapView.Overlays[Global.BingMapsRoadOverlayKey].IsVisible = Global.BaseMapType == BaseMapType.BingMapsRoad;
Global.MapView.Refresh();
}
else
{
bingMapsKeyEditText.Enabled = true;
bingMapsKeyOkButton.Enabled = true;
Toast.MakeText(context, "The input BingMapKey is not validate.", ToastLength.Long).Show();
}
});
});
}
private void BingMapsKeyCancelButton_Click(object sender, EventArgs e)
{
Cancel();
}
private bool Validate(string bingMapsKey, BingMapsMapType mapType)
{
bool result = false;
URL url = null;
Stream stream = null;
URLConnection conn = null;
string loginServiceTemplate = "http://dev.virtualearth.net/REST/v1/Imagery/Metadata/{0}?&incl=ImageryProviders&o=xml&key={1}";
try
{
string loginServiceUri = string.Format(CultureInfo.InvariantCulture, loginServiceTemplate, mapType, bingMapsKey);
url = new URL(loginServiceUri);
conn = url.OpenConnection();
stream = conn.InputStream;
if (stream != null)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(stream);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("bing", "http://schemas.microsoft.com/search/local/ws/rest/v1");
XmlNode root = xDoc.SelectSingleNode("bing:Response", nsmgr);
XmlNode imageUrlElement = root.SelectSingleNode("bing:ResourceSets/bing:ResourceSet/bing:Resources/bing:ImageryMetadata/bing:ImageUrl", nsmgr);
XmlNodeList subdomainsElement = root.SelectNodes("bing:ResourceSets/bing:ResourceSet/bing:Resources/bing:ImageryMetadata/bing:ImageUrlSubdomains/bing:string", nsmgr);
if (imageUrlElement != null && subdomainsElement != null)
{
result = true;
}
}
}
catch
{ }
finally
{
if (url != null) url.Dispose();
if (conn != null) conn.Dispose();
if (stream != null) stream.Dispose();
}
return result;
}
}
}
RangeChangedEventArgs.cs
namespace MapSuiteEarthquakeStatistics
{
public class RangeChangedEventArgs
{
public RangeChangedEventArgs()
{ }
public int LowerValue { get; set; }
public int UpperValue { get; set; }
}
}
RangeSeekBar.cs
using Android.Content;
using Android.Graphics;
using Android.Util;
using Android.Views;
using System;
namespace MapSuiteEarthquakeStatistics
{
public class RangeSeekBar : View
{
public event EventHandler<RangeChangedEventArgs> RangeChanged;
private readonly UInt32 inRangeColor = 0xff007AFF;
private readonly UInt32 outRangeColor = 0xff777777;
private readonly UInt32 textColor = 0xffffffff;
private float lineWidth = 5.0f;
private float textSize = 25.0f;
private int lowerCenterX;
private int upperCenterX;
private int bmpWidth;
private int bmpHeight;
private Bitmap lowerBmp;
private Bitmap upperBmp;
private bool isInit;
private bool isLowerMoving;
private bool isUpperMoving;
private int paddingLeft;
private int paddingRight;
private int paddingTop;
private int paddingBottom;
private int lineHeight;
private int lineLength;
private int lineStart;
private int lineEnd;
private float smallValue;
private float bigValue;
private float smallRange;
private float bigRange;
public RangeSeekBar(Context content)
: this(content, null)
{ }
public RangeSeekBar(Context content, IAttributeSet attrs)
: base(content, attrs)
{
isInit = false;
isLowerMoving = false;
isUpperMoving = false;
smallValue = 0.0f;
bigValue = 100.0f;
paddingLeft = 100;
paddingRight = 100;
paddingTop = 10;
paddingBottom = 10;
smallRange = smallValue;
bigRange = bigValue;
lowerBmp = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.Slider);
upperBmp = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.Slider);
bmpWidth = upperBmp.Width;
bmpHeight = upperBmp.Height;
}
public float SmallValue
{
get { return smallValue; }
set { smallValue = value; }
}
public float BigValue
{
get { return bigValue; }
set { bigValue = value; }
}
public float SmallRange
{
get { return smallRange; }
set { smallRange = value; }
}
public float BigRange
{
get { return bigRange; }
set { bigRange = value; }
}
private int MeasureWidth(int measureSpec)
{
int result = 0;
MeasureSpecMode specMode = MeasureSpec.GetMode(measureSpec);
int specSize = MeasureSpec.GetSize(measureSpec);
if (specMode == MeasureSpecMode.Exactly)
{
result = specSize;
}
else
{
result = paddingLeft + paddingRight + bmpWidth * 2;
if (specMode == MeasureSpecMode.AtMost)
{
result = System.Math.Min(result, specSize);
}
}
return result;
}
private int MeasureHeight(int measureHeight)
{
int result = 0;
MeasureSpecMode specMode = MeasureSpec.GetMode(measureHeight);
int specSize = MeasureSpec.GetSize(measureHeight);
if (specMode == MeasureSpecMode.Exactly)
{
result = bmpHeight * 2;
}
else
{
result = bmpHeight + paddingTop + paddingBottom;
if (specMode == MeasureSpecMode.AtMost)
{
result = System.Math.Min(result, specSize);
}
}
return result;
}
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
widthMeasureSpec = MeasureWidth(widthMeasureSpec);
heightMeasureSpec = MeasureHeight(heightMeasureSpec);
SetMeasuredDimension(widthMeasureSpec, heightMeasureSpec);
}
protected override void OnDraw(Canvas canvas)
{
base.OnDraw(canvas);
if (!isInit)
{ Init(canvas); }
bmpWidth = upperBmp.Width;
bmpHeight = upperBmp.Height;
lineHeight = this.Height - paddingBottom - lowerBmp.Height / 2;
int barHeight = this.Height - paddingBottom - lowerBmp.Height / 2;
float textHeight = (this.Height / 2f) + (textSize) / 2 - 3;
// Line Style
Paint linePaint = new Paint();
linePaint.AntiAlias = true;
linePaint.StrokeWidth = lineWidth;
// Draw Highlight Line
linePaint.Color = new Color((int)inRangeColor);
canvas.DrawLine(lowerCenterX, barHeight, upperCenterX, barHeight, linePaint);
// Draw Line
linePaint.Color = new Color((int)outRangeColor);
canvas.DrawLine(lineStart, barHeight, lowerCenterX, barHeight, linePaint);
canvas.DrawLine(upperCenterX, barHeight, lineEnd, barHeight, linePaint);
// Draw Slider
Paint bmpPaint = new Paint();
canvas.DrawBitmap(lowerBmp, lowerCenterX - bmpWidth / 2, barHeight - bmpHeight / 2, bmpPaint);
canvas.DrawBitmap(lowerBmp, upperCenterX - bmpWidth / 2, barHeight - bmpHeight / 2, bmpPaint);
// Draw Text
Paint textPaint = new Paint();
textPaint.Color = new Color((int)textColor);
textPaint.TextSize = textSize;
textPaint.AntiAlias = true;
textPaint.StrokeWidth = lineWidth;
int small = (int)Math.Round(smallRange);
int big = (int)Math.Round(bigRange);
canvas.DrawText(small.ToString(), 2, textHeight, textPaint);
canvas.DrawText(big.ToString(), Width - textSize / 2 * big.ToString().Length - 5, textHeight, textPaint);
}
private void Init(Canvas canvas)
{
textSize = this.Height / 4;
paddingLeft = canvas.Width / 7;
paddingRight = canvas.Width / 7;
lineLength = this.Width - paddingLeft - paddingRight;
lineStart = paddingLeft;
lineEnd = lineLength + paddingLeft;
lowerCenterX = lineStart;
upperCenterX = lineEnd;
lineHeight = this.Height - paddingBottom - lowerBmp.Height / 2;
lowerCenterX = InvertComputRange(smallRange);
upperCenterX = InvertComputRange(bigRange);
isInit = true;
}
public override bool OnTouchEvent(MotionEvent e)
{
base.OnTouchEvent(e);
float xPos = e.GetX();
switch (e.Action)
{
case MotionEventActions.Down:
float yPos = e.GetY();
if (System.Math.Abs(yPos - lineHeight) > bmpHeight / 1.5)
{
return false;
}
if (System.Math.Abs(xPos - lowerCenterX) < bmpWidth / 1.5)
{
isLowerMoving = true;
}
if (System.Math.Abs(xPos - upperCenterX) < bmpWidth / 1.5)
{
isUpperMoving = true;
}
if (xPos >= lineStart && xPos <= lowerCenterX - bmpWidth / 2)
{
lowerCenterX = (int)xPos;
UpdateRange();
PostInvalidate();
}
if (xPos <= lineEnd && xPos >= upperCenterX + bmpWidth / 2)
{
upperCenterX = (int)xPos;
UpdateRange();
PostInvalidate();
}
break;
case MotionEventActions.Move:
if (isLowerMoving)
{
if (xPos >= lineStart && xPos < upperCenterX - bmpWidth)
{
lowerCenterX = (int)xPos;
UpdateRange();
PostInvalidate();
}
}
if (isUpperMoving)
{
if (xPos > lowerCenterX + bmpWidth && xPos < lineEnd)
{
upperCenterX = (int)xPos;
UpdateRange();
PostInvalidate();
}
}
break;
case MotionEventActions.Up:
isLowerMoving = false;
isUpperMoving = false;
break;
default:
break;
}
return true;
}
private void UpdateRange()
{
smallRange = ComputRange(lowerCenterX);
bigRange = ComputRange(upperCenterX);
OnRangeChanged(new RangeChangedEventArgs() { LowerValue = (int)Math.Round(smallRange), UpperValue = (int)Math.Round(bigRange) });
}
private float ComputRange(float range)
{
return (range - lineStart) * (bigValue - smallValue) / lineLength
+ smallValue;
}
private int InvertComputRange(float range)
{
return (int)((range - smallValue) * lineLength / (bigValue - smallValue) + lineStart);
}
protected virtual void OnRangeChanged(RangeChangedEventArgs e)
{
if (RangeChanged != null)
{
RangeChanged(this, e);
}
}
}
}
SelectBaseMapTypeDialog.cs
using Android.App;
using Android.Content;
using Android.Views;
using Android.Widget;
using System;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
public class SelectBaseMapTypeDialog : AlertDialog
{
private ISharedPreferences preferences;
private View selectBaseMapTypeView;
private string tempBaseMap;
private Context context;
private Button baseMapOkButton;
private Button baseMapCancelButton;
private RadioButton wmkRoadRadioButton;
private RadioButton wmkAerialRadioButton;
private RadioButton wmkAerialWithLabelsRadioButton;
private RadioButton osmRadioButton;
private RadioButton bingaRadioButton;
private RadioButton bingrRadioButton;
public SelectBaseMapTypeDialog(Context context, ISharedPreferences preferences)
: base(context)
{
this.context = context;
this.preferences = preferences;
selectBaseMapTypeView = View.Inflate(context, Resource.Layout.SelectBaseMapTypeLayout, null);
this.SetView(selectBaseMapTypeView);
wmkRoadRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.wmkRoadRadioButton);
wmkAerialRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.wmkAerialRadioButton);
wmkAerialWithLabelsRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.wmkAerialWithLabelsRadioButton);
osmRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.osmRadioButton);
bingaRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.bingaRadioButton);
bingrRadioButton = selectBaseMapTypeView.FindViewById<RadioButton>(Resource.Id.bingrRadioButton);
wmkRoadRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
wmkAerialRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
wmkAerialWithLabelsRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
osmRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
bingaRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
bingrRadioButton.CheckedChange += BaseMapRadioButton_CheckedChange;
baseMapOkButton = selectBaseMapTypeView.FindViewById<Button>(Resource.Id.OkButton);
baseMapCancelButton = selectBaseMapTypeView.FindViewById<Button>(Resource.Id.CancelButton);
baseMapOkButton.Click += BaseMapOkButton_Click;
baseMapCancelButton.Click += (sender, args) => Cancel();
}
public override void Show()
{
RefreshBaseMapTypeControls();
base.Show();
}
private void BaseMapRadioButton_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
{
RadioButton radioButton = (RadioButton)sender;
if (radioButton.Checked)
{
tempBaseMap = radioButton.Text;
}
}
private void RefreshBaseMap()
{
BaseMapType mapType;
string baseMapTypeString = tempBaseMap.Replace(" ", "");
if (Enum.TryParse(baseMapTypeString, true, out mapType)) Global.BaseMapType = mapType;
switch (Global.BaseMapType)
{
case BaseMapType.WorldMapKitRoad:
Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.Road;
Global.WorldMapKitOverlay.IsVisible = true;
Global.OpenStreetMapOverlay.IsVisible = false;
Global.BingMapsAerialOverlay.IsVisible = false;
Global.BingMapsRoadOverlay.IsVisible = false;
Global.MapView.Refresh();
break;
case BaseMapType.WorldMapKitAerial:
Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.Aerial;
Global.WorldMapKitOverlay.IsVisible = true;
Global.OpenStreetMapOverlay.IsVisible = false;
Global.BingMapsAerialOverlay.IsVisible = false;
Global.BingMapsRoadOverlay.IsVisible = false;
Global.MapView.Refresh();
break;
case BaseMapType.WorldMapKitAerialWithLabels:
Global.WorldMapKitOverlay.MapType = WorldMapKitMapType.AerialWithLabels;
Global.WorldMapKitOverlay.IsVisible = true;
Global.OpenStreetMapOverlay.IsVisible = false;
Global.BingMapsAerialOverlay.IsVisible = false;
Global.BingMapsRoadOverlay.IsVisible = false;
Global.MapView.Refresh();
break;
case BaseMapType.OpenStreetMap:
Global.WorldMapKitOverlay.IsVisible = false;
Global.OpenStreetMapOverlay.IsVisible = true;
Global.BingMapsAerialOverlay.IsVisible = false;
Global.BingMapsRoadOverlay.IsVisible = false;
Global.MapView.Refresh();
break;
case BaseMapType.BingMapsAerial:
case BaseMapType.BingMapsRoad:
string result = preferences.GetString(Global.PREFS_BINGMAPKEY, string.Empty);
if (!string.IsNullOrEmpty(result))
{
((BingMapsOverlay)Global.MapView.Overlays[Global.BingMapsAerialOverlayKey]).ApplicationId = result;
((BingMapsOverlay)Global.MapView.Overlays[Global.BingMapsRoadOverlayKey]).ApplicationId = result;
Global.MapView.Overlays[Global.WorldMapKitOverlayKey].IsVisible = false;
Global.MapView.Overlays[Global.OpenStreetMapOverlayKey].IsVisible = false;
Global.MapView.Overlays[Global.BingMapsAerialOverlayKey].IsVisible = Global.BaseMapType == BaseMapType.BingMapsAerial;
Global.MapView.Overlays[Global.BingMapsRoadOverlayKey].IsVisible = Global.BaseMapType == BaseMapType.BingMapsRoad;
}
else
{
InputBingMapKeyDialog dialog = new InputBingMapKeyDialog(context, this, preferences);
dialog.Show();
}
break;
}
}
private void BaseMapOkButton_Click(object sender, EventArgs e)
{
RefreshBaseMap();
Cancel();
}
private void RefreshBaseMapTypeControls()
{
switch (Global.BaseMapType)
{
case BaseMapType.WorldMapKitRoad:
wmkRoadRadioButton.Checked = true;
break;
case BaseMapType.WorldMapKitAerial:
wmkAerialRadioButton.Checked = true;
break;
case BaseMapType.WorldMapKitAerialWithLabels:
wmkAerialWithLabelsRadioButton.Checked = true;
break;
case BaseMapType.OpenStreetMap:
osmRadioButton.Checked = true;
break;
case BaseMapType.BingMapsRoad:
bingrRadioButton.Checked = true;
break;
case BaseMapType.BingMapsAerial:
bingaRadioButton.Checked = true;
break;
default:
break;
}
}
}
}
SelectDisplayTypeDialog.cs
using Android.App;
using Android.Content;
using Android.Views;
using Android.Widget;
using System;
using ThinkGeo.MapSuite.AndroidEdition;
using ThinkGeo.MapSuite.Core;
namespace MapSuiteEarthquakeStatistics
{
public class SelectDisplayTypeDialog : AlertDialog
{
private DisplayType displayType;
private DisplayType oldDisplayType;
private View selectDisplayTypeView;
private LayerOverlay earthquakeOverlay;
private HeatLayer earthquakeHeatLayer;
private ShapeFileFeatureLayer earthquakePointLayer;
private RadioButton heatRadioButton;
private RadioButton isoRadioButton;
private RadioButton pointRadioButton;
private Button displayTypeOkButton;
private Button displayTypeCancelButton;
public SelectDisplayTypeDialog(Context context, DisplayType displayType)
: base(context)
{
selectDisplayTypeView = View.Inflate(context, Resource.Layout.SelectDisplayStyleTypeLayout, null);
this.SetView(selectDisplayTypeView);
this.displayType = displayType;
earthquakeOverlay = Global.MapView.Overlays[Global.EarthquakeOverlayKey] as LayerOverlay;
earthquakePointLayer = earthquakeOverlay.Layers[Global.EarthquakePointLayerKey] as ShapeFileFeatureLayer;
earthquakeHeatLayer = earthquakeOverlay.Layers[Global.EarthquakeHeatLayerKey] as HeatLayer;
heatRadioButton = selectDisplayTypeView.FindViewById<RadioButton>(Resource.Id.HeatStyleRadioButton);
isoRadioButton = selectDisplayTypeView.FindViewById<RadioButton>(Resource.Id.IsoLineStyleRadioButton);
pointRadioButton = selectDisplayTypeView.FindViewById<RadioButton>(Resource.Id.PointStyleRadioButton);
displayTypeOkButton = selectDisplayTypeView.FindViewById<Button>(Resource.Id.OkButton);
displayTypeCancelButton = selectDisplayTypeView.FindViewById<Button>(Resource.Id.CancelButton);
heatRadioButton.CheckedChange += DisplayTypeRadioButton_CheckedChange;
isoRadioButton.CheckedChange += DisplayTypeRadioButton_CheckedChange;
pointRadioButton.CheckedChange += DisplayTypeRadioButton_CheckedChange;
displayTypeCancelButton.Click += DisplayTypeCancelButton_Click;
displayTypeOkButton.Click += DisplayTypeOkButton_Click;
}
public override void Show()
{
oldDisplayType = displayType;
base.Show();
}
private void DisplayTypeRadioButton_CheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
{
if (sender.Equals(heatRadioButton) && heatRadioButton.Checked)
{
displayType = DisplayType.Heat;
}
else if (sender.Equals(isoRadioButton) && isoRadioButton.Checked)
{
displayType = DisplayType.ISOLine;
}
else if (sender.Equals(pointRadioButton) && pointRadioButton.Checked)
{
displayType = DisplayType.Point;
}
}
private void DisplayTypeOkButton_Click(object sender, EventArgs e)
{
this.Cancel();
earthquakePointLayer.IsVisible = false;
earthquakeHeatLayer.IsVisible = false;
if (displayType == DisplayType.Heat)
{
earthquakeHeatLayer.IsVisible = true;
}
else if (displayType == DisplayType.Point)
{
earthquakePointLayer.IsVisible = true;
}
earthquakeOverlay.Refresh();
}
private void DisplayTypeCancelButton_Click(object sender, EventArgs e)
{
this.Cancel();
displayType = oldDisplayType;
switch (displayType)
{
case DisplayType.Heat:
heatRadioButton.Checked = true;
break;
case DisplayType.ISOLine:
isoRadioButton.Checked = true;
break;
case DisplayType.Point:
pointRadioButton.Checked = true;
break;
}
}
}
}
AssemblyInfo.cs
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("MapSuiteEarthquakeStatistics")]
[assembly: AssemblyDescription("")]
[assembly:|AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly:|AssemblyProduct("MapSuiteEarthquakeStatistics")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[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")]
Resource.Designer.cs
#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("MapSuiteEarthquakeStatistics.Resource", IsApplication=true)]
namespace MapSuiteEarthquakeStatistics
{
[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::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_default256x256;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_default512x512 = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_default512x512;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_globe;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_globe_Pressed = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_globe_Pressed;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_Minus;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Minus_Pressed = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_Minus_Pressed;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_noImageTile = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_noImageTile;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_Plus;
global::ThinkGeo.MapSuite.AndroidEdition.Resource.Drawable.icon_mapsuite_Plus_Pressed = global::MapSuiteEarthquakeStatistics.Resource.Drawable.icon_mapsuite_Plus_Pressed;
}
public partial class Attribute
{
static Attribute()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Attribute()
{
}
}
public partial class Drawable
{
// aapt resource value: 0x7f020000
public const int basemap = 2130837504;
// aapt resource value: 0x7f020001
public const int capture = 2130837505;
// aapt resource value: 0x7f020002
public const int clear = 2130837506;
// aapt resource value: 0x7f020003
public const int crossicon = 2130837507;
// aapt resource value: 0x7f020004
public const int displaytype = 2130837508;
// aapt resource value: 0x7f020005
public const int displaytype_bing_aerial = 2130837509;
// aapt resource value: 0x7f020006
public const int displaytype_bing_road = 2130837510;
// aapt resource value: 0x7f020007
public const int displaytype_osm = 2130837511;
// aapt resource value: 0x7f020008
public const int displaytype_wmk = 2130837512;
// aapt resource value: 0x7f020009
public const int draw_polygon = 2130837513;
// aapt resource value: 0x7f02000a
public const int draw_polygon_check = 2130837514;
// aapt resource value: 0x7f02000b
public const int draw_Rectangle = 2130837515;
// aapt resource value: 0x7f02000c
public const int draw_Rectangle_check = 2130837516;
// aapt resource value: 0x7f02000d
public const int Icon = 2130837517;
// aapt resource value: 0x7f02000e
public const int icon_mapsuite_default256x256 = 2130837518;
// aapt resource value: 0x7f02000f
public const int icon_mapsuite_default512x512 = 2130837519;
// aapt resource value: 0x7f020010
public const int icon_mapsuite_globe = 2130837520;
// aapt resource value: 0x7f020011
public const int icon_mapsuite_globe_Pressed = 2130837521;
// aapt resource value: 0x7f020012
public const int icon_mapsuite_Minus = 2130837522;
// aapt resource value: 0x7f020013
public const int icon_mapsuite_Minus_Pressed = 2130837523;
// aapt resource value: 0x7f020014
public const int icon_mapsuite_noImageTile = 2130837524;
// aapt resource value: 0x7f020015
public const int icon_mapsuite_Plus = 2130837525;
// aapt resource value: 0x7f020016
public const int icon_mapsuite_Plus_Pressed = 2130837526;
// aapt resource value: 0x7f020017
public const int linearlayoutStyle = 2130837527;
// aapt resource value: 0x7f020018
public const int MapSuite = 2130837528;
// aapt resource value: 0x7f020019
public const int Pan_check = 2130837529;
// aapt resource value: 0x7f02001a
public const int Pan_KeyDown = 2130837530;
// aapt resource value: 0x7f02001b
public const int Pan_Uncheck = 2130837531;
// aapt resource value: 0x7f02001c
public const int panicon1 = 2130837532;
// aapt resource value: 0x7f02001d
public const int panicon1_check = 2130837533;
// aapt resource value: 0x7f02001e
public const int panicon1_on = 2130837534;
// aapt resource value: 0x7f02001f
public const int panicon2 = 2130837535;
// aapt resource value: 0x7f020020
public const int panicon3 = 2130837536;
// aapt resource value: 0x7f020021
public const int polygonicon = 2130837537;
// aapt resource value: 0x7f020022
public const int rectangleicon = 2130837538;
// aapt resource value: 0x7f020023
public const int recycleicon1 = 2130837539;
// aapt resource value: 0x7f020024
public const int recycleicon2 = 2130837540;
// aapt resource value: 0x7f020025
public const int save = 2130837541;
// aapt resource value: 0x7f020026
public const int searchicon = 2130837542;
// aapt resource value: 0x7f020027
public const int Slider = 2130837543;
static Drawable()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Drawable()
{
}
}
public partial class Id
{
// aapt resource value: 0x7f050001
public const int BingMapsKeyEditText = 2131034113;
// aapt resource value: 0x7f050003
public const int CancelButton = 2131034115;
// aapt resource value: 0x7f050019
public const int ClearButton = 2131034137;
// aapt resource value: 0x7f050017
public const int DrawPolygonButton = 2131034135;
// aapt resource value: 0x7f050018
public const int DrawRectangleButton = 2131034136;
// aapt resource value: 0x7f050022
public const int HeatStyleRadioButton = 2131034146;
// aapt resource value: 0x7f050023
public const int IsoLineStyleRadioButton = 2131034147;
// aapt resource value: 0x7f05001a
public const int MoreOptionsButton = 2131034138;
// aapt resource value: 0x7f050002
public const int OkButton = 2131034114;
// aapt resource value: 0x7f050016
public const int PanButton = 2131034134;
// aapt resource value: 0x7f050021
public const int PointStyleRadioButton = 2131034145;
// aapt resource value: 0x7f050014
public const int ToolsLinearLayout = 2131034132;
// aapt resource value: 0x7f050013
public const int androidMap = 2131034131;
// aapt resource value: 0x7f05001f
public const int bingaRadioButton = 2131034143;
// aapt resource value: 0x7f050020
public const int bingrRadioButton = 2131034144;
// aapt resource value: 0x7f050008
public const int dateRange = 2131034120;
// aapt resource value: 0x7f050007
public const int depthRange = 2131034119;
// aapt resource value: 0x7f05000f
public const int depthValue = 2131034127;
// aapt resource value: 0x7f05000e
public const int latitudeValue = 2131034126;
// aapt resource value: 0x7f050005
public const int linearLayout1 = 2131034117;
// aapt resource value: 0x7f050009
public const int linearLayout3 = 2131034121;
// aapt resource value: 0x7f050011
public const int locationValue = 2131034129;
// aapt resource value: 0x7f05000d
public const int longitudeValue = 2131034125;
// aapt resource value: 0x7f050006
public const int magnitudeRange = 2131034118;
// aapt resource value: 0x7f050010
public const int magnitudeValue = 2131034128;
// aapt resource value: 0x7f050004
public const int mainLayout = 2131034116;
// aapt resource value: 0x7f05001e
public const int osmRadioButton = 2131034142;
// aapt resource value: 0x7f05000a
public const int queryButton = 2131034122;
// aapt resource value: 0x7f05000b
public const int queryResultTitleTextView = 2131034123;
// aapt resource value: 0x7f050015
public const int radioGroup1 = 2131034133;
// aapt resource value: 0x7f050012
public const int resultListView = 2131034130;
// aapt resource value: 0x7f050000
public const int textView1 = 2131034112;
// aapt resource value: 0x7f050025
public const int uploadDataTextView = 2131034149;
// aapt resource value: 0x7f050024
public const int uploadProgressBar = 2131034148;
// aapt resource value: 0x7f05001c
public const int wmkAerialRadioButton = 2131034140;
// aapt resource value: 0x7f05001d
public const int wmkAerialWithLabelsRadioButton = 2131034141;
// aapt resource value: 0x7f05001b
public const int wmkRoadRadioButton = 2131034139;
// aapt resource value: 0x7f05000c
public const int yearValue = 2131034124;
static Id()
{
global::Android.Runtime.ResourceIdManager.UpdateIdValues();
}
private Id()
{
}
}
public partial class Layout
{
// aapt resource value: 0x7f030000
public const int BingMapsKeyLayout = 2130903040;
// aapt resource value: 0x7f030001
public const int Configuration = 2130903041;
// aapt resource value: 0x7f030002
public const int listviewLayout = 2130903042;
// aapt resource value: 0x7f030003
public const int Main = 2130903043;
// aapt resource value: 0x7f030004
public const int RadioButtonTextColorSelector = 2130903044;
// aapt resource value: 0x7f030005
public const int SelectBaseMapTypeLayout = 2130903045;
// aapt resource value: 0x7f030006
public const int SelectDisplayStyleTypeLayout = 2130903046;
// aapt resource value: 0x7f030007
public const int SelectorDrawPolygon = 2130903047;
// aapt resource value: 0x7f030008
public const int SelectorDrawRectangle = 2130903048;
// aapt resource value: 0x7f030009
public const int SelectorPan = 2130903049;
// aapt resource value: 0x7f03000a
public const int SplashLayout = 2130903050;
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