Ejemplo n.º 1
0
        public ActionResult Index(FormCollection waypoints)
        {
            FlythroughModel model         = new FlythroughModel();
            var             keys          = waypoints.AllKeys.ToList();
            var             waypointCount = keys.Where(x => x.Contains("waypoint_")).Count();
            string          URL           = "https://api.opentopodata.org/v1/eudem25m";
            string          urlParameters = @"?locations=";
            HttpClient      client        = new HttpClient();

            client.BaseAddress = new Uri(URL);

            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("*/*"));
            for (int i = 0; i < waypointCount; i++)
            {
                string      waypoint  = Request.Form["waypoint_" + i];
                string      target    = Request.Form["target_" + i];
                string      elevation = Request.Form["elevation_" + i];
                CameraModel cam       = new CameraModel(waypoint, target, elevation);
                urlParameters += Math.Round(cam.Lat, 6) + "," + Math.Round(cam.Lng, 6) + (i != waypointCount - 1 ? "|" : "");
                model.Cameras.Add(cam);
            }
            URL += urlParameters;
            List <Result> resultList = new List <Result>();

            try
            {
                string response = client.GetStringAsync(URL).Result;  // Blocking call! Program will wait here until a response is received or a timeout occurs.
                if (response != null)
                {
                    Root elevationResults = JsonConvert.DeserializeObject <Root>(response);
                    for (int i = 0; i < elevationResults.results.Count(); i++)
                    {
                        double num = elevationResults.results[i].elevation == null ? 0 : (double)elevationResults.results[i].elevation;
                        model.Cameras[i].GroundElevation = Math.Round(num * feetInMeter, 1);
                    }
                    resultList = elevationResults.results;
                }
                else
                {
                    throw new HttpException();
                }
            }
            catch (Exception ex)
            {
                // I dunno
            }
            string mod = JsonConvert.SerializeObject(model);

            Session["Settings"] = mod;
            //System.IO.File.WriteAllText("settings.json", mod);

            return(View("Fullscreen", model));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            FlythroughModel model = new FlythroughModel();

            object mod = Session["Settings"];

            if (mod != null)
            {
                string str = (string)mod;
                model = JsonConvert.DeserializeObject <FlythroughModel>(str);
            }

            return(View("WayPoints", model));
        }