/// <summary> /// Starts tracking at a given location. /// </summary> /// <param name="location"></param> public void Track(GeoCoordinate location) { if (_lastTouch.HasValue) { // is tracking disabled now? TimeSpan timeFromLastTouch = new TimeSpan (DateTime.Now.Ticks - _lastTouch.Value); if (timeFromLastTouch.TotalSeconds >= this.RestartAfterTouch.Value) { // ok, the animator has waited long enough. _lastTouch = null; } else { // ok, the animator still has to wait for user-input. return; } } // check if the minimum gap between tracking events is respected. long now = DateTime.Now.Ticks; if (_lastTrack.HasValue) { if (_minimumTrackGap > now - _lastTrack.Value) { return; // too fast! } } _lastTrack = now; // animate the next step(s). TimeSpan lastTrackInterval = new TimeSpan(0, 0, 0, 0, 750); long ticks = DateTime.Now.Ticks; if (_lastTicks.HasValue) { // update the last track interval. lastTrackInterval = TimeSpan.FromTicks(ticks - _lastTicks.Value); } _lastTicks = ticks; OsmSharp.Logging.Log.TraceEvent("", System.Diagnostics.TraceEventType.Information, "Interval: {0}ms", lastTrackInterval.TotalMilliseconds); // give location to the route tracker. _routeTracker.Track(location); // calculate all map view parameters (zoom, location, tilt) to display the route/direction correctly. float zoom = this.DefaultZoom; GeoCoordinate center = _routeTracker.PositionRoute; double nextDistance = 20; Degree tilt = _mapView.MapTilt; GeoCoordinate next = _routeTracker.PositionIn(nextDistance); if (next != null) { IProjection projection = _mapView.Map.Projection; VectorF2D direction = new PointF2D(projection.ToPixel(next)) - new PointF2D(projection.ToPixel(center)); tilt = direction.Angle(new VectorF2D(0, -1)); } // animate to the given parameter (zoom, location, tilt). _animator.Stop(); _animator.Start(center, zoom, tilt, lastTrackInterval.Subtract(new TimeSpan(0, 0, 0, 0, 150))); }