示例#1
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            if (resultCode == PoiSelectActivity.RESULT_OK)
            {
                var id = data.GetLongExtra("Id", 0);

                var selectedPoint = (id == (long)PoiId.CURRENT_LOCATION)
                    ? PoiSelectActivity.GetMyLocationPoi(AppContext)
                    : AppContext.Database.GetItem(id);

                if (requestCode == PoiSelectActivity.REQUEST_SELECT_CAMERADIRECTION)
                {
                    if (!TryGetGpsLocation(out GpsLocation location, false))
                    {
                        PopupHelper.ErrorDialog(this, Resource.String.PhotoParameters_SetCameraLocationFirst);
                    }
                    var bearing = GpsUtils.QuickBearing(location, new GpsLocation(selectedPoint.Longitude, selectedPoint.Latitude, selectedPoint.Altitude));
                    UpdateHeading(bearing);
                }
                else if (requestCode == PoiSelectActivity.REQUEST_SELECT_CAMERALOCATION)
                {
                    var location = new GpsLocation(selectedPoint.Longitude, selectedPoint.Latitude, selectedPoint.Altitude);
                    UpdateCameraLocation(location);
                    UpdateCameraAltitude(location);
                }
            }
        }
示例#2
0
        public static Visibility IsPoiVisible(PoiViewItem item, ElevationProfileData elevationProfileData)
        {
            if (elevationProfileData == null)
            {
                return(Visibility.Visible);
            }

            var leftPoints  = elevationProfileData.GetData((int)item.GpsLocation.Bearing);
            var rightPoints = elevationProfileData.GetData((int)GpsUtils.Normalize360(item.GpsLocation.Bearing.Value + 1));

            if (leftPoints == null || rightPoints == null)
            {
                return(Visibility.Visible);
            }

            var maxLeft = new GpsLocation()
            {
                VerticalViewAngle = -100, Distance = 100
            };
            var leftPoints2 = leftPoints.GetPoints().Where(p => p.Distance < item.GpsLocation.Distance);

            if (leftPoints2.Any())
            {
                maxLeft = leftPoints2.Aggregate((max, item2) => item2?.VerticalViewAngle > max?.VerticalViewAngle ? item2 : max);
            }

            var maxRight = new GpsLocation()
            {
                VerticalViewAngle = -100, Distance = 100
            };
            var rightPoints2 = rightPoints.GetPoints().Where(p => p.Distance < item.GpsLocation.Distance);

            if (rightPoints2.Any())
            {
                maxRight = rightPoints2.Aggregate((max, item2) => item2?.VerticalViewAngle > max?.VerticalViewAngle ? item2 : max);
            }

            var maxViewAngle = maxRight.VerticalViewAngle > maxLeft.VerticalViewAngle ? maxRight : maxLeft;

            var itemViewAngle     = item.VerticalViewAngle;
            var viewAngleDiff     = item.VerticalViewAngle - maxViewAngle.VerticalViewAngle;
            var viewAngleDistance = item.GpsLocation.Distance - maxViewAngle.Distance;

            var viewAngleVisibilityLimit     = -(itemViewAngle * 0.01 + 0.0);
            var viewAnglePartVisibilityLimit = -(itemViewAngle * 0.2 + 1.0);
            var distancePartVisibilityLimit  = 2000;//m

            if (viewAngleDiff > viewAngleVisibilityLimit)
            {
                return(Visibility.Visible);
            }

            if (viewAngleDiff > viewAnglePartVisibilityLimit && viewAngleDistance < distancePartVisibilityLimit)
            {
                return(Visibility.PartialyVisible);
            }

            return(Visibility.Invisible);
        }
示例#3
0
        private void OnSaveClicked()
        {
            try
            {
                _photoData.Tag = _editTextTag.Text;

                if (!TryGetGpsLocation(out GpsLocation location))
                {
                    return;
                }
                _photoData.Latitude  = location.Latitude;
                _photoData.Longitude = location.Longitude;
                _photoData.Altitude  = location.Altitude;


                if (!string.IsNullOrEmpty(_editTextHeading.Text))
                {
                    double heading = 0;
                    if (!double.TryParse(_editTextHeading.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out heading))
                    {
                        PopupHelper.ErrorDialog(this, Resource.String.EditPoi_WrongFormat);
                        return;
                    }
                    _photoData.Heading = GpsUtils.Normalize180(heading);
                }
                else
                {
                    _photoData.Heading = null;
                }


                if (!double.TryParse(_editTextViewAngleHorizontal.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var viewAngleHorizontal))
                {
                    PopupHelper.ErrorDialog(this, Resource.String.EditPoi_WrongFormat);
                    return;
                }
                _photoData.ViewAngleHorizontal = viewAngleHorizontal;

                if (!double.TryParse(_editTextViewAngleVertical.Text, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var viewAngleVertical))
                {
                    PopupHelper.ErrorDialog(this, Resource.String.EditPoi_WrongFormat);
                    return;
                }
                _photoData.ViewAngleVertical = viewAngleVertical;

                _photoData.JsonElevationProfileData = null;
                //_photoData.ShowElevationProfile = true;

                Context.PhotosModel.UpdateItem(_photoData);

                Finish();
            }
            catch (Exception ex)
            {
                PopupHelper.ErrorDialog(this, "Unable to save image. Error details: " + ex.Message);
            }
        }
示例#4
0
 private void UpdateCameraAltitude(GpsLocation location)
 {
     if (GpsUtils.HasAltitude(location))
     {
         _editTextAltitude.Text = $"{location.Altitude:F0}";
     }
     else
     {
         _editTextAltitude.Text = "";
     }
 }
