Exemplo n.º 1
0
        public void UpdateHexagonsInView()
        {
            /*
             * if (Current.Instance.MapControl.Viewport.Resolution > 50)
             * {
             *  ClearGraphics();
             *  return;
             * }
             * */

            if (!Enabled)
            {
                return;
            }

            var topLeft     = Current.Instance.MapControl.Viewport.Extent.TopLeft;
            var bottomLeft  = Current.Instance.MapControl.Viewport.Extent.BottomLeft;
            var bottomRight = Current.Instance.MapControl.Viewport.Extent.BottomRight;
            var topRight    = Current.Instance.MapControl.Viewport.Extent.TopRight;

            var llTopLeft     = SphericalMercator.ToLonLat(topLeft.X, topLeft.Y);
            var llbottomLeft  = SphericalMercator.ToLonLat(bottomLeft.X, bottomLeft.Y);
            var llbottonRight = SphericalMercator.ToLonLat(bottomRight.X, bottomRight.Y);
            var llTopRight    = SphericalMercator.ToLonLat(topRight.X, topRight.Y);

            var wkt = String.Format(CultureInfo.InvariantCulture, "POLYGON(({0} {1},{2} {3},{4} {5},{6} {7},{0} {1}))", llTopLeft.x, llTopLeft.y, llbottomLeft.x, llbottomLeft.y, llbottonRight.x, llbottonRight.y, llTopRight.x, llTopRight.y);

            //Esto se ejecuta al principio o cuando haces una actualizacion
            landRequest.GetLandByWkt(wkt, Current.Instance.Earthwatcher.Lands.First().Id);
        }
Exemplo n.º 2
0
        public void UpdateHexagonsFromMemory()
        {
            if (Current.Instance.Lands == null)
            {
                return;
            }


            if (!Enabled)
            {
                return;
            }

            var topLeft     = Current.Instance.MapControl.Viewport.Extent.TopLeft;
            var bottomLeft  = Current.Instance.MapControl.Viewport.Extent.BottomLeft;
            var bottomRight = Current.Instance.MapControl.Viewport.Extent.BottomRight;
            var topRight    = Current.Instance.MapControl.Viewport.Extent.TopRight;

            var llTopLeft     = SphericalMercator.ToLonLat(topLeft.X, topLeft.Y);
            var llbottomLeft  = SphericalMercator.ToLonLat(bottomLeft.X, bottomLeft.Y);
            var llbottonRight = SphericalMercator.ToLonLat(bottomRight.X, bottomRight.Y);
            var llTopRight    = SphericalMercator.ToLonLat(topRight.X, topRight.Y);

            var landPieces = Current.Instance.Lands.Where(x => x.Latitude >= llbottomLeft.y && x.Latitude <= llTopLeft.y && x.Longitude >= llTopLeft.x && x.Longitude <= llTopRight.x);

            UpdateLands(landPieces.ToList());
        }
Exemplo n.º 3
0
        public void UpdateHexagonsInView()
        {
            if (Current.Instance.MapControl.Viewport.Resolution > 50)
            {
                ClearGraphics();
                return;
            }

            if (!Enabled)
            {
                return;
            }

            var topLeft     = Current.Instance.MapControl.Viewport.Extent.TopLeft;
            var bottomLeft  = Current.Instance.MapControl.Viewport.Extent.BottomLeft;
            var bottomRight = Current.Instance.MapControl.Viewport.Extent.BottomRight;
            var topRight    = Current.Instance.MapControl.Viewport.Extent.TopRight;

            var llTopLeft     = SphericalMercator.ToLonLat(topLeft.X, topLeft.Y);
            var llbottomLeft  = SphericalMercator.ToLonLat(bottomLeft.X, bottomLeft.Y);
            var llbottonRight = SphericalMercator.ToLonLat(bottomRight.X, bottomRight.Y);
            var llTopRight    = SphericalMercator.ToLonLat(topRight.X, topRight.Y);

            var wkt = String.Format(CultureInfo.InvariantCulture, "POLYGON(({0} {1},{2} {3},{4} {5},{6} {7},{0} {1}))", llTopLeft.x, llTopLeft.y, llbottomLeft.x, llbottomLeft.y, llbottonRight.x, llbottonRight.y, llTopRight.x, llTopRight.y);

            landRequest.GetLandByWkt(wkt);
        }
