Ejemplo n.º 1
0
        void UpdateMap(TripPoint point, bool updateCamera = true)
        {
            if (map == null)
                return;
            //Get trail position or current potion to move car
            var latlng = point == null
                ? viewModel?.CurrentPosition?.ToLatLng()
                : point.ToLatLng();
            Activity?.RunOnUiThread(() =>
            {
                UpdateCar(latlng);
                driveLine?.Remove();
                var polyOptions = new PolylineOptions();

                if (allPoints == null)
                {
                    allPoints = viewModel.CurrentTrip.Points.ToLatLngs();
                }
                else if (point != null)
                {
                    allPoints.Add(point.ToLatLng());
                }

                polyOptions.Add(allPoints.ToArray());

                if (!driveLineColor.HasValue)
                    driveLineColor = new Color(ContextCompat.GetColor(Activity, Resource.Color.recording_accent));

                polyOptions.InvokeColor(driveLineColor.Value);
                driveLine = map.AddPolyline(polyOptions);
                if (updateCamera)
                    UpdateCamera(latlng);
            });
        }
        void SetupMap()
        {
            if (map == null)
            {
                return;
            }

            if (mapView.Width == 0)
            {
                mapView.PostDelayed(SetupMap, 500);
                return;
            }

            if (viewModel.CurrentTrip.HasSimulatedOBDData)
            {
                var activity = (BaseActivity)Activity;
                activity.SupportActionBar.Title = "Current Trip (Sim OBD)";
            }


            TripPoint start = null;

            if (viewModel.CurrentTrip.Points.Count != 0)
            {
                start = viewModel.CurrentTrip.Points[0];
            }

            UpdateMap(start, false);

            if (start != null)
            {
                UpdateCamera(carMarker.Position);
                AddStartMarker(start.ToLatLng());
            }
        }