Ejemplo n.º 1
0
        public static void ZoomToHexagon(MapControl mapcontrol, string geohex)
        {
            var zone = GeoHex.Decode(geohex);

            if (zone == null)
            {
                var ws = new WarningScreen("Sorry this land is not available");
                ws.Show();
                return;
            }

            var       coordinates          = zone.getHexCoords();
            var       sphericalTopLeft     = SphericalMercator.FromLonLat(coordinates[0].Longitude, coordinates[1].Latitude);
            var       sphericalBottomRight = SphericalMercator.FromLonLat(coordinates[3].Longitude, coordinates[4].Latitude);
            const int marge = 8000;

            mapcontrol.ZoomToBox(new Mapsui.Geometries.Point(sphericalTopLeft.x - marge, sphericalTopLeft.y - marge), new Mapsui.Geometries.Point(sphericalBottomRight.x + marge, sphericalBottomRight.y + marge));

            //TODO: Blergh awfull dirty dirty hack to show hexagon after zoomToHexagon (problem = Extend is a center point after ZoomToBox)
            mapcontrol.ZoomIn();
            mapcontrol.ZoomOut();

            var hexLayer = (HexagonLayer)Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername);

            hexLayer.UpdateHexagonsInView();
            Current.Instance.MapControl.OnViewChanged(true);
        }
Ejemplo n.º 2
0
        private void LandChanged(object sender, EventArgs e)
        {
            var land = sender as Land;

            selectedLand = land;

            if (land == null)
            {
                return;
            }

            if (!Current.Instance.Tutorial2Started)
            {
                Current.Instance.EarthwatcherLand = land;
                zone = GeoHex.Decode(land.GeohexKey);

                var hexagonLayer = Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername) as HexagonLayer;

                if (hexagonLayer != null && zone != null)
                {
                    hexagonLayer.AddHexagon(zone, LandStatus.NotChecked, true);
                }
            }

            MapHelper.ZoomToHexagon(Current.Instance.MapControl, land.GeohexKey);

            if (Current.Instance.Tutorial2Started)
            {
                this.Tutorial21StoryBoard.Begin();
            }
        }
Ejemplo n.º 3
0
        public List <SatelliteImage> GetImagesByHexagon(double latitude, double longitude)
        {
            //Get the geohex locations
            string geoHexCode = GeoHex.Encode(longitude, latitude, 7);
            Zone   zone       = GeoHex.Decode(geoHexCode);

            Loc[] locs = zone.getHexCoords();

            //Create a Polygon
            IEnumerable <XY> pointCollection = GetPointCollection(locs);
            Polygon          polygon         = new Polygon(pointCollection);

            return(GetImagesByPolygon(polygon));
        }
Ejemplo n.º 4
0
        public void AddBasecamp(Land land)
        {
            var zone = GeoHex.Decode(land.GeohexKey);

            var isOwn = Current.Instance.Lands.Any(x => x.GeohexKey == land.GeohexKey);
            var sphericalCoordinates = ConvertHexCoordinates(zone.getHexCoords());
            var polygon = new Polygon {
                ExteriorRing = new LinearRing(sphericalCoordinates)
            };
            var feature = new Feature {
                Geometry = polygon
            };

            feature["bccode"] = zone.code;

            _source.Features.Add(feature);
        }
Ejemplo n.º 5
0
        public void AddHexagon(Land land)
        {
            var zone = GeoHex.Decode(land.GeohexKey);

            var isOwn = Current.Instance.Earthwatcher.Lands.Any(x => x.GeohexKey == land.GeohexKey);
            var sphericalCoordinates = ConvertHexCoordinates(zone.getHexCoords());
            var polygon = new Polygon {
                ExteriorRing = new LinearRing(sphericalCoordinates)
            };
            var feature = new Feature {
                Geometry = polygon
            };

            feature["isGreenpeaceUser"] = land.EarthwatcherId.HasValue && land.EarthwatcherId.Value == Configuration.GreenpeaceId ? "True" : "False";
            feature["hexcode"]          = zone.code;

            bool ischecked = false;

            if (land.OKs != null && land.Alerts != null)
            {
                if (land.OKs.Split(',').Any(x => x.Equals(Current.Instance.Earthwatcher.Id.ToString())) || land.Alerts.Split(',').Any(x => x.Equals(Current.Instance.Earthwatcher.Id.ToString())))
                {
                    ischecked = true;
                }
            }
            bool denouncedByMe = false;

            if (Current.Instance.RegionScores.Any(x => x.Action.Equals(ActionPoints.Action.DemandAuthorities.ToString()) && (x.LandId == land.Id)))
            {
                denouncedByMe = true;
            }

            bool islockedOnly = land.IsLocked == true && land.DemandAuthorities == false ? true : false;

            feature.Styles.Add(GetVectorStyle(land.LandStatus, isOwn, land.DemandAuthorities, ischecked, land.EarthwatcherId.HasValue && land.EarthwatcherId.Value == Configuration.GreenpeaceId ? true : false, islockedOnly, denouncedByMe));

            source.Features.Add(feature);
        }
