Skip to content
This repository has been archived by the owner on Sep 3, 2019. It is now read-only.

Commit

Permalink
Add Unified version of API and sample. Test is not yet ported.
Browse files Browse the repository at this point in the history
  • Loading branch information
kochizufan committed Jan 18, 2015
1 parent d4fceb8 commit a2508b8
Show file tree
Hide file tree
Showing 35 changed files with 1,745 additions and 5,190 deletions.
34 changes: 19 additions & 15 deletions OsmSharp.iOS.UI.Sample/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;

#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif

namespace OsmSharp.iOS.UI.Sample
{
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
SampleViewController viewController;
[Register("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
SampleViewController viewController;

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);

viewController = new SampleViewController();
window.RootViewController = viewController;
viewController = new SampleViewController();
window.RootViewController = viewController;

window.MakeKeyAndVisible();
window.MakeKeyAndVisible();

return true;
}
}
return true;
}
}
}
6 changes: 5 additions & 1 deletion OsmSharp.iOS.UI.Sample/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
using System;
using System.Collections.Generic;
using System.Linq;

#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif

namespace OsmSharp.iOS.UI.Sample
{
Expand Down
210 changes: 107 additions & 103 deletions OsmSharp.iOS.UI.Sample/SampleViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Drawing;
using System.Reflection;
using System.Timers;
using MonoTouch.UIKit;
using OsmSharp.Collections.Tags;
using OsmSharp.Logging;
using OsmSharp.Math.Geo;
Expand All @@ -35,14 +34,19 @@
using OsmSharp.UI.Map.Layers;
using OsmSharp.UI.Renderer.Scene;
using OsmSharp.iOS.UI.Controls;
#if __UNIFIED__
using UIKit;
#else
using MonoTouch.UIKit;
#endif

namespace OsmSharp.iOS.UI.Sample
{
/// <summary>
/// The sample view controller.
/// </summary>
public class SampleViewController : UIViewController
{
public class SampleViewController : UIViewController
{
/// <summary>
/// Holds the router.
/// </summary>
Expand All @@ -68,18 +72,18 @@ public class SampleViewController : UIViewController
/// </summary>
private IEnumerator<GeoCoordinate> _enumerator;

/// <summary>
/// Holds the center marker.
/// </summary>
private MapMarker _centerMarker;
/// <summary>
/// Holds the center marker.
/// </summary>
private MapMarker _centerMarker;

/// <summary>
/// Initializes a new instance of the <see cref="OsmSharp.iOS.UI.Sample.SampleViewController"/> class.
/// </summary>
public SampleViewController()
{
public SampleViewController()
{

}
}

/// <summary>
/// Initializes the View property.
Expand All @@ -88,19 +92,19 @@ public override void LoadView ()
{
base.LoadView ();

// initialize OsmSharp native hooks.
Native.Initialize();
// initialize OsmSharp native hooks.
Native.Initialize();

// enable the loggging.
// enable the loggging.
OsmSharp.Logging.Log.Enable();
OsmSharp.Logging.Log.RegisterListener(new OsmSharp.iOS.UI.Log.ConsoleTraceListener());

// initialize map.
var map = new Map();
// add a tile layer.
// map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
// map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom(
// Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.iOS.UI.Sample.kempen.mbtiles"), "map")));
// map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png"));
// map.AddLayer(new LayerMBTile(SQLiteConnection.CreateFrom(
// Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.iOS.UI.Sample.kempen.mbtiles"), "map")));

// add an online osm-data->mapCSS translation layer.
//map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter));
Expand All @@ -109,113 +113,113 @@ public override void LoadView ()
"OsmSharp.iOS.UI.Sample.default.map");
map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true)));

// var primitivesLayer = new LayerPrimitives(map.Projection);
// primitivesLayer.AddPoint(new GeoCoordinate(51.26371, 4.78601), 10,
// SimpleColor.FromKnownColor(KnownColor.Blue).Value);
// map.AddLayer(primitivesLayer);
// var primitivesLayer = new LayerPrimitives(map.Projection);
// primitivesLayer.AddPoint(new GeoCoordinate(51.26371, 4.78601), 10,
// SimpleColor.FromKnownColor(KnownColor.Blue).Value);
// map.AddLayer(primitivesLayer);

// // define dummy from and to points.
// // define dummy from and to points.
var from = new GeoCoordinate(51.261203, 4.780760);
var to = new GeoCoordinate(51.267797, 4.801362);
//
// // deserialize the pre-processed graph.
// var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
// TagsCollectionBase metaData = null;
// var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
// "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing");
// var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);
//
// // initialize router.
// _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());
//
// // resolve points.
// RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
// RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
//
// // calculate route.
// Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
// RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
// _enumerator = route.GetRouteEnumerable(10).GetEnumerator();
//
// // add a router layer.
// _routeLayer = new LayerRoute(map.Projection);
// _routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
// map.AddLayer(_routeLayer);
//
// // deserialize the pre-processed graph.
// var routingSerializer = new CHEdgeDataDataSourceSerializer(false);
// TagsCollectionBase metaData = null;
// var graphStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
// "OsmSharp.iOS.UI.Sample.kempen-big.osm.pbf.routing");
// var graphDeserialized = routingSerializer.Deserialize(graphStream, out metaData, true);
//
// // initialize router.
// _router = Router.CreateCHFrom(graphDeserialized, new CHRouter(), new OsmRoutingInterpreter());
//
// // resolve points.
// RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, from);
// RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, to);
//
// // calculate route.
// Route route = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2);
// RouteTracker routeTracker = new RouteTracker(route, new OsmRoutingInterpreter());
// _enumerator = route.GetRouteEnumerable(10).GetEnumerator();
//
// // add a router layer.
// _routeLayer = new LayerRoute(map.Projection);
// _routeLayer.AddRoute (route, SimpleColor.FromKnownColor(KnownColor.Blue, 125).Value, 12);
// map.AddLayer(_routeLayer);

// define the mapview.
_mapView = new MapView();
//_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent);
_mapView.MapAllowTilt = false;
_mapView.MapAllowTilt = false;
_mapView.Map = map;
_mapView.MapMaxZoomLevel = 19;
_mapView.MapMinZoomLevel = 0;
_mapView.MapMaxZoomLevel = 19;
_mapView.MapMinZoomLevel = 0;
_mapView.MapTilt = 0;
_mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601);
_mapView.MapZoom = 18;
_mapView.MapInitialized += _mapView_MapInitialized;
_mapView.MapInitialized += _mapView_MapInitialized;

