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); }
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(); } }
public Feature GetFeature(double longitude, double latitude, int level) { //Get the hexcode for the clicked area and try to find if its a feature on the map var hexCode = GeoHex.Encode(longitude, latitude, level); var feature = hexagonLayer.GetFeatureByHex(hexCode); return(feature); }
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); } } } }
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)); }
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); }
//Helpers public Feature GetFeature(double longitude, double latitude, int level) { //Get the hexcode for the clicked area and try to find if its a feature on the map var hexCode = GeoHex.Encode(longitude, latitude, level); Feature feature = null; //TEST if (first) { feature = bcLayer.GetFeatureByHex(hexCode); //TEST first = false; } else { feature = hexagonLayer.GetFeatureByHex(hexCode); } return(feature); }
public void ShowInfo(double lon, double lat) { // first try on level 7... var feature = GetFeature(lon, lat, 7); var hexCode = GeoHex.Encode(lon, lat, 7); if (feature == null) { // try on level 6... hexCode = GeoHex.Encode(lon, lat, 6); feature = GetFeature(lon, lat, 6); if (feature == null) { return; } } UpdateInfo(hexCode, false); Move(); isShown = true; Visibility = Visibility.Visible; }
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); }
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); }
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); } }
public static List <Land> GenerateLands(PointD topLeft, PointD bottomRight, int level, int regionId) { var horaInicio = DateTime.Now; Console.WriteLine("Hora de inicio GenerateLands: " + horaInicio); var newLand = new List <Land>(); //Tamaño Mediano (Salta) //const double increase = 0.0075; //level = 7; //Tamaño Grande (Chaco 10K Total - Las que no sirben) const double increase = 0.0175; level = 6; //Tamaño Chico //const double increase = 0.00175; //level = 8; int assignables = 0; int unassignables = 0; for (var i = topLeft.X; i <= bottomRight.X; i += increase) { for (var j = topLeft.Y; j >= bottomRight.Y; j -= increase) { var hexKey = GeoHex.Encode(i, j, level); var land = new Land(); land.Longitude = i; land.Latitude = j; land.GeohexKey = hexKey; land.RegionId = regionId; land.BasecampId = 999; //FORMA FACIL DE IDENTIFICAR A LAS NUEVAS PARCELAS CREADAS PARA TEST if ((!newLand.Any(l => l.GeohexKey == hexKey))) { if (_forestlaw != null) { if (ComputeLandThreat(land)) { //ComputeBasecampIntersection(land); newLand.Add(land); assignables++; } else { unassignables++; } } else { unassignables++; newLand.Add(land); } } } } var horaFin = DateTime.Now; Console.WriteLine("Hora Fin GenerateLands: " + horaFin); Console.WriteLine("ASIGNABLES: " + assignables); Console.WriteLine("NO ASIGNABLES: " + unassignables); return(newLand); }