Exemplo n.º 4
0
        public LayerChooser()
        {
            InitializeComponent();

            if (Current.Instance.TutorialStarted || Current.Instance.Tutorial2Started)
            {
                TutorialText.Visibility = System.Windows.Visibility.Visible;
                if (Current.Instance.Tutorial2Started)
                {
                    TutorialTextBlock.Text = "Nuevamente, estas son las imágenes satelitales disponibles. \r\n\r\nElegí la más reciente, la cual se va a agregar como una capa por encima del mapa";
                }
            }

            imageRequest.ImageRequestReceived += ImageRequestImageRequestReceived;

            var topLeft     = Current.Instance.MapControl.Viewport.Extent.TopLeft;
            var bottomLeft  = Current.Instance.MapControl.Viewport.Extent.BottomLeft;
            var bottomRight = Current.Instance.MapControl.Viewport.Extent.BottomRight;
            var topRight    = Current.Instance.MapControl.Viewport.Extent.TopRight;

            var llTopLeft     = SphericalMercator.ToLonLat(topLeft.X, topLeft.Y);
            var llbottomLeft  = SphericalMercator.ToLonLat(bottomLeft.X, bottomLeft.Y);
            var llbottonRight = SphericalMercator.ToLonLat(bottomRight.X, bottomRight.Y);
            var llTopRight    = SphericalMercator.ToLonLat(topRight.X, topRight.Y);

            var wkt = String.Format(CultureInfo.InvariantCulture, "POLYGON(({0} {1},{2} {3},{4} {5},{6} {7},{0} {1}))", llTopLeft.x, llTopLeft.y, llbottomLeft.x, llbottomLeft.y, llbottonRight.x, llbottonRight.y, llTopRight.x, llTopRight.y);

            imageRequest.GetByExtent(wkt);
        }
Exemplo n.º 5
0
        public ActionResult Index(int width, int height, string bbox, string layers)
        {
            var bounds            = CreateBBox(bbox);
            var boundsLL          = SphericalMercator.ToLonLat(bounds);
            var boundsGeographyLL = boundsLL.ToSqlGeography();
            var states            = new GeometryDataSource().Query(boundsGeographyLL, "states");;

            var memoryStream = new MemoryStream();

            using (var bitmap = new Bitmap(width, height))
                using (var g = Graphics.FromImage(bitmap))
                    using (var pen = new Pen(Color.Blue, 2.0f))
                    {
                        g.CompositingMode    = CompositingMode.SourceOver;
                        g.CompositingQuality = CompositingQuality.HighQuality;
                        foreach (var state in states)
                        {
                            var geography = (SqlGeography)state["geom"];
                            {
                                using (var gp = CreateGraphicsPath(bounds, bitmap, geography))
                                {
                                    g.DrawPath(pen, gp);
                                }
                            }
                        }
                        bitmap.Save(memoryStream, ImageFormat.Png);
                    }
            return(File(memoryStream.ToArray(), "image/png"));
        }
Exemplo n.º 6
0
        private void BtnOkMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (Current.Instance.Username == null || Current.Instance.Password == null || Current.Instance.Earthwatcher == null)
            {
                var ws = new WarningScreen(Labels.Flag1);
                ws.Show();

                _ignoreClick = true;
                Reset();
                return;
            }

            var comment = txtComment.Text;
            var eId     = Current.Instance.Earthwatcher.Id;

            //Get lat lon for flag
            var generalTransform         = imgFlagShadow.TransformToVisual(Current.Instance.MapControl);
            var childToParentCoordinates = generalTransform.Transform(new Point(15, imgFlagShadow.ActualHeight));
            var spherical = Current.Instance.MapControl.Viewport.ScreenToWorld(childToParentCoordinates.X, childToParentCoordinates.Y);
            var lonLat    = SphericalMercator.ToLonLat(spherical.X, spherical.Y);

            //Post
            var flagPost = new FlagRequests(Constants.BaseApiUrl);

            flagPost.FlagAdded += OnFlagAdded;
            var flag = new Earthwatchers.Models.Flag {
                Comment = comment, EarthwatcherId = eId, Latitude = lonLat.y, Longitude = lonLat.x
            };

            flagPost.Post(flag, Current.Instance.Username, Current.Instance.Password);

            _ignoreClick = true;
            Reset();
        }
Exemplo n.º 7
0
        public static Point OffsetMeters(this Point point, double dx, double dy)
        {
            const double EarthRadius = 6_371_000;
            Point        lonLat      = SphericalMercator.ToLonLat(point.X, point.Y);
            var          newLon      = lonLat.X + (dx / EarthRadius) * (180 / Math.PI) / Math.Cos(lonLat.Y * Math.PI / 180);
            var          newLat      = lonLat.Y + (dy / EarthRadius) * (180 / Math.PI);

            return(SphericalMercator.FromLonLat(newLon, newLat));
        }
        private static float CalcStepMeters(float step, Point origin)
        {
            const double earthRadius = 6371000; //meters
            const double deg2rad     = Math.PI / 180;

            Point  offseted = origin + new Point(step, 0);
            double lat      = deg2rad * SphericalMercator.ToLonLat(origin.X, origin.Y).X;
            double lon1     = deg2rad * SphericalMercator.ToLonLat(origin.X, origin.Y).X;
            double lon2     = deg2rad * SphericalMercator.ToLonLat(offseted.X, offseted.Y).X;
            double deltaLon = lon2 - lon1;

            return((float)(2 * earthRadius * Math.Asin(Math.Abs(Math.Sin(deltaLon / 2) * Math.Cos(lat / 2)))));
        }
