public RouteTrackerDisplayLocationDataSource(LocationDataSource dataSource, RouteTracker routeTracker) { // Set the data source _inputDataSource = dataSource ?? throw new ArgumentNullException(nameof(dataSource)); // Set the route tracker. _routeTracker = routeTracker ?? throw new ArgumentNullException(nameof(routeTracker)); // Change the tracker location when the source location changes. _inputDataSource.LocationChanged += InputLocationChanged; // Update the location output when the tracker location updates. _routeTracker.TrackingStatusChanged += TrackingStatusChanged; }
/// <summary> /// Creates a new route tracker animator. /// </summary> /// <param name="mapView">The mapview.</param> /// <param name="routeTracker">The tracker tracking the route.</param> /// <param name="restartAfterTouch">The time in second to wait before resuming tracking after the mapview is touched.</param> /// <param name="defaultZoom">The default zoom.</param> public RouteTrackerAnimator(IMapView mapView, RouteTracker routeTracker, Second restartAfterTouch, float defaultZoom) { this.MinZoom = 18; this.MaxZoom = 30; this.DefaultZoom = defaultZoom; _mapView = mapView; _animator = new MapViewAnimator(mapView); _routeTracker = routeTracker; _minimumTrackGap = new TimeSpan(0, 0, 0, 0, 500).Ticks; this.RestartAfterTouch = restartAfterTouch; _mapView.MapTouched += MapViewMapTouched; }
private void SampleUnloaded(object sender, RoutedEventArgs e) { // Stop the speech synthesizer. _mediaElement.Stop(); _speechSynthesizer.Dispose(); // Stop the tracker. if (_tracker != null) { _tracker.TrackingStatusChanged -= TrackingStatusUpdated; _tracker.NewVoiceGuidance -= SpeakDirection; _tracker = null; } // Stop the location data source. MyMapView.LocationDisplay?.DataSource?.StopAsync(); }
private void NavigateButton_Clicked(object sender, EventArgs e) { // Create the route tracker. _routeTracker = new RouteTracker(PassedRouteResult, 0); // Listen for updated guidance. _routeTracker.NewVoiceGuidance += RouteTracker_VoiceGuidanceChanged; // Disable rerouting _routeTracker.DisableRerouting(); Device.BeginInvokeOnMainThread(() => { // Prevent re-navigating. NavigateButton.IsEnabled = false; }); }
public void Dispose() { // Stop currently playing speech. _speechToken.Cancel(); // Stop the tracker. if (_tracker != null) { _tracker.TrackingStatusChanged -= TrackingStatusUpdated; _tracker.NewVoiceGuidance -= SpeakDirection; _tracker.RerouteStarted -= RerouteStarted; _tracker.RerouteCompleted -= RerouteCompleted; _tracker = null; } // Stop the location data source. MyMapView.LocationDisplay?.DataSource?.StopAsync(); }
private async void StartNavigation() { // Get the directions for the route. _directionsList = _route.DirectionManeuvers; // Create a route tracker. _tracker = new RouteTracker(_routeResult, 0); _tracker.NewVoiceGuidance += SpeakDirection; // Handle route tracking status changes. _tracker.TrackingStatusChanged += TrackingStatusUpdated; // Check if this route task supports rerouting. if (_routeTask.RouteTaskInfo.SupportsRerouting) { Device.BeginInvokeOnMainThread(() => { MessagesTextBlock.Text = "Reroute is enabled"; }); // Enable automatic re-routing. await _tracker.EnableReroutingAsync(_routeTask, _routeParams, ReroutingStrategy.ToNextWaypoint, false); // Handle re-routing completion to display updated route graphic and report new status. _tracker.RerouteStarted += RerouteStarted; _tracker.RerouteCompleted += RerouteCompleted; } // Turn on navigation mode for the map view. MyMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Navigation; MyMapView.LocationDisplay.AutoPanModeChanged += AutoPanModeChanged; // Add simulated data source for the location display. var simulationParameters = new SimulationParameters(DateTimeOffset.Now, 40.0); var simulatedDataSource = new SimulatedLocationDataSource(); simulatedDataSource.SetLocationsWithPolyline(_route.RouteGeometry, simulationParameters); MyMapView.LocationDisplay.DataSource = new RouteTrackerDisplayLocationDataSource(simulatedDataSource, _tracker); // Use this instead if you want real location: //MyMapView.LocationDisplay.DataSource = new RouteTrackerDisplayLocationDataSource(new SystemLocationDataSource(), _tracker); // Enable the location display (this will start the location data source). MyMapView.LocationDisplay.IsEnabled = true; }
private void SampleUnloaded(object sender, RoutedEventArgs e) { #if !NET_CORE_3 // Stop the speech synthesizer. _speechSynthesizer.SpeakAsyncCancelAll(); _speechSynthesizer.Dispose(); #endif // Stop the tracker. if (_tracker != null) { _tracker.TrackingStatusChanged -= TrackingStatusUpdated; _tracker.NewVoiceGuidance -= SpeakDirection; _tracker.RerouteStarted -= RerouteStarted; _tracker.RerouteCompleted -= RerouteCompleted; _tracker = null; } // Stop the location data source. MyMapView.LocationDisplay?.DataSource?.StopAsync(); }
private async void StartNavigation(object sender, EventArgs e) { // Disable the start navigation button. _navigateButton.Enabled = false; // Get the directions for the route. _directionsList = _route.DirectionManeuvers; // Create a route tracker. _tracker = new RouteTracker(_routeResult, 0, true); _tracker.NewVoiceGuidance += SpeakDirection; // Handle route tracking status changes. _tracker.TrackingStatusChanged += TrackingStatusUpdated; // Check if this route task supports rerouting. if (_routeTask.RouteTaskInfo.SupportsRerouting) { // Enable automatic re-routing. await _tracker.EnableReroutingAsync(new ReroutingParameters(_routeTask, _routeParams) { Strategy = ReroutingStrategy.ToNextWaypoint, VisitFirstStopOnStart = false }); // Handle re-routing completion to display updated route graphic and report new status. _tracker.RerouteStarted += RerouteStarted; _tracker.RerouteCompleted += RerouteCompleted; } // Turn on navigation mode for the map view. _myMapView.LocationDisplay.AutoPanMode = LocationDisplayAutoPanMode.Navigation; _myMapView.LocationDisplay.AutoPanModeChanged += AutoPanModeChanged; // Add a data source for the location display. _myMapView.LocationDisplay.DataSource = new RouteTrackerDisplayLocationDataSource(new GpxProvider(_gpxPath), _tracker); // Use this instead if you want real location: // _myMapView.LocationDisplay.DataSource = new RouteTrackerLocationDataSource(new SystemLocationDataSource(), _tracker); // Enable the location display (this will start the location data source). _myMapView.LocationDisplay.IsEnabled = true; }
public override void ViewDidDisappear(bool animated) { base.ViewDidDisappear(animated); // Stop the location data source. _myMapView.LocationDisplay?.DataSource?.StopAsync(); // Stop the speech synthesizer. _speechSynthesizer.StopSpeaking(AVSpeechBoundary.Word); _speechSynthesizer.Dispose(); // Stop the tracker. if (_tracker != null) { _tracker.TrackingStatusChanged -= TrackingStatusUpdated; _tracker.NewVoiceGuidance -= SpeakDirection; _tracker = null; } // Unsubscribe from events, per best practice. _navigateButton.Clicked -= StartNavigation; _recenterButton.Clicked -= Recenter; }
public void RoutePositionAfterRegressionTest1() { var delta = .00001; // a route of approx 30 m along the following coordinates: // 50.98624687752063, 2.902620979360633 // 50.98624687752063, 2.9027639004471673 (10m) // 50.986156907620895, 2.9027639004471673 (20m) // 50.9861564788317, 2.902620884621392 (30m) var route1 = new Route(); route1.Vehicle = Vehicle.Car.UniqueName; var route1entry1 = new RouteSegment(); route1entry1.Distance = -1; route1entry1.Latitude = 50.98624687752063f; route1entry1.Longitude = 2.902620979360633f; route1entry1.Metrics = null; route1entry1.Points = new RoutePoint[1]; route1entry1.Points[0] = new RoutePoint(); route1entry1.Points[0].Name = "TestPoint1"; route1entry1.Points[0].Tags = new RouteTags[1]; route1entry1.Points[0].Tags[0] = new RouteTags(); route1entry1.Points[0].Tags[0].Value = "TestValue1"; route1entry1.Points[0].Tags[0].Key = "TestKey1"; route1entry1.SideStreets = new RouteSegmentBranch[] { new RouteSegmentBranch() { Latitude = 51, Longitude = 3.999f, Tags = new RouteTags[] { new RouteTags() { Key = "name", Value = "Street B" }, new RouteTags() { Key = "highway", Value = "residential" } }, Name = "Street B" } }; route1entry1.Tags = new RouteTags[1]; route1entry1.Tags[0] = new RouteTags(); route1entry1.Tags[0].Key = "highway"; route1entry1.Tags[0].Value = "residential"; route1entry1.Time = 10; route1entry1.Type = RouteSegmentType.Start; route1entry1.Name = string.Empty; route1entry1.Names = null; RouteSegment route1entry2 = new RouteSegment(); route1entry2.Distance = -1; route1entry2.Latitude = 50.98624687752063f; route1entry2.Longitude = 2.9027639004471673f; route1entry2.Metrics = null; route1entry2.Points = new RoutePoint[1]; route1entry2.Points[0] = new RoutePoint(); route1entry2.Points[0].Name = "TestPoint2"; route1entry2.Points[0].Tags = new RouteTags[1]; route1entry2.Points[0].Tags[0] = new RouteTags(); route1entry2.Points[0].Tags[0].Value = "TestValue2"; route1entry1.Points[0].Tags[0].Key = "TestKey2"; route1entry2.SideStreets = new RouteSegmentBranch[] { new RouteSegmentBranch() { Latitude = 51, Longitude = 3.999f, Tags = new RouteTags[] { new RouteTags() { Key = "name", Value = "Street B" }, new RouteTags() { Key = "highway", Value = "residential" } }, Name = "Street B" } }; route1entry2.Tags = new RouteTags[1]; route1entry2.Tags[0] = new RouteTags(); route1entry2.Tags[0].Key = "highway"; route1entry2.Tags[0].Value = "residential"; route1entry2.Time = 10; route1entry2.Type = RouteSegmentType.Start; route1entry2.Name = string.Empty; route1entry2.Names = null; RouteSegment route1entry3 = new RouteSegment(); route1entry3.Distance = -1; route1entry3.Latitude = 50.986156907620895f; route1entry3.Longitude = 2.9027639004471673f; route1entry3.Metrics = null; route1entry3.Points = new RoutePoint[1]; route1entry3.Points[0] = new RoutePoint(); route1entry3.Points[0].Name = "TestPoint3"; route1entry3.Points[0].Tags = new RouteTags[1]; route1entry3.Points[0].Tags[0] = new RouteTags(); route1entry3.Points[0].Tags[0].Value = "TestValue3"; route1entry1.Points[0].Tags[0].Key = "TestKey3"; route1entry3.SideStreets = new RouteSegmentBranch[] { new RouteSegmentBranch() { Latitude = 51, Longitude = 3.999f, Tags = new RouteTags[] { new RouteTags() { Key = "name", Value = "Street B" }, new RouteTags() { Key = "highway", Value = "residential" } }, Name = "Street B" } }; route1entry3.Tags = new RouteTags[1]; route1entry3.Tags[0] = new RouteTags(); route1entry3.Tags[0].Key = "highway"; route1entry3.Tags[0].Value = "residential"; route1entry3.Time = 10; route1entry3.Type = RouteSegmentType.Start; route1entry3.Name = string.Empty; route1entry3.Names = null; RouteSegment route1entry4 = new RouteSegment(); route1entry4.Distance = -1; route1entry4.Latitude = 50.9861564788317f; route1entry4.Longitude = 2.902620884621392f; route1entry4.Metrics = null; route1entry4.Points = new RoutePoint[1]; route1entry4.Points[0] = new RoutePoint(); route1entry4.Points[0].Name = "TestPoint4"; route1entry4.Points[0].Tags = new RouteTags[1]; route1entry4.Points[0].Tags[0] = new RouteTags(); route1entry4.Points[0].Tags[0].Value = "TestValue4"; route1entry1.Points[0].Tags[0].Key = "TestKey4"; route1entry4.SideStreets = new RouteSegmentBranch[] { new RouteSegmentBranch() { Latitude = 51, Longitude = 3.999f, Tags = new RouteTags[] { new RouteTags() { Key = "name", Value = "Street B" }, new RouteTags() { Key = "highway", Value = "residential" } }, Name = "Street B" } }; route1entry4.Tags = new RouteTags[1]; route1entry4.Tags[0] = new RouteTags(); route1entry4.Tags[0].Key = "highway"; route1entry4.Tags[0].Value = "residential"; route1entry4.Time = 10; route1entry4.Type = RouteSegmentType.Start; route1entry4.Name = string.Empty; route1entry4.Names = null; route1.Segments = new RouteSegment[4]; route1.Segments[0] = route1entry1; route1.Segments[1] = route1entry2; route1.Segments[2] = route1entry3; route1.Segments[3] = route1entry4; // create the route tracker. var routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); var distance = 5.0; var location = route1.PositionAfter(distance); routeTracker.Track(location); Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta); Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta); Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta); Assert.AreEqual(new GeoCoordinate(route1.Segments[1].Latitude, route1.Segments[1].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta); var locationAfter = routeTracker.PositionAfter(10.0); distance = 15.0; location = route1.PositionAfter(distance); Assert.AreEqual(location.Latitude, locationAfter.Latitude, delta); Assert.AreEqual(location.Longitude, locationAfter.Longitude, delta); routeTracker.Track(location); Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta); Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta); Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta); Assert.AreEqual(new GeoCoordinate(route1.Segments[2].Latitude, route1.Segments[2].Longitude).DistanceReal(location).Value, routeTracker.DistanceNextInstruction.Value, delta); location = new GeoCoordinate(route1.Segments[3].Latitude, route1.Segments[3].Longitude); Meter distanceFromStart; route1.ProjectOn(location, out distanceFromStart); distance = distanceFromStart.Value; routeTracker.Track(location); Assert.AreEqual(distance, routeTracker.DistanceFromStart.Value, delta); Assert.AreEqual(location.Latitude, routeTracker.PositionRoute.Latitude, delta); Assert.AreEqual(location.Longitude, routeTracker.PositionRoute.Longitude, delta); Assert.AreEqual(0, routeTracker.DistanceNextInstruction.Value, delta); }
public override void LoadView() { OsmSharp.Logging.Log.Enable(); base.LoadView(); // initialize a test-map. var map = new Map(); map.AddLayer(new LayerScene(Scene2DLayered.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.map"), true))); // Perform any additional setup after loading the view, typically from a nib. MapView mapView = new MapView(); _mapView = mapView; //mapViewAnimator = new MapViewAnimator (mapView); mapView.Map = map; mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel // mapView.MapTapEvent+= delegate(GeoCoordinate geoCoordinate) { // mapView.AddMarker(geoCoordinate).TouchDown += MapMarkerClicked; // }; mapView.MapMaxZoomLevel = 18; mapView.MapMinZoomLevel = 12; mapView.MapZoom = 16; mapView.MapTilt = 30; var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.iOS.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(graphDeserialized), new OsmRoutingInterpreter()); // long before = DateTime.Now.Ticks; // // var routeLocations = new GeoCoordinate[] { // new GeoCoordinate (50.8247730, 2.7524706), // new GeoCoordinate (50.8496394, 2.7301512), // new GeoCoordinate (50.8927741, 2.6138545), // new GeoCoordinate (50.8296363, 2.8869437) // }; // // var routerPoints = new RouterPoint[routeLocations.Length]; // for (int idx = 0; idx < routeLocations.Length; idx++) { // routerPoints [idx] = router.Resolve (Vehicle.Car, routeLocations [idx]); // // mapView.AddMarker (routeLocations [idx]); // } // OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> tspRouter = new OsmSharp.Routing.TSP.RouterTSPWrapper<RouterTSPAEXGenetic> ( // new RouterTSPAEXGenetic (10, 20), router); // // Route route = tspRouter.CalculateTSP (Vehicle.Car, routerPoints); // // long after = DateTime.Now.Ticks; // // OsmSharp.Logging.Log.TraceEvent("OsmSharp.Android.UI.MapView", System.Diagnostics.TraceEventType.Information,"Routing & TSP in {0}ms", // new TimeSpan (after - before).TotalMilliseconds); // 51.160477" lon="2.961497 GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); //GeoCoordinate point1 = new GeoCoordinate(51.159132, 2.958755); //GeoCoordinate point2 = new GeoCoordinate(51.160477, 2.961497); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); _enumerator = route1.GetRouteEnumerable(10).GetEnumerator(); //List<Instruction> instructions = InstructionGenerator.Generate(route1, new OsmRoutingInterpreter()); // _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute(route1); map.AddLayer(_routeLayer); View = mapView; mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(point1); mapView.AddMarker(point2); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); // // //mapView.ZoomToMarkers(); //GeoCoordinateBox box = new GeoCoordinateBox (new GeoCoordinate[] { point1, point2 }); // mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) { //_routeTrackerAnimator.Track(box.GenerateRandomIn()); //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); //mapViewAnimator.Stop(); //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); }; RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _routeTrackerAnimator = new RouteTrackerAnimator(mapView, routeTracker, 5); // // Timer timer = new Timer (150); // timer.Elapsed += new ElapsedEventHandler (TimerHandler); // timer.Start (); // // Task.Factory.StartNew (() => { // System.Threading.Thread.Sleep(200); // do something. // InvokeOnMainThread (() => { // mapView.ZoomToMarkers (); // }); // }); // }
/// <summary> /// Raises the create event. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // enable the logggin. OsmSharp.Logging.Log.Enable(); OsmSharp.Logging.Log.RegisterListener(new OsmSharp.Android.UI.Log.LogTraceListener()); // 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")); // add an online osm-data->mapCSS translation layer. //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // add a pre-processed vector data file. var sceneStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.default.map"); map.AddLayer(new LayerScene(Scene2D.Deserialize(sceneStream, true))); // 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.Android.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(this, new MapViewSurface(this)); //_mapView = new MapView(this, new MapViewGLSurface(this)); //_mapView.MapTapEvent += new MapViewEvents.MapTapEventDelegate(_mapView_MapTapEvent); _mapView.Map = map; _mapView.MapMaxZoomLevel = 20; _mapView.MapMinZoomLevel = 10; _mapView.MapTilt = 0; _mapView.MapCenter = new GeoCoordinate(51.26371, 4.78601); _mapView.MapZoom = 18; // add markers. _mapView.AddMarker(from); _mapView.AddMarker(to); // initialize a text view to display routing instructions. _textView = new TextView(this); _textView.SetBackgroundColor(global::Android.Graphics.Color.White); _textView.SetTextColor(global::Android.Graphics.Color.Black); // add the mapview to the linear layout. var layout = new LinearLayout(this); layout.Orientation = Orientation.Vertical; layout.AddView(_textView); layout.AddView(_mapView); // create the route tracker animator. _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(); SetContentView(layout); }
/// <summary> /// Raises the create event. /// </summary> /// <param name="bundle">Bundle.</param> protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); OsmSharp.Logging.Log.Enable(); // OsmSharp.IO.Output.OutputStreamHost.RegisterOutputStream ( // new OsmSharp.Android.UI.IO.Output.ConsoleOutputStream ()); // create the MapCSS image source. var imageSource = new MapCSSDictionaryImageSource(); imageSource.Add("styles/default/parking.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.parking.png")); imageSource.Add("styles/default/bus.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.bus.png")); imageSource.Add("styles/default/postbox.png", Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.images.postbox.png")); // // load mapcss style interpreter. // var mapCSSInterpreter = new MapCSSInterpreter( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.mapcss"), // imageSource); // initialize the data source. //var dataSource = new MemoryDataSource(); // var source = new XmlOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm")); // var source = new PBFOsmStreamReader( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf")); // dataSource.PullFromSource(source); // initialize map. var map = new Map(); //map.AddLayer(new LayerTile(@"http://otile1.mqcdn.com/tiles/1.0.0/osm/{0}/{1}/{2}.png")); //map.AddLayer(new OsmLayer(dataSource, mapCSSInterpreter)); // map.AddLayer(new LayerScene(Scene2DSimple.Deserialize( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.osm.pbf.scene.simple"), true))); map.AddLayer( new LayerScene( Scene2DLayered.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream(@"OsmSharp.Android.UI.Sample.wvl.map"), true))); // var routingSerializer = new V2RoutingDataSourceLiveEdgeSerializer(true); // var graphSerialized = routingSerializer.Deserialize( // //Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.osm.pbf.routing.3")); // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.pbf.routing.4")); //// //// var graphLayer = new LayerDynamicGraphLiveEdge(graphSerialized, mapCSSInterpreter); //// map.AddLayer(graphLayer); // // // calculate route. // Router router = Router.CreateLiveFrom( // graphSerialized, // new OsmRoutingInterpreter()); var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(false); var graphDeserialized = routingSerializer.Deserialize( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.wvl.routing"), true); _router = Router.CreateCHFrom( graphDeserialized, new CHRouter(), new OsmRoutingInterpreter()); GeoCoordinate point1 = new GeoCoordinate(51.158075, 2.961545); GeoCoordinate point2 = new GeoCoordinate(51.190503, 3.004793); RouterPoint routerPoint1 = _router.Resolve(Vehicle.Car, point1); RouterPoint routerPoint2 = _router.Resolve(Vehicle.Car, point2); Route route1 = _router.Calculate(Vehicle.Car, routerPoint1, routerPoint2); RouteTracker routeTracker = new RouteTracker(route1, new OsmRoutingInterpreter()); _enumerator = route1.GetRouteEnumerable(20).GetEnumerator(); _routeLayer = new LayerRoute(map.Projection); _routeLayer.AddRoute(route1, SimpleColor.FromKnownColor(KnownColor.Blue).Value); map.AddLayer(_routeLayer); // // create gpx layer. // LayerGpx gpxLayer = new LayerGpx(map.Projection); // gpxLayer.AddGpx( // Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Android.UI.Sample.test.gpx")); // map.AddLayer(gpxLayer); // // set control properties. // var mapView = new MapView(this); // mapView.MapMaxZoomLevel = 20; // mapView.MapMinZoomLevel = 12; // //var mapView = new MapGLView (this); // mapView.Map = map; // //mapView.Center = new GeoCoordinate(51.158075, 2.961545); // gistel // //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); // mapView.MapCenter = new GeoCoordinate(51.26337, 4.78739); // //mapView.Center = new GeoCoordinate(51.156803, 2.958887); // mapView.MapZoomLevel = 15; // var mapView = new OpenGLRenderer2D( // this, null); // _mapView = new MapView<MapGLView>(this, new MapGLView(this)); _mapView = new MapView(this, new MapViewSurface(this)); //_mapView = new MapView(this, new MapViewGLSurface(this)); _mapView.Map = map; (_mapView as IMapView).AutoInvalidate = true; _mapView.MapMaxZoomLevel = 20; _mapView.MapMinZoomLevel = 12; _mapView.MapTilt = 0; //var mapView = new MapGLView (this); _mapView.MapCenter = new GeoCoordinate(51.158075, 2.961545); // gistel //mapView.MapCenter = new GeoCoordinate (50.88672, 3.23899); //mapLayout.MapCenter = new GeoCoordinate(51.26337, 4.78739); //mapView.Center = new GeoCoordinate(51.156803, 2.958887); _mapView.MapZoom = 17; //MapViewAnimator mapViewAnimator = new MapViewAnimator(mapLayout); //_mapView.MapTapEvent += delegate(GeoCoordinate geoCoordinate) //{ // _mapView.ZoomToMarkers(); // //_mapView.AddMarker(geoCoordinate).Click += new EventHandler(MainActivity_Click); // //mapViewAnimator.Stop(); // //mapViewAnimator.Start(geoCoordinate, 15, new TimeSpan(0, 0, 2)); //}; //Create the user interface in code var layout = new RelativeLayout(this); layout.AddView(_mapView); _mapView.AddMarker(new GeoCoordinate(51.1612, 2.9795)); _mapView.AddMarker(new GeoCoordinate(51.1447, 2.9483)); //_mapView.ZoomToMarkers(); _routeTrackerAnimator = new RouteTrackerAnimator(_mapView, routeTracker, 5); Timer timer = new Timer(250); timer.Elapsed += new ElapsedEventHandler(TimerHandler); timer.Start(); SetContentView(layout); }
/// <summary>Establishes the target route.</summary> /// <remarks>Establishes the target route.</remarks> /// <exception cref="Apache.Http.HttpException"></exception> /// <exception cref="System.IO.IOException"></exception> internal virtual void EstablishRoute(AuthState proxyAuthState, HttpClientConnection managedConn, HttpRoute route, IHttpRequest request, HttpClientContext context) { RequestConfig config = context.GetRequestConfig(); int timeout = config.GetConnectTimeout(); RouteTracker tracker = new RouteTracker(route); int step; do { HttpRoute fact = tracker.ToRoute(); step = this.routeDirector.NextStep(route, fact); switch (step) { case HttpRouteDirector.ConnectTarget: { this.connManager.Connect(managedConn, route, timeout > 0 ? timeout : 0, context); tracker.ConnectTarget(route.IsSecure()); break; } case HttpRouteDirector.ConnectProxy: { this.connManager.Connect(managedConn, route, timeout > 0 ? timeout : 0, context); HttpHost proxy = route.GetProxyHost(); tracker.ConnectProxy(proxy, false); break; } case HttpRouteDirector.TunnelTarget: { bool secure = CreateTunnelToTarget(proxyAuthState, managedConn, route, request, context ); this.log.Debug("Tunnel to target created."); tracker.TunnelTarget(secure); break; } case HttpRouteDirector.TunnelProxy: { // The most simple example for this case is a proxy chain // of two proxies, where P1 must be tunnelled to P2. // route: Source -> P1 -> P2 -> Target (3 hops) // fact: Source -> P1 -> Target (2 hops) int hop = fact.GetHopCount() - 1; // the hop to establish bool secure = CreateTunnelToProxy(route, hop, context); this.log.Debug("Tunnel to proxy created."); tracker.TunnelProxy(route.GetHopTarget(hop), secure); break; } case HttpRouteDirector.LayerProtocol: { this.connManager.Upgrade(managedConn, route, context); tracker.LayerProtocol(route.IsSecure()); break; } case HttpRouteDirector.Unreachable: { throw new HttpException("Unable to establish route: " + "planned = " + route + "; current = " + fact); } case HttpRouteDirector.Complete: { this.connManager.RouteComplete(managedConn, route, context); break; } default: { throw new InvalidOperationException("Unknown step indicator " + step + " from RouteDirector." ); } } }while (step > HttpRouteDirector.Complete); }