예제 #1
0
        public ActionResult ClusterData(int zoom)
        {
            MongoService mongoService = new MongoService();
            var          data         = mongoService.GetAllLocations();
            var          zoomLevel    = GetZoomLevel(zoom);
            var          radius       = GetClusterRadius(zoom);
            var          clusters     = new List <PokemonLocation>();

            foreach (var location in data)
            {
                if (!mongoService.IsClusterWithinDistance(location.Location, radius, zoomLevel))
                {
                    mongoService.AddCluster(new Cluster()
                    {
                        Location  = location.Location,
                        ZoomLevel = zoomLevel
                    });
                }
            }
            foreach (var location in data)
            {
                var nearestCluster = mongoService.FindNearestCluster(location.Location, radius, zoomLevel);
                if (zoomLevel == ZoomLevel.OneThroughFive)
                {
                    location.FirstClusterId = nearestCluster.Id;
                }
                if (zoomLevel == ZoomLevel.SixThroughSeven)
                {
                    location.SecondClusterId = nearestCluster.Id;
                }
                if (zoomLevel == ZoomLevel.EightThroughTen)
                {
                    location.ThirdClusterId = nearestCluster.Id;
                }
                if (zoomLevel == ZoomLevel.ElevenThroughThirteen)
                {
                    location.FourthClusterId = nearestCluster.Id;
                }
                mongoService.UpdateInstances(location);
            }

            return(View());
        }