Ejemplo n.º 6
0
        private void LandRequestLandInViewReceived(object sender, EventArgs e)
        {
            var landPieces = sender as List <Land>;

            Current.Instance.LandInView = landPieces;

            ClearGraphics();

            if (landPieces == null || Current.Instance.MapControl.Viewport.Resolution > 50)
            {
                return;
            }

            foreach (var landPiece in landPieces)
            {
                var zone = GeoHex.Decode(landPiece.GeohexKey);

                var isOwn = Current.Instance.EarthwatcherLand != null && Current.Instance.EarthwatcherLand.GeohexKey.Equals(landPiece.GeohexKey);

                AddHexagon(zone, landPiece.LandStatus, isOwn);
            }

            Current.Instance.MapControl.OnViewChanged(true);
        }
Ejemplo n.º 7
0
        private static void DoWork(object sender, DoWorkEventArgs e)
        {
            //Esto quedo obsoleto si no vamos a usar Azure

            /*
             * storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=guardianes;AccountKey=vlG2nCfujtarq9++4+Qh21vZvD6c9+PUfNqR/9o+yc7AXifypGBVeEYgSRBMRx9AhLGoIcGJkgSqypduaaBnxw==");
             * blobClient = storageAccount.CreateCloudBlobClient();
             * if (includeHexagon)
             * {
             *  container = blobClient.GetContainerReference("demand");
             * }
             * else
             * {
             *  container = blobClient.GetContainerReference("minigame");
             * }
             * */

            //Encoder
            jgpEncoder = GetEncoder(ImageFormat.Jpeg);
            System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
            myEncoderParameters = new EncoderParameters(1);

            EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 100L);

            myEncoderParameters.Param[0] = myEncoderParameter;

            List <string> hexCodes = new List <string>();

            if (string.IsNullOrEmpty(_geoHexKey))
            {
                hexCodes = landRepository.GetVerifiedLandsGeoHexCodes(0, includeHexagon);
            }
            else
            {
                hexCodes.Add(_geoHexKey);
            }

            foreach (var geohex in hexCodes)
            {
                string baseurl = landRepository.GetImageBaseUrl(true, geohex);
                string newurl  = landRepository.GetImageBaseUrl(false, geohex);

                var zone = GeoHex.Decode(geohex);

                var sphericalCoordinates = ConvertHexCoordinates(zone.getHexCoords());

                var top    = sphericalCoordinates.Max(s => s.Y);
                var bottom = sphericalCoordinates.Min(s => s.Y);
                var left   = sphericalCoordinates.Min(s => s.X);
                var right  = sphericalCoordinates.Max(s => s.X);

                var extent = new BruTile.Extent(left, bottom, right, top);

                var schema = new SphericalMercatorWorldSchema();
                schema.Extent = extent;

                var tiles = schema.GetTilesInView(extent, 13);

                var newTop    = tiles.Max(s => s.Extent.MaxY);
                var newBottom = tiles.Min(s => s.Extent.MinY);
                var newLeft   = tiles.Min(s => s.Extent.MinX);
                var newRight  = tiles.Max(s => s.Extent.MaxX);

                int[] cols    = tiles.OrderBy(t => t.Index.Col).ThenByDescending(t => t.Index.Row).Select(t => t.Index.Col).Distinct().ToArray();
                int[] rows    = tiles.OrderBy(t => t.Index.Col).ThenByDescending(t => t.Index.Row).Select(t => t.Index.Row).Distinct().ToArray();
                int   width   = 256 * cols.Length;
                int   height  = 256 * rows.Length;
                float hexLeft = (float)(((left - newLeft) * width) / (newRight - newLeft));
                float hexTop  = (float)(((top - newTop) * height) / (newBottom - newTop));

                CreateCanvas(baseurl, geohex, tiles, width, height, hexLeft, hexTop, cols, rows, true);
                CreateCanvas(newurl, geohex, tiles, width, height, hexLeft, hexTop, cols, rows, false);
            }
        }