private void UpdatePolyLine() { //var nativeMap = Control as MKMapView; if (polyline != null) { nativeMap.RemoveOverlay(polyline); polyline.Dispose(); } nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; int index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); polyline = routeOverlay; }
/// <summary> /// Posts the load subscriptions. /// </summary> /// <returns>The load subscriptions.</returns> public override IEnumerable <IDisposable> LoadSubscriptions() { yield return(ViewModel.WhenAnyValue(vm => vm.Feedbacks).BindTo <FeedbackListItemViewModel, FeedbackListItemTableViewCell>(_feedbackTableView, 80, cell => cell.Initialize())); yield return(ViewModel.WhenAnyValue(vm => vm.Infos) .Select((IReactiveList <TetrixViewModelBase> list) => { return list.GroupBy(model => (float)model.Height) .Select(typeGroup => { var collection = new ReactiveList <TetrixViewModelBase>(); collection.AddRange(typeGroup); return new TableSectionInformation <TetrixViewModelBase, BaseTableViewCell>(collection, (model) => { var cellIndentifier = ""; TypeSwitch.On(model) .Case((HeaderListItemViewModel m) => cellIndentifier = HeaderTableViewCell.Key) .Case((ContactListItemViewModel m) => cellIndentifier = ContactTableViewCell.Key); return new NSString(cellIndentifier); }, typeGroup.Key, cell => cell.Initialize()); }).ToList(); }).BindTo(_infoTableView)); yield return(this.WhenAnyValue(v => v._tableSource.ElementSelected) .Subscribe(x => { // when ever this value is updated we want to make sure we only ever have // the latest subscription _serialDisposable.Disposable = x.Subscribe(vm => ViewModel.SelectFeedbackAsync()); })); yield return(this.WhenAnyValue(v => v._infoTableSource.ElementSelected) .Subscribe(x => { // when ever this value is updated we want to make sure we only ever have // the latest subscription _serialDisposable.Disposable = x.Subscribe(vm => ViewModel.SelectContactAsync()); })); yield return(Observable.FromEventPattern <PathUpdateEventArgs>(ViewModel, "PathUpdate") .Window(() => Observable.Interval(TimeSpan.FromSeconds(2))) .SelectMany(x => x.Take(1)) .SubscribeOn(ViewModel.Scheduler) .Subscribe(e => { var pathArgs = e.EventArgs; var latDif = pathArgs.StartCoordinate.Latitude - pathArgs.EndCoordinate.Latitude; var lonDif = pathArgs.StartCoordinate.Longitude - pathArgs.EndCoordinate.Longitude; var midLat = latDif / 2 + pathArgs.EndCoordinate.Latitude; var midLon = lonDif / 2 + pathArgs.EndCoordinate.Longitude; double dist = Math.Sqrt(latDif * latDif + lonDif * lonDif) * 90; var polyline = new List <CLLocationCoordinate2D>(); foreach (var pathPoint in pathArgs.Path) { polyline.Add(new CLLocationCoordinate2D(pathPoint.Latitude, pathPoint.Longitude)); } // Must update the UI on the main thread // set map center var mapCenter = new CLLocationCoordinate2D(midLat, midLon); var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, dist * 2000, dist * 2000); // if _mkPolyLine not null, remove then recreate and re add if (_mkPolyLine != null) { _mapView.RemoveOverlay(_mkPolyLine); _mkPolyLine?.Dispose(); } _mkPolyLine = MKPolyline.FromCoordinates(polyline.ToArray()); _mapView.CenterCoordinate = mapCenter; _mapView.Region = mapRegion; // add map overlay for path _mapView.AddOverlay(_mkPolyLine); })); yield return(ViewModel.WhenAnyValue(vm => vm.LocationLoading) .SubscribeOn(ViewModel.Scheduler) .Subscribe(loading => { if (loading) { _progressView.StartAnimating(); } else { _progressView.StopAnimating(); } })); }