private async void ProcessImageRequest(BaseImageryRestRequest imageRequest) { try { RequestProgressBar.Visibility = Visibility.Visible; RequestProgressBarText.Text = string.Empty; RequestUrlTbx.Text = imageRequest.GetRequestUrl(); //Process the request by using the ServiceManager. using (var s = await ServiceManager.GetImageAsync(imageRequest)) { var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = s; bitmapImage.EndInit(); ImageBox.Source = bitmapImage; } ImageTab.IsSelected = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } RequestProgressBar.Visibility = Visibility.Collapsed; }
/// <summary> /// Processes a REST requests that returns an image stream. /// </summary> /// <param name="imageryRequest">The REST request to process.</param> /// <returns>A stream containing an image.</returns> public static async Task <Stream> GetImageAsync(BaseImageryRestRequest imageryRequest) { if (imageryRequest is ImageryRequest) { var r = imageryRequest as ImageryRequest; r.GetMetadata = false; if (r.Pushpins != null && (r.Pushpins.Count > 18 || r.Style != null)) { //Make a post request when there are more than 18 pushpins as there is a risk of URL becoming too large for a GET request. return(await ServiceHelper.PostStringAsync(new Uri(r.GetPostRequestUrl()), r.GetPushpinsAsString(), null).ConfigureAwait(false)); } else { return(await ServiceHelper.GetStreamAsync(new Uri(r.GetRequestUrl())).ConfigureAwait(false)); } } else { return(await ServiceHelper.GetStreamAsync(new Uri(imageryRequest.GetRequestUrl())).ConfigureAwait(false)); } }