Exemplo n.º 1
0
        void CreateUnits()
        {
            _units = new Unit[PlanetConfig.UnitSize, PlanetConfig.UnitSize];
            GeoRange rect = Surface.Rect / PlanetConfig.UnitSize;

            for (int x = 0; x < PlanetConfig.UnitSize; x++)
            {
                GeoRange tmpRect = rect;
                for (int y = 0; y < PlanetConfig.UnitSize; y++)
                {
                    _units[x, y] = CreateUnit(cfg, new Vector2Int(x, y), rect, this, ZoomLevel + 1);

                    rect = rect.NextBottom();
                }
                rect = tmpRect.NextRight();
            }
        }
Exemplo n.º 2
0
        void CreatePlanetUnits()
        {
            _units = new Unit[PlanetConfig.UnitSize, PlanetConfig.UnitSize / 2];
            GeoRange rect = new GeoRange(Surface.Rect.Start, Surface.Rect.Width / PlanetConfig.UnitSize, 2 * Surface.Rect.Height / PlanetConfig.UnitSize);

            for (int x = 0; x < PlanetConfig.UnitSize; x++)
            {
                GeoRange tmpRect = rect;
                for (int y = 0; y < PlanetConfig.UnitSize / 2; y++)
                {
                    _units[x, y] = CreateUnit(cfg, new Vector2Int(x, y), rect, this, ZoomLevel + 1);

                    rect = rect.NextBottom();
                }
                rect = tmpRect.NextRight();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Helper method to get retailers within range from model
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        private async Task <List <Retailer> > GetRetailersInBounds(GeoRange range)
        {
            var retailers = await db.Retailers.Include(r => r.LatLng).Include(r => r.Address)
                            .Where(r => r.LatLng.Lat <= range.TopLeft.Lat &&
                                   r.LatLng.Lng >= range.TopLeft.Lng &&
                                   r.LatLng.Lat >= range.BottomRight.Lat &&
                                   r.LatLng.Lng <= range.BottomRight.Lng).ToListAsync();

            if (userLocation != null)
            {
                retailers.Sort(delegate(Retailer r1, Retailer r2)
                {
                    return(r1.LatLng.MilesTo(userLocation).CompareTo(r2.LatLng.MilesTo(userLocation)));
                });
            }

            return(retailers);
        }
Exemplo n.º 4
0
        static Unit CreateUnit(
            PlanetConfig cfg,
            Vector2Int localIdx,
            GeoRange rect,
            Unit parentUnit,
            int zoomLevel)
        {
            //var unit = new GameObject().AddComponent<Unit>();
            //unit.name = localIdx.ToString();
            //unit.transform.parent = parentGo;
            var unit = new Unit
            {
                Parent    = parentUnit,
                cfg       = cfg,
                ZoomLevel = zoomLevel
            };

            if (parentUnit == null)
            {
                unit.dataStart = localIdx;
            }
            else
            {
                unit.dataStart = parentUnit.dataStart * PlanetConfig.UnitSize + localIdx;
            }
            unit.LocalIndex = localIdx;
            if (zoomLevel == 0)
            {
                //unit.Surface = SurfaceArea.Load();
                if (unit.Surface == null)
                {
                    unit.Surface        = new SurfaceArea(rect);
                    unit.Surface.Points = PerlinNoiseGenerator.CreatePlanetSurfacePoints(cfg);
                    //unit.Surface.Save();
                }
            }
            else
            {
                unit.Surface = new SurfaceArea(rect);
            }

            return(unit);
        }
        public List<AdventureLocation> GetNearByAdventureLocations(GeoPoint point, GeoRange range)
        {
            var locations = new List<AdventureLocation>
                                {
                                    new AdventureLocation(point, "test00"),
                                    new AdventureLocation(point, "test01"),
                                    new AdventureLocation(point, "test02"),
                                    new AdventureLocation(point, "test03"),
                                    new AdventureLocation(point, "test04"),
                                    new AdventureLocation(point, "test05"),
                                    new AdventureLocation(point, "test06"),
                                    new AdventureLocation(point, "test07"),
                                    new AdventureLocation(point, "test08")
                                };

            return locations;

            /*
            var setting = new ConnectionSettings(ElasticServer, 9200);
            setting.SetDefaultIndex("pins");

            //request.ValidateRange(_defaultRangeSetting);

            var client = new ElasticClient(setting);

            var results = client.Search<Spot>(s => s
                .From(0) // skip
                .Size(10) // limit
                .Filter(f => f
                        .GeoDistance("geo.location", filter =>
                            filter
                            .Location(point.Lat, point.Lon)
                            .Distance(range.ToString())))
                .Index("pins") // which index
                .Type("location") // what type in the index
                );

            return results.Documents.ToList();
            */
        }
Exemplo n.º 6
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            double lat = 0.0;
            double.TryParse(txtLatSearch.Text, out lat);
            double lon = 0.0;
            double.TryParse(txtLonSearch.Text, out lon);

            int range = 5;
            int.TryParse(txtMilesSearch.Text, out range);
            GeoRange geoRange = new GeoRange() { Range = range };
            //var locations = _adventureLocationRepository.GetNearBy(new LocationPoint() { Lat = lat, Lon = lon }, geoRange);

            //StringBuilder sb = new StringBuilder();
            //int c = 0;
            //foreach (var adventureLocation in locations)
            //{
            //    sb.AppendFormat("{0}. {1} [Lon:{2}, lat:{3}]", c++, adventureLocation.Name, adventureLocation.LocationPoint.Lon, adventureLocation.LocationPoint.Lat);
            //    sb.AppendLine();
            //}

            //MessageBox.Show(sb.ToString());
        }