Esempio n. 1
0
        /// <summary>
        ///     Retrieves the product from the Trek web services and saves it to a file. If the
        ///     requested file is already present on the file system, then it is loaded instead,
        ///     unless file redownload is forced.
        /// </summary>
        public void SubsetProduct(TerrainProductMetadata productInfo, bool forceRedownload, Action <string> callback)
        {
            if (productInfo.Format == 0)
            {
                productInfo.Format = ImageFileFormat.Tiff;
            }

            string filename = $"{productInfo.EncodeBase64()}.{FilePath.ProductFileExtension}";

            string         directory      = Path.Combine(FilePath.PersistentRoot, FilePath.Product);
            IList <string> availableFiles = FileUtils.ListFiles(directory, $"*.{FilePath.ProductFileExtension}", true);

            string filepath = Path.Combine(directory, filename);

            if (availableFiles.Contains(filename))
            {
                if (!forceRedownload)
                {
                    callback(filepath);
                    return;
                }

                File.Delete(filepath);
            }

            string baseUrlWithFormat = $"{BaseUrl}{SubsetUrl}/{productInfo.Format.FileExtension()}/subset";

            IDictionary <string, string> paramsMap = new Dictionary <string, string>()
            {
                { "itemUUID", productInfo.ProductUUID },
                { "bbox", productInfo.BoundingBox.ToString(",") },
                { "width", $"{productInfo.Width}" },
                { "height", $"{productInfo.Height}" }
            };

            string resourceUrl = HttpRequestUtils.AppendParams(baseUrlWithFormat, paramsMap, true);

            Debug.Log(resourceUrl);

            VerifyProductExists(productInfo, exists => {
                if (exists)
                {
                    HttpClient.DownloadFile(resourceUrl, filepath, callback);
                }
                else
                {
                    Debug.LogError($"Product UUID {productInfo.ProductUUID} is not a raster or does not exist.");
                }
            });
        }
        public void GetDistance(string points, Action <string> callback)
        {
            IDictionary <string, string> paramsMap = new Dictionary <string, string>()
            {
                { "endpoint", Endpoint },
                { "path", points },
                { "radiusInMeters", Mars.Radius.ToString() }
            };

            string url = HttpRequestUtils.AppendParams("https://trek.nasa.gov/mars/TrekServices/ws/elevationProfile/distance", paramsMap);

            HttpClient.Get(url, res => {
                string responseBody = HttpClient.GetReponseBody(res);
                callback?.Invoke(responseBody);
            });
        }
Esempio n. 3
0
        public void GetRasters(Action <SearchResult> callback, bool forceRefresh = false)
        {
            if (forceRefresh)
            {
                _rasters = null;
            }
            if (_rasters)
            {
                callback?.Invoke(_rasters);
                return;
            }
            IDictionary <string, string> paramsMap = new Dictionary <string, string>()
            {
                { "productType", "*" },
            };
            string searchUrl = HttpRequestUtils.AppendParams($"{BaseUrl}{SearchUrl}", paramsMap);

            HttpClient.Get(searchUrl, (res) => {
                string responseBody = HttpClient.GetReponseBody(res);
                _rasters            = DeserializeResults(responseBody);
                callback?.Invoke(_rasters);
            });
        }