示例#5
0
 private void UpdateHeading(double?heading)
 {
     if (heading.HasValue)
     {
         _editTextHeading.Text = $"{GpsUtils.Normalize360(heading.Value):F1}".Replace(",", ".");
     }
     else
     {
         _editTextHeading.Text = "";
     }
 }
示例#6
0
        private void OnSelectionUpdated(Poi poi)
        {
            FindViewById <TextView>(Resource.Id.textViewPlaceName).Text    = poi.Name;
            FindViewById <TextView>(Resource.Id.textViewPlaceCountry).Text = PoiCountryHelper.GetCountryName(poi.Country);
            FindViewById <TextView>(Resource.Id.textViewAltitude).Text     = $"{poi.Altitude:F0} m";
            FindViewById <TextView>(Resource.Id.textViewGpsLocation).Text  = GpsUtils.LocationAsString(poi.Latitude, poi.Longitude);

            var thumbnail = FindViewById <ImageView>(Resource.Id.Thumbnail);

            thumbnail.SetImageResource(PoiCategoryHelper.GetImage(poi.Category));

            CalculateDownloadSize(poi);
        }
示例#7
0
 private void UpdateCameraLocation(GpsLocation location)
 {
     if (GpsUtils.HasLocation(location))
     {
         _editTextLongitude.Text = $"{location.Longitude:F7}".Replace(",", ".");
         _editTextLatitude.Text  = $"{location.Latitude:F7}".Replace(",", ".");
     }
     else
     {
         _editTextLongitude.Text = "";
         _editTextLatitude.Text  = "";
     }
 }
        public ElevationTileCollection(GpsLocation myLocation, int visibility)
        {
            _myLocation = myLocation;
            _visibility = visibility;
            GpsUtils.BoundingRect(_myLocation, _visibility, out _boundingRectMin, out _boundingRectMax);

            for (var lat = Math.Floor(_boundingRectMin.Latitude); lat < Math.Floor(_boundingRectMax.Latitude) + 1; lat++)
            {
                for (var lon = Math.Floor(_boundingRectMin.Longitude); lon < Math.Floor(_boundingRectMax.Longitude) + 1; lon++)
                {
                    _elevationTiles.Add(new ElevationTile(new GpsLocation(lon, lat, 0)));
                }
            }
        }
示例#9
0
        public void OnPhotoShowRequest(int position)
        {
            var photoData = _adapter[position];

            if (!GpsUtils.HasLocation(photoData.GetPhotoGpsLocation()) || !GpsUtils.HasAltitude(photoData.GetPhotoGpsLocation()))
            {
                PopupHelper.ErrorDialog(this, Resource.String.PhotoParameters_SetCameraLocationFirst);
                return;
            }
            Intent showIntent = new Intent(this, typeof(PhotoShowActivity));

            showIntent.PutExtra("ID", _adapter[position].Id);
            StartActivity(showIntent);
        }
示例#10
0
        private void OnCameraLocationClicked()
        {
            GpsLocation location = _photoData.GetPhotoGpsLocation();

            if (!GpsUtils.HasLocation(location))
            {
                location = AppContext.MyLocation;
            }

            Intent intent = new Intent(this, typeof(PoiSelectActivity));

            intent.SetAction(PoiSelectActivity.REQUEST_SELECT_CAMERALOCATION.ToString());
            intent.PutExtra("Longitude", location.Longitude);
            intent.PutExtra("Latitude", location.Latitude);
            intent.PutExtra("SortBy", PoiSelectActivity.SortBy.Name.ToString());
            StartActivityForResult(intent, PoiSelectActivity.REQUEST_SELECT_CAMERALOCATION);
        }
示例#11
0
        private ElevationData GetElevationDataForAngle(ushort angle, GpsLocation myLocation, double maxDistance, ElevationTileCollection etc)
        {
            var ed = new ElevationData(angle);

            for (double d = 500; d < maxDistance; d += Math.Min(100, d / 100))
            {
                var x = GpsUtils.QuickGetGeoLocation(myLocation, d, angle);
                //int size = d < 5000 ? 1 : 3;
                int size = Math.Min(((int)d / 20000) + 1, 4);//0-20:1 20-40:2 40-60:3 60-100:4
                if (etc.TryGetElevation(x, out var elevation, size))
                {
                    x.Altitude = elevation;
                    x.Distance = d;
                    x.Bearing  = angle;
                    x.GetVerticalViewAngle(myLocation);

                    ed.Add(x);
                }
            }

            return(ed);
        }
示例#12
0
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            if (resultCode == Result.Ok && requestCode == REQUEST_IMPORT_PHOTO)
            {
                var uri = data.Data;

                var path = PathUtil.GetPath(this, uri);
                if (path == null)
                {
                    PopupHelper.ErrorDialog(this, Resources.GetText(Resource.String.PhotoParameters_CantLoadImage));
                    return;
                }

                var exifData = ExifDataReader.ReadExifData(path);

                //update altitude
                if (GpsUtils.HasLocation(exifData.location))
                {
                    if (!GpsUtils.HasAltitude(exifData.location))
                    {
                        if (TryGetElevation(exifData.location, out var altitude))
                        {
                            exifData.location.Altitude = altitude;
                        }
                    }
                }

                Task.Run(async() =>
                {
                    var photoData = await ImageSaver.Import(path, exifData, Context);

                    Intent importActivityIntent = new Intent(this, typeof(PhotoParametersActivity));
                    importActivityIntent.PutExtra("Id", photoData.Id);
                    StartActivity(importActivityIntent);
                });
            }
        }