Exemplo n.º 9
0
        private void MapControlMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (!isScoreAdding) //esto evita que abran el hexagono nuevamente mientras se está guardando un puntaje
            {
                if ((Current.Instance.TutorialStarted && tutorialCompletePhase1) || (Current.Instance.Tutorial2Started && tutorialCompletePhase2) || (!Current.Instance.TutorialStarted && !Current.Instance.Tutorial2Started))
                {
                    leftMouseButtonDown = true;

                    if (!layerHelper.FindLayer(Constants.Hexagonlayername).Enabled)
                    {
                        return;
                    }

                    var mousePos            = e.GetPosition(mapControl);
                    var sphericalCoordinate = mapControl.Viewport.ScreenToWorld(mousePos.X, mousePos.Y); //TODO: posicionar bien el tooltip
                    var lonLat = SphericalMercator.ToLonLat(sphericalCoordinate.X, sphericalCoordinate.Y);

                    var feature = hexagonInfo.GetFeature(lonLat.x, lonLat.y, 7);
                    var hexCode = GeoHex.Encode(lonLat.x, lonLat.y, 7);

                    if (feature == null)
                    {
                        // try on level 6...
                        hexCode = GeoHex.Encode(lonLat.x, lonLat.y, 6);
                    }

                    bool showHex = true;
                    if ((Current.Instance.TutorialStarted || Current.Instance.Tutorial2Started) && !selectedLand.GeohexKey.Equals(hexCode))
                    {
                        showHex = false;
                    }

                    if (showHex)
                    {
                        if (Current.Instance.TutorialStarted)
                        {
                            this.Tutorial5.Visibility      = System.Windows.Visibility.Collapsed;
                            this.Tutorial5Arrow.Visibility = System.Windows.Visibility.Collapsed;
                        }

                        if (Current.Instance.Tutorial2Started)
                        {
                            this.Tutorial23.Visibility     = System.Windows.Visibility.Collapsed;
                            this.Tutorial5Arrow.Visibility = System.Windows.Visibility.Collapsed;
                        }

                        hexagonInfo.ShowInfo(lonLat.x, lonLat.y);
                    }
                }
            }
        }
Exemplo n.º 10
0
        public void SphericalMercatorPrecisionTest()
        {
            // Arrange
            var inLon = 101.71046179910427;
            var inLat = 3.1567427968766819;

            // Act
            var(x, y)           = SphericalMercator.FromLonLat(inLon, inLat);
            var(outLon, outLat) = SphericalMercator.ToLonLat(x, y);

            // Assert
            var distanceInKilometer = Haversine.Distance(inLon, inLat, outLon, outLat);
            var distanceInCentimer  = distanceInKilometer * 100000;

            Assert.Less(distanceInCentimer, 1);
        }
Exemplo n.º 11
0
        public override void MapControlOnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            var mapInfo  = e.GetMapInfo(_mapControl);
            var position = SphericalMercator.ToLonLat(mapInfo.WorldPosition.X, mapInfo.WorldPosition.Y);

            var contextMenu = new ContextMenu();

            if (mapInfo.Feature is IHasContextMenuOptions feature)
            {
                feature.OnContextOpen(contextMenu, RouteController);
            }
            else
            {
                contextMenu.Items.Add(NewWaypointMenuItem(position));
                contextMenu.Items.Add(MoveWaypointMenuItem(position));
            }

            contextMenu.Items.Add(SaveRouteMenuItem());

            contextMenu.IsOpen = true;
        }