// add markers.
var marker = _mapView.AddMarker (from);
var popupTextView = new UITextView();
popupTextView.Text = "Hey, this is popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);
marker = _mapView.AddMarker (to);
popupTextView = new UITextView();
popupTextView.Text = "Hey, this is another popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);
// add markers.
var marker = _mapView.AddMarker (from);
var popupTextView = new UITextView();
popupTextView.Text = "Hey, this is popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);
marker = _mapView.AddMarker (to);
popupTextView = new UITextView();
popupTextView.Text = "Hey, this is another popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);

this.AddMarkers();
this.AddMarkers();

// add center marker.
_centerMarker = _mapView.AddMarker(_mapView.MapCenter);
// add center marker.
_centerMarker = _mapView.AddMarker(_mapView.MapCenter);

// create the route tracker animator.
// _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);
// _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5, 17);

// // simulate a number of gps-location update along the calculated route.
// Timer timer = new Timer(250);
// timer.Elapsed += new ElapsedEventHandler(TimerHandler);
// timer.Start();
// // simulate a number of gps-location update along the calculated route.
// Timer timer = new Timer(250);
// timer.Elapsed += new ElapsedEventHandler(TimerHandler);
// timer.Start();

View = _mapView;
}

void AddMarkers()
{
var from = new GeoCoordinate(51.261203, 4.780760);
var to = new GeoCoordinate(51.267797, 4.801362);

var box = new GeoCoordinateBox(from, to);

_mapView.ClearMarkers();

MapMarker marker;
for (int idx = 0; idx < 20; idx++)
{
var pos = box.GenerateRandomIn();
marker = _mapView.AddMarker(pos);
var popupTextView = new UITextView();
popupTextView.Text = "Hey, this is popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);
}
}


/// <summary>
/// Called when the map was first initialized.
/// </summary>
/// <param name="mapView">Map view.</param>
/// <param name="newZoom">New zoom.</param>
/// <param name="newTilt">New tilt.</param>
/// <param name="newCenter">New center.</param>
private void _mapView_MapInitialized(OsmSharp.UI.IMapView mapView, float newZoom, OsmSharp.Units.Angle.Degree newTilt, GeoCoordinate newCenter)
{
// make sure the center marker stays in place from now on.
_centerMarker.MoveWithMap = false;
}
void AddMarkers()
{
var from = new GeoCoordinate(51.261203, 4.780760);
var to = new GeoCoordinate(51.267797, 4.801362);

var box = new GeoCoordinateBox(from, to);

_mapView.ClearMarkers();

MapMarker marker;
for (int idx = 0; idx < 20; idx++)
{
var pos = box.GenerateRandomIn();
marker = _mapView.AddMarker(pos);
var popupTextView = new UITextView();
popupTextView.Text = "Hey, this is popup text!";
popupTextView.BackgroundColor = UIColor.FromWhiteAlpha(0.5f, 0.5f);
marker.AddPopup(popupTextView, 100, 100);
}
}


/// <summary>
/// Called when the map was first initialized.
/// </summary>
/// <param name="mapView">Map view.</param>
/// <param name="newZoom">New zoom.</param>
/// <param name="newTilt">New tilt.</param>
/// <param name="newCenter">New center.</param>
private void _mapView_MapInitialized(OsmSharp.UI.IMapView mapView, float newZoom, OsmSharp.Units.Angle.Degree newTilt, GeoCoordinate newCenter)
{
// make sure the center marker stays in place from now on.
_centerMarker.MoveWithMap = false;
}

/// <summary>
/// Handles the timer event from the timer.
Expand All @@ -233,5 +237,5 @@ private void TimerHandler(object sender, ElapsedEventArgs e)
_routeTrackerAnimator.Track(other);
}
}
}
}
}
Loading

0 comments on commit a2508b8

Please sign in to comment.