Exemplo n.º 12
0
        void landRequests_ConfirmationAdded(object sender, EventArgs e)
        {
            if ((ConfirmationSort)sender == ConfirmationSort.Confirm)
            {
                if (!string.IsNullOrEmpty(selectedLand.DeforestationConfirmers))
                {
                    selectedLand.DeforestationConfirmers += ",";
                }
                selectedLand.DeforestationConfirmers += Current.Instance.Earthwatcher.Id.ToString();
            }
            else
            {
                if (!string.IsNullOrEmpty(selectedLand.DeforestationDeconfirmers))
                {
                    selectedLand.DeforestationDeconfirmers += ",";
                }
                selectedLand.DeforestationDeconfirmers += Current.Instance.Earthwatcher.Id.ToString();
            }

            if (!Current.Instance.Scores.Any(x => x.Action.Equals("ConfirmationAdded") && x.Published > selectedLand.LastReset))
            {
                Current.Instance.AddScore.Add("ConfirmationAdded", 500);
            }

            var topLeft     = Current.Instance.MapControl.Viewport.Extent.TopLeft;
            var bottomLeft  = Current.Instance.MapControl.Viewport.Extent.BottomLeft;
            var bottomRight = Current.Instance.MapControl.Viewport.Extent.BottomRight;
            var topRight    = Current.Instance.MapControl.Viewport.Extent.TopRight;

            var llTopLeft     = SphericalMercator.ToLonLat(topLeft.X, topLeft.Y);
            var llbottomLeft  = SphericalMercator.ToLonLat(bottomLeft.X, bottomLeft.Y);
            var llbottonRight = SphericalMercator.ToLonLat(bottomRight.X, bottomRight.Y);
            var llTopRight    = SphericalMercator.ToLonLat(topRight.X, topRight.Y);

            var wkt = String.Format(CultureInfo.InvariantCulture, "POLYGON(({0} {1},{2} {3},{4} {5},{6} {7},{0} {1}))", llTopLeft.x, llTopLeft.y, llbottomLeft.x, llbottomLeft.y, llbottonRight.x, llbottonRight.y, llTopRight.x, llTopRight.y);

            landRequests.LandInViewReceived += LivLandInViewReceived;
            landRequests.GetLandByWkt(wkt);
        }
Exemplo n.º 13
0
        private void CalculateDistance()
        {
            var distance = 0d;

            for (var i = 0; i < _pointList.Count; i++)
            {
                if (i + 1 >= _pointList.Count)
                {
                    break;
                }

                var world1 = Current.Instance.MapControl.Viewport.ScreenToWorld(_pointList[i].X, _pointList[i].Y);
                var world2 = Current.Instance.MapControl.Viewport.ScreenToWorld(_pointList[i + 1].X, _pointList[i + 1].Y);

                var lonLat1 = SphericalMercator.ToLonLat(world1.X, world1.Y);
                var lonLat2 = SphericalMercator.ToLonLat(world2.X, world2.Y);

                distance += Distance(lonLat1.y, lonLat1.x, lonLat2.y, lonLat2.x);
            }

            txtDistance.Text = string.Format("Distance: {0} KM", Math.Round(distance, 4));
        }
Exemplo n.º 14
0
        /// <summary>
        /// Event generated by map
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_Info(object sender, Mapsui.UI.MapInfoEventArgs e)
        {
            CheckBox chkCalibOn = FindViewById <CheckBox>(Resource.Id.chkCalibOn);
            CheckBox chkUserOn  = FindViewById <CheckBox>(Resource.Id.chkUserOn);

            if (chkCalibOn.Checked)
            {
                //recalculate calib point position
                Mapsui.Geometries.Point p = SphericalMercator.ToLonLat(e.MapInfo.WorldPosition.X, e.MapInfo.WorldPosition.Y);
                CalibPosition = new GlobalCoordinates(p.Y, p.X);
                UpdateCalibPoints();
                SaveSettings();
                _mapControl.Refresh();
            }
            else if (chkUserOn.Checked)
            {
                //set user position
                Mapsui.Geometries.Point p = SphericalMercator.ToLonLat(e.MapInfo.WorldPosition.X, e.MapInfo.WorldPosition.Y);
                UserPosition = new GlobalCoordinates(p.Y, p.X);
                UpdateUserPosPoints();
                SettingsSaver.SaveUserPos(UserPosition.Latitude.Degrees, UserPosition.Longitude.Degrees);
                _mapControl.Refresh();
            }
        }
Exemplo n.º 15
0
        public static Position ToNative(this MPoint point)
        {
            var result = SphericalMercator.ToLonLat(point.X, point.Y);

            return(new Position(result.lat, result.lon));
        }
Exemplo n.º 16
0
 public static Point ToLonLat(this Point point)
 {
     return(SphericalMercator.ToLonLat(point.X, point.Y));
 }
Exemplo n.º 17
0
 // Returns the distance in kilometers
 public double GetGeoDistance(Mapsui.Geometries.Point p1, Mapsui.Geometries.Point p2)
 {
     Mapsui.Geometries.Point lonLatPoint1 = SphericalMercator.ToLonLat(p1.X, p1.Y);
     Mapsui.Geometries.Point lonLatPoint2 = SphericalMercator.ToLonLat(p2.X, p2.Y);
     return(GetGeoDistanceTo(lonLatPoint1.Y, lonLatPoint1.X, lonLatPoint2.Y, lonLatPoint2.X, 'K